List of usage examples for java.io Serializable toString
public String toString()
From source file:org.rhq.enterprise.server.plugins.rhnhosted.PrimaryXML.java
/** * Will create a xml string snippet conforming to the <package> entry in a primary.xml file used by yum * * @param pkg JAXB Object to transform/* w ww . j av a 2 s . c o m*/ * @return string snippet of xml data */ static public String createPackageXML(RhnPackageType pkg) { Namespace packageNS = Namespace.getNamespace(RHNHOSTED_URI); Element top = new Element("package", packageNS); top.setAttribute("type", "rpm"); Element name = new Element("name", packageNS); name.setText(pkg.getName()); top.addContent(name); Element arch = new Element("arch", packageNS); arch.setText(pkg.getPackageArch()); top.addContent(arch); Element version = new Element("version", packageNS); version.setText(pkg.getVersion()); version.setAttribute("ver", pkg.getVersion()); version.setAttribute("rel", pkg.getRelease()); String epoch = pkg.getEpoch(); // Note, if epoch is empty we need to change it to a zero as that is what yum expects. if (StringUtils.isBlank(epoch)) { epoch = "0"; } version.setAttribute("epoch", epoch); top.addContent(version); Element checksum = new Element("checksum", packageNS); checksum.setAttribute("type", "md5"); checksum.setAttribute("pkgid", "YES"); checksum.setText(pkg.getMd5Sum()); top.addContent(checksum); Element summary = new Element("summary", packageNS); summary.setText(pkg.getRhnPackageSummary()); top.addContent(summary); Element description = new Element("description", packageNS); description.setText(pkg.getRhnPackageDescription()); top.addContent(description); Element packager = new Element("packager", packageNS); //TODO: Not sure if we get 'packager' info from RHN. packager.setText(""); top.addContent(packager); Element url = new Element("url", packageNS); //TODO: Not sure what to put for url value, don't think it applies to RHN url.setText(""); top.addContent(url); Element time = new Element("time", packageNS); //TODO: Verify below, guessing for file/build times. time.setAttribute("file", pkg.getLastModified()); time.setAttribute("build", pkg.getBuildTime()); top.addContent(time); Element size = new Element("size", packageNS); size.setAttribute("package", pkg.getPackageSize()); size.setAttribute("archive", pkg.getPayloadSize()); //TODO: Unsure about installed, does this need to change on server side when package is installed on a client? size.setAttribute("installed", ""); top.addContent(size); Element location = new Element("location", packageNS); //This value can not be empty and can not contain a "?". //It's value is ignored by the RHQ processing for yum. //RHQ will append a series of request parameters to download the file. String rpmName = RHNHelper.constructRpmDownloadName(pkg.getName(), pkg.getVersion(), pkg.getRelease(), pkg.getEpoch(), pkg.getPackageArch()); location.setAttribute("href", rpmName); top.addContent(location); Element format = new Element("format", packageNS); Namespace rpmNS = Namespace.getNamespace("rpm", "http://rhq-project.org/rhnhosted"); Element rpmLicense = new Element("license", rpmNS); rpmLicense.setText(pkg.getRhnPackageCopyright()); format.addContent(rpmLicense); Element rpmVendor = new Element("vendor", rpmNS); rpmVendor.setText(pkg.getRhnPackageVendor()); format.addContent(rpmVendor); Element rpmGroup = new Element("group", rpmNS); rpmGroup.setText(pkg.getPackageGroup()); format.addContent(rpmGroup); Element rpmBuildHost = new Element("buildhost", rpmNS); rpmBuildHost.setText(pkg.getBuildHost()); format.addContent(rpmBuildHost); Element rpmSourceRPM = new Element("sourcerpm", rpmNS); rpmSourceRPM.setText(pkg.getSourceRpm()); format.addContent(rpmSourceRPM); Element rpmHeaderRange = new Element("header-range", rpmNS); rpmHeaderRange.setAttribute("start", pkg.getRhnPackageHeaderStart()); rpmHeaderRange.setAttribute("end", pkg.getRhnPackageHeaderEnd()); format.addContent(rpmHeaderRange); Element rpmProvides = new Element("provides", rpmNS); RhnPackageProvidesType provides_type = pkg.getRhnPackageProvides(); if (provides_type != null) { List<RhnPackageProvidesEntryType> provides = provides_type.getRhnPackageProvidesEntry(); for (RhnPackageProvidesEntryType provEntry : provides) { Element entry = new Element("entry", rpmNS); entry.setAttribute("name", provEntry.getName()); String flags = getFlags(provEntry.getSense()); if (!StringUtils.isBlank(flags)) { entry.setAttribute("flags", flags); String provEpoch = getEpoch(provEntry.getVersion()); entry.setAttribute("epoch", provEpoch); String provVer = getVersion(provEntry.getVersion()); entry.setAttribute("ver", provVer); String provRel = getRelease(provEntry.getVersion()); entry.setAttribute("rel", getRelease(provEntry.getVersion())); } rpmProvides.addContent(entry); } } format.addContent(rpmProvides); Element rpmRequires = new Element("requires", rpmNS); RhnPackageRequiresType requires_type = pkg.getRhnPackageRequires(); if (requires_type != null) { List<RhnPackageRequiresEntryType> requires = requires_type.getRhnPackageRequiresEntry(); for (RhnPackageRequiresEntryType reqEntry : requires) { Element entry = new Element("entry", rpmNS); entry.setAttribute("name", reqEntry.getName()); String flags = getFlags(reqEntry.getSense()); if (!StringUtils.isBlank(flags)) { entry.setAttribute("flags", flags); String reqEpoch = getEpoch(reqEntry.getVersion()); entry.setAttribute("epoch", reqEpoch); String reqVer = getVersion(reqEntry.getVersion()); entry.setAttribute("ver", reqVer); String reqRel = getRelease(reqEntry.getVersion()); entry.setAttribute("rel", getRelease(reqEntry.getVersion())); } rpmRequires.addContent(entry); } } format.addContent(rpmRequires); Element rpmConflicts = new Element("conflicts", rpmNS); rpmConflicts.setText(pkg.getRhnPackageConflicts()); format.addContent(rpmConflicts); Element rpmObsoletes = new Element("obsoletes", rpmNS); RhnPackageObsoletesType obs_type = pkg.getRhnPackageObsoletes(); if (obs_type != null) { List<Serializable> obsoletes = obs_type.getContent(); for (Serializable s : obsoletes) { RhnPackageObsoletesEntryType obsEntry = null; if (s instanceof String) { String obsString = (String) s; if (StringUtils.isBlank(obsString)) { continue; } //log.debug("Adding Obsoletes info <String Class> value = " + obsString); Element entry = new Element("entry", rpmNS); entry.setAttribute("name", obsString); rpmObsoletes.addContent(entry); // skip rest of obs processing for this entry continue; } // // Below obs entry processing is for JAXBElement types only // if (s instanceof JAXBElement) { JAXBElement je = (JAXBElement) s; //log.debug("Processing obsolete info for JAXBElement of type : " + je.getDeclaredType()); obsEntry = (RhnPackageObsoletesEntryType) je.getValue(); } else if (s instanceof RhnPackageObsoletesEntryType) { obsEntry = (RhnPackageObsoletesEntryType) s; } else { log.info("Processing obsoletes info: unable to determine what class obsoletes entry is: " + "getClass() = " + s.getClass() + ", toString() = " + s.toString() + ", hashCode = " + s.hashCode()); continue; } Element entry = new Element("entry", rpmNS); entry.setAttribute("name", obsEntry.getName()); String obsVer = obsEntry.getVersion(); if (!StringUtils.isBlank(obsVer)) { entry.setAttribute("version", obsVer); } String obsFlags = getFlags(obsEntry.getSense()); if (!StringUtils.isBlank(obsFlags)) { entry.setAttribute("flags", obsFlags); } rpmObsoletes.addContent(entry); } } format.addContent(rpmObsoletes); top.addContent(format); XMLOutputter xmlOut = new XMLOutputter(); return xmlOut.outputString(top); }
From source file:org.carewebframework.vista.mbroker.BrokerSession.java
public void fireRemoteEvent(String eventName, Serializable eventData, String[] recipients) { RPCParameters params = new RPCParameters(); params.get(0).setValue(eventName);/*from w ww. j a va 2 s.c om*/ RPCParameter param = params.get(1); String data = eventData == null ? "" : eventData instanceof String ? eventData.toString() : Constants.JSON_PREFIX + JSONUtil.serialize(eventData); int index = 0; for (int i = 0; i < data.length(); i += 255) { param.put(Integer.toString(++index), StringUtils.substring(data, i, i + 255)); } param = params.get(2); for (String recip : recipients) { if (!recip.isEmpty()) { if (processRecipient(param, "#", "UID", recip) || processRecipient(param, "", "DUZ", recip)) { } } } callRPC("RGNETBEV BCAST", params); }
From source file:com.clican.pluto.fsm.engine.state.DefaultStateImpl.java
/** * ???timeOutListenner??Job/*from w w w . jav a2s.com*/ * * @param state * @param event * @param startTime * ?job */ protected void prepareJobs(State state, Event event, Date startTime) { if (timeoutListeners != null && !timeoutListeners.isEmpty()) { for (String name : timeoutListeners.keySet()) { if (log.isDebugEnabled()) { log.debug("prepare timeout listener[" + name + "] of state[" + state.getName() + "]."); } TimeOutListener listener = timeoutListeners.get(name); BusinessCalendar businessCalendar = listener.getBusinessCalendar() != null ? listener.getBusinessCalendar() : this.businessCalendar; Calendar temp = Calendar.getInstance(); if (StringUtils.isNotEmpty(listener.getStartTime())) { Serializable startTimeSer = getVariableValueByEL(listener.getStartTime(), event, true); if (startTimeSer instanceof Date) { temp.setTime((Date) startTimeSer); } else if (startTimeSer instanceof Calendar) { temp.setTime(((Calendar) startTimeSer).getTime()); } else { if (StringUtils.isNumeric(startTimeSer.toString())) { temp.setTimeInMillis(Long.parseLong(startTimeSer.toString())); } } } Job job = new Job(); job.setName(name); job.setBusinessCalendarName(listener.getBusinessCalendarName()); Serializable dueTime = this.getVariableValueByEL(listener.getDueTime(), event, true); if (dueTime == null) { // Job, ?Job if (startTime == null) { log.warn("Job: " + name + " have no dueTime, create fail!"); continue; } else { job.setExecuteTime(startTime); } } else { if (dueTime instanceof Date) { temp.setTimeInMillis(((Date) dueTime).getTime()); } else if (dueTime instanceof Calendar) { temp.setTimeInMillis(((Calendar) dueTime).getTimeInMillis()); } else if (dueTime instanceof Long) { temp.setTimeInMillis((Long) dueTime); } else if (dueTime instanceof String) { temp.setTimeInMillis(businessCalendar.add(temp.getTime(), (String) dueTime).getTime()); } else { throw new RuntimeException("Unsupported DueTime format"); } job.setExecuteTime(temp.getTime()); } if (StringUtils.isNotEmpty(listener.getRepeatDuration())) { job.setRepeatDuration((String) getVariableValueByEL(listener.getRepeatDuration(), event, true)); } if (StringUtils.isNotEmpty(listener.getRepeatTime())) { job.setRepeatTime(Integer .valueOf(getVariableValueByEL(listener.getRepeatTime(), event, true).toString())); } job.setState(state); jobContext.addJob(job); } } else { if (log.isDebugEnabled()) { log.debug("there is no timeout listener in state[" + state.getName() + "]."); } } }
From source file:org.alfresco.rm.rest.api.impl.FilePlanComponentsApiUtils.java
protected PathInfo lookupPathInfo(NodeRef nodeRefIn) { List<ElementInfo> pathElements = new ArrayList<>(); Boolean isComplete = Boolean.TRUE; final Path nodePath = nodeService.getPath(nodeRefIn); ;//w ww .java 2 s .c o m final int pathIndex = 2; for (int i = nodePath.size() - pathIndex; i >= 0; i--) { Element element = nodePath.get(i); if (element instanceof Path.ChildAssocElement) { ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef(); if (elementRef.getParentRef() != null) { NodeRef childNodeRef = elementRef.getChildRef(); if (permissionService.hasPermission(childNodeRef, PermissionService.READ) == AccessStatus.ALLOWED) { Serializable nameProp = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME); pathElements.add(0, new ElementInfo(childNodeRef.getId(), nameProp.toString())); } else { // Just return the pathInfo up to the location where the user has access isComplete = Boolean.FALSE; break; } } } } String pathStr = null; if (pathElements.size() > 0) { StringBuilder sb = new StringBuilder(120); for (PathInfo.ElementInfo e : pathElements) { sb.append("/").append(e.getName()); } pathStr = sb.toString(); } else { // There is no path element, so set it to null in order to be // ignored by Jackson during serialisation isComplete = null; } return new PathInfo(pathStr, isComplete, pathElements); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
public static Node createFileNode(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData content, final ITransformer<IRepositoryFileData> transformer) throws RepositoryException { // Not need to check the name if we encoded it // checkName( file.getName() ); String encodedFileName = JcrStringHelper.fileNameEncode(file.getName()); Node parentFolderNode;/* w w w. j a va 2 s .co m*/ if (parentFolderId != null) { parentFolderNode = session.getNodeByIdentifier(parentFolderId.toString()); } else { parentFolderNode = session.getRootNode(); } // guard against using a file retrieved from a more lenient session inside a more strict session Assert.notNull(parentFolderNode); Node fileNode = parentFolderNode.addNode(encodedFileName, pentahoJcrConstants.getPHO_NT_PENTAHOFILE()); fileNode.setProperty(pentahoJcrConstants.getPHO_CONTENTTYPE(), transformer.getContentType()); fileNode.setProperty(pentahoJcrConstants.getPHO_LASTMODIFIED(), Calendar.getInstance()); fileNode.setProperty(pentahoJcrConstants.getPHO_HIDDEN(), file.isHidden()); fileNode.setProperty(pentahoJcrConstants.getPHO_FILESIZE(), content.getDataSize()); fileNode.setProperty(pentahoJcrConstants.getPHO_ACLNODE(), file.isAclNode()); if (file.getLocalePropertiesMap() != null && !file.getLocalePropertiesMap().isEmpty()) { Node localeNodes = fileNode.addNode(pentahoJcrConstants.getPHO_LOCALES(), pentahoJcrConstants.getPHO_NT_LOCALE()); setLocalePropertiesMap(session, pentahoJcrConstants, localeNodes, file.getLocalePropertiesMap()); } Node metaNode = fileNode.addNode(pentahoJcrConstants.getPHO_METADATA(), JcrConstants.NT_UNSTRUCTURED); setMetadataItemForFile(session, PentahoJcrConstants.PHO_CONTENTCREATOR, file.getCreatorId(), metaNode); fileNode.addMixin(pentahoJcrConstants.getMIX_LOCKABLE()); fileNode.addMixin(pentahoJcrConstants.getMIX_REFERENCEABLE()); if (file.isVersioned()) { // fileNode.setProperty(addPentahoPrefix(session, PentahoJcrConstants.PENTAHO_VERSIONED), true); fileNode.addMixin(pentahoJcrConstants.getPHO_MIX_VERSIONABLE()); } transformer.createContentNode(session, pentahoJcrConstants, content, fileNode); return fileNode; }
From source file:hermes.renderers.DefaultMessageRenderer.java
/** * Depending on configuration, show the object via toString() or a list of * properties./*from ww w.j a v a2 s . co m*/ * * @param objectMessage * @return * @throws JMSException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ protected JComponent handleObjectMessage(final ObjectMessage objectMessage) throws JMSException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { // // Unserialize the object and display all its properties Serializable obj = objectMessage.getObject(); if (obj instanceof JComponent) { return (JComponent) obj; } else { JTextArea textPane = new JTextArea(); StringBuffer buffer = new StringBuffer(); MyConfig currentConfig = (MyConfig) getConfig(); if (obj == null) { buffer.append("Payload is null"); } else if (currentConfig.isToStringOnObjectMessage()) { buffer.append(obj.toString()); } else { buffer.append(obj.toString()).append("\n\nProperty list\n"); for (Iterator iter = PropertyUtils.describe(obj).entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); buffer.append(entry.getKey().toString()).append("=").append(entry.getValue()).append("\n"); } } textPane.setEditable(false); textPane.setText(buffer.toString()); return textPane; } }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileAclDao.java
public RepositoryFileAcl createAcl(final Serializable fileId, final RepositoryFileAcl acl) { if (isKioskEnabled()) { throw new RuntimeException( Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); //$NON-NLS-1$ }//from w w w . ja v a2s. c o m return (RepositoryFileAcl) jcrTemplate.execute(new JcrCallback() { public Object doInJcr(final Session session) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node node = session.getNodeByIdentifier(fileId.toString()); String absPath = node.getPath(); AccessControlManager acMgr = session.getAccessControlManager(); AccessControlList acList = getAccessControlList(acMgr, absPath); acMgr.setPolicy(absPath, acList); return internalUpdateAcl(session, pentahoJcrConstants, fileId, acl); } }); }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImplTest.java
@Test public void testFindEntitiesByPropertyValue() { final String BASE_ID = "testFindEntitiesByPropertyValue"; Map<String, Serializable> props = createEntityProperties(BASE_ID); List<String> expected = new ArrayList<>(); for (int index = 0; index < Byte.SIZE; index++) { String id = BASE_ID + index; repo.setProperties(id, props);//from w w w.j ava 2 s. c o m expected.add(id); } for (Map.Entry<String, Serializable> pe : props.entrySet()) { String propName = pe.getKey(); Serializable propValue = pe.getValue(); List<String> actual = repo.findEntities(propName, propValue); if (!CollectionUtils.isEqualCollection(expected, actual)) { fail("Mismatched results for " + propName + "=" + propValue + ": expected=" + expected + ", actual=" + actual); } // change the type so we know it won't matcj if (propValue instanceof String) { propValue = Integer.valueOf(propValue.hashCode()); } else { propValue = propValue.toString(); } actual = repo.findEntities(propName, propValue); if (ExtendedCollectionUtils.size(actual) > 0) { fail("Unexpected results for " + propName + "=" + propValue + ": " + actual); } } }