List of usage examples for java.io Serializable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.ag.repo.transfer.RepoPrimaryManifestProcessorImpl.java
/** * This method takes all the received properties and separates them into two parts. The content properties are * removed from the non-content properties such that the non-content properties remain in the "props" map and the * content properties are returned from this method Subsequently, any properties that are to be retained from the * local repository are copied over into the "props" map. The result of all this is that, upon return, "props" * contains all the non-content properties that are to be written to the local repo, and "contentProps" contains all * the content properties that are to be written to the local repo. * /*from ww w. ja v a 2 s .c o m*/ * @param nodeToUpdate * The noderef of the existing node in the local repo that is to be updated with these properties. May be * null, indicating that these properties are destined for a brand new local node. * @param props * @return A map containing the content properties from the supplied "props" map */ private Map<QName, Serializable> processProperties(NodeRef nodeToUpdate, Map<QName, Serializable> props, boolean isNew) { Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); // ...and copy any supplied content properties into this new map... for (Map.Entry<QName, Serializable> propEntry : props.entrySet()) { Serializable value = propEntry.getValue(); if (log.isDebugEnabled()) { if (value == null) { log.debug("Received a null value for property " + propEntry.getKey()); } } if ((value != null) && ContentData.class.isAssignableFrom(value.getClass())) { contentProps.put(propEntry.getKey(), propEntry.getValue()); } } // Now we can remove the content properties from amongst the other kinds // of properties // (no removeAll on a Map...) for (QName contentPropertyName : contentProps.keySet()) { props.remove(contentPropertyName); } if (!isNew) { // Finally, overlay the repo-specific properties from the existing // node (if there is one) Map<QName, Serializable> existingProps = (nodeToUpdate == null) ? new HashMap<QName, Serializable>() : nodeService.getProperties(nodeToUpdate); for (QName localProperty : getLocalProperties()) { Serializable existingValue = existingProps.get(localProperty); if (existingValue != null) { props.put(localProperty, existingValue); } else { props.remove(localProperty); } } } return contentProps; }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.provider.RuleFieldPersistenceProvider.java
protected boolean populateSimpleRule(PopulateValueRequest populateValueRequest, Serializable instance) throws Exception { boolean dirty = false; String prop = populateValueRequest.getProperty().getName(); if (prop.contains(FieldManager.MAPFIELDSEPARATOR)) { Field field = populateValueRequest.getFieldManager().getField(instance.getClass(), prop.substring(0, prop.indexOf(FieldManager.MAPFIELDSEPARATOR))); if (field.getAnnotation(OneToMany.class) == null) { throw new UnsupportedOperationException( "RuleFieldPersistenceProvider is currently only compatible with map fields when modelled using @OneToMany"); }/* w w w . ja v a2 s.c om*/ } DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator(); //AntiSamy HTML encodes the rule JSON - pass the unHTMLEncoded version DataWrapper dw = ruleFieldExtractionUtility .convertJsonToDataWrapper(populateValueRequest.getProperty().getUnHtmlEncodedValue()); if (dw == null || StringUtils.isEmpty(dw.getError())) { String mvel = ruleFieldExtractionUtility.convertSimpleMatchRuleJsonToMvel(translator, RuleIdentifier.ENTITY_KEY_MAP.get(populateValueRequest.getMetadata().getRuleIdentifier()), populateValueRequest.getMetadata().getRuleIdentifier(), dw); Class<?> valueType = getStartingValueType(populateValueRequest); //This is a simple String field (or String map field) if (String.class.isAssignableFrom(valueType)) { //first check if the property is null and the mvel is null if (instance != null && mvel == null) { Object value = populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()); dirty = value != null; } else { dirty = checkDirtyState(populateValueRequest, instance, mvel); } populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), mvel); } if (SimpleRule.class.isAssignableFrom(valueType)) { boolean persist = false; SimpleRule rule; try { rule = (SimpleRule) populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()); if (rule == null) { rule = (SimpleRule) valueType.newInstance(); Field field = populateValueRequest.getFieldManager().getField(instance.getClass(), prop.substring(0, prop.indexOf(FieldManager.MAPFIELDSEPARATOR))); OneToMany oneToMany = field.getAnnotation(OneToMany.class); Object parent = extractParent(populateValueRequest, instance); populateValueRequest.getFieldManager().setFieldValue(rule, oneToMany.mappedBy(), parent); populateValueRequest.getFieldManager().setFieldValue(rule, populateValueRequest.getMetadata().getMapKeyValueProperty(), prop.substring(prop.indexOf(FieldManager.MAPFIELDSEPARATOR) + FieldManager.MAPFIELDSEPARATOR.length(), prop.length())); persist = true; } } catch (FieldNotAvailableException e) { throw new IllegalArgumentException(e); } if (mvel == null) { //cause the rule to be deleted dirty = populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()) != null; if (dirty) { if (!populateValueRequest.getProperty().getName() .contains(FieldManager.MAPFIELDSEPARATOR)) { populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), null); } else { populateValueRequest.getPersistenceManager().getDynamicEntityDao().remove(rule); } } } else if (rule != null) { dirty = !mvel.equals(rule.getMatchRule()); if (!dirty && extensionManager != null) { ExtensionResultHolder<Boolean> resultHolder = new ExtensionResultHolder<Boolean>(); ExtensionResultStatusType result = extensionManager.getProxy().establishDirtyState(rule, resultHolder); if (ExtensionResultStatusType.NOT_HANDLED != result && resultHolder.getResult() != null) { dirty = resultHolder.getResult(); } } if (dirty) { updateSimpleRule(populateValueRequest, mvel, persist, rule); } } } } return dirty; }
From source file:org.openiot.gsn.beans.StreamElement.java
/** * Verify if the data corresponds to the fieldType * @param fieldType/* ww w .ja v a 2 s.co m*/ * @param data * @throws IllegalArgumentException */ private void verifyTypeCompatibility(Byte fieldType, Serializable data) throws IllegalArgumentException { if (data == null) return; switch (fieldType) { case DataTypes.TINYINT: if (!(data instanceof Byte)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.SMALLINT: if (!(data instanceof Short)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.BIGINT: if (!(data instanceof Long)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.CHAR: case DataTypes.VARCHAR: if (!(data instanceof String)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.INTEGER: if (!(data instanceof Integer)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.DOUBLE: if (!(data instanceof Double || data instanceof Float)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.BINARY: // if ( data[ i ] instanceof String ) data[ i ] = ( ( String ) // data[ i ] ).getBytes( ); if (!(data instanceof byte[] || data instanceof String)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; } }
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/*ww w. j a va 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:gsn.beans.StreamElement.java
/** * Verify if the data corresponds to the fieldType * @param fieldType/*from ww w .ja v a 2s. co m*/ * @param data * @throws IllegalArgumentException */ private void verifyTypeCompatibility(Byte fieldType, Serializable data) throws IllegalArgumentException { if (data == null) return; switch (fieldType) { case DataTypes.TINYINT: if (!(data instanceof Byte)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.SMALLINT: if (!(data instanceof Short)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.BIGINT: if (!(data instanceof Long)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.CHAR: case DataTypes.VARCHAR: if (!(data instanceof String)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.INTEGER: if (!(data instanceof Integer)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.DOUBLE: if (!(data instanceof Double || data instanceof Float)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.FLOAT: if (!(data instanceof Float)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; case DataTypes.BINARY: // if ( data[ i ] instanceof String ) data[ i ] = ( ( String ) // data[ i ] ).getBytes( ); if (!(data instanceof byte[] || data instanceof String)) throw new IllegalArgumentException("The field is defined as " + DataTypes.TYPE_NAMES[fieldType] + " while the actual data in the field is of type : *" + data.getClass().getCanonicalName() + "*"); break; } }
From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java
private boolean isValueInstanceOfDefinedClass(QName qname, Serializable value) { PortletApplicationDefinition app = portletWindow.getPortletEntity().getPortletDefinition().getApplication(); List<? extends EventDefinition> events = app.getEventDefinitions(); if (events != null) { for (EventDefinition def : events) { if (def.getQName() != null) { if (def.getQName().equals(qname)) return value.getClass().getName().equals(def.getValueType()); } else { QName tmp = new QName(app.getDefaultNamespace(), def.getName()); if (tmp.equals(qname)) return value.getClass().getName().equals(def.getValueType()); }//w w w . j av a 2s. com } } // event not declared return true; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.TestCswRecordConverter.java
private void assertDateConversion(Serializable ser, Calendar expectedDate) { assertThat(ser, not(nullValue()));//from w w w. j a v a 2 s. co m assertThat(Date.class.isAssignableFrom(ser.getClass()), is(true)); Date date = (Date) ser; Calendar cal = Calendar.getInstance(); cal.setTime(date); assertThat(cal.get(Calendar.MONTH), equalTo(expectedDate.get(Calendar.MONTH))); assertThat(cal.get(Calendar.YEAR), equalTo(expectedDate.get(Calendar.YEAR))); assertThat(cal.get(Calendar.DAY_OF_MONTH), equalTo(expectedDate.get(Calendar.DAY_OF_MONTH))); }
From source file:net.sf.jasperreports.compilers.JavaScriptCompilerBase.java
@Override protected JREvaluator loadEvaluator(Serializable compileData, String unitName) throws JRException { if (compileData instanceof JavaScriptCompileData) { if (log.isDebugEnabled()) { log.debug("JavaScriptCompileData found for " + unitName); }//from www. j a v a 2 s . c o m JavaScriptCompileData jsCompileData = (JavaScriptCompileData) compileData; return new JavaScriptEvaluator(jasperReportsContext, jsCompileData); } if (compileData instanceof JavaScriptCompiledData) { JavaScriptCompiledData jsCompiledData = (JavaScriptCompiledData) compileData; return new JavaScriptCompiledEvaluator(jasperReportsContext, unitName, jsCompiledData); } throw new JRException(EXCEPTION_MESSAGE_KEY_INVALID_COMPILE_DATA_TYPE, new Object[] { compileData.getClass().getName() }); }
From source file:net.di2e.ecdr.commons.CDRMetacard.java
protected <T> T getAttributeValue(Attribute attribute, Class<T> returnType) { Serializable data = attribute.getValue(); if (returnType.isAssignableFrom(data.getClass())) { return returnType.cast(data); } else {//from www .jav a 2 s. c om if (LOGGER.isDebugEnabled()) { LOGGER.trace(data.getClass().toString() + " can not be assigned to " + returnType.toString()); } } return null; }