List of usage examples for java.io Serializable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.atlas.storm.hook.StormAtlasHook.java
private Referenceable createSpoutInstance(String spoutName, SpoutSpec stormSpout) throws IllegalAccessException { Referenceable spoutReferenceable = new Referenceable(StormDataTypes.STORM_SPOUT.getName()); spoutReferenceable.set(AtlasClient.NAME, spoutName); Serializable instance = Utils.javaDeserialize(stormSpout.get_spout_object().get_serialized_java(), Serializable.class); spoutReferenceable.set("driverClass", instance.getClass().getName()); Map<String, String> flatConfigMap = StormTopologyUtil.getFieldValues(instance, true, null); spoutReferenceable.set("conf", flatConfigMap); return spoutReferenceable; }
From source file:org.apache.atlas.storm.hook.StormAtlasHook.java
private void addTopologyInputs(Referenceable topologyReferenceable, Map<String, SpoutSpec> spouts, Map stormConf, String topologyOwner, List<Referenceable> dependentEntities) throws IllegalAccessException { final ArrayList<Referenceable> inputDataSets = new ArrayList<>(); for (Map.Entry<String, SpoutSpec> entry : spouts.entrySet()) { Serializable instance = Utils.javaDeserialize(entry.getValue().get_spout_object().get_serialized_java(), Serializable.class); String simpleName = instance.getClass().getSimpleName(); final Referenceable datasetRef = createDataSet(simpleName, topologyOwner, instance, stormConf, dependentEntities);/* w w w . j av a 2 s . c om*/ if (datasetRef != null) { inputDataSets.add(datasetRef); } } topologyReferenceable.set("inputs", inputDataSets); }
From source file:ddf.catalog.validation.impl.validator.SizeValidator.java
/** * {@inheritDoc}//from w w w .j a v a 2 s . c om * <p> * Validates only the values of {@code attribute} that are {@link CharSequence}s, * {@link Collection}s, {@link Map}s, or arrays. */ @Override public Optional<AttributeValidationReport> validate(final Attribute attribute) { Preconditions.checkArgument(attribute != null, "The attribute cannot be null."); final String name = attribute.getName(); for (final Serializable value : attribute.getValues()) { int size; if (value instanceof CharSequence) { size = ((CharSequence) value).length(); } else if (value instanceof Collection) { size = ((Collection) value).size(); } else if (value instanceof Map) { size = ((Map) value).size(); } else if (value != null && value.getClass().isArray()) { size = Array.getLength(value); } else { continue; } if (!checkSize(size)) { final String violationMessage = String.format("%s size must be between %d and %d", name, min, max); final AttributeValidationReportImpl report = new AttributeValidationReportImpl(); report.addViolation( new ValidationViolationImpl(Collections.singleton(name), violationMessage, Severity.ERROR)); return Optional.of(report); } } return Optional.empty(); }
From source file:com.github.maoo.indexer.webscripts.NodeDetailsWebScript.java
private Map<String, Pair<String, String>> toStringMap(Map<QName, Serializable> propertyMap) { Map<String, Pair<String, String>> ret = new HashMap<String, Pair<String, String>>(1, 1.0f); for (QName propertyName : propertyMap.keySet()) { Serializable propertyValue = propertyMap.get(propertyName); if (propertyValue != null) { String propertyType = propertyValue.getClass().getName(); String stringValue = propertyValue.toString(); if (propertyType.equals("java.util.Date")) { stringValue = sdf.format(propertyValue); }//from w w w . ja v a2 s. c o m ret.put(propertyName.toPrefixString(namespaceService), new Pair<String, String>(propertyType, stringValue)); } } return ret; }
From source file:org.apache.atlas.storm.hook.StormAtlasHook.java
private void addTopologyOutputs(Referenceable topologyReferenceable, StormTopology stormTopology, String topologyOwner, Map stormConf, List<Referenceable> dependentEntities) throws Exception { final ArrayList<Referenceable> outputDataSets = new ArrayList<>(); Map<String, Bolt> bolts = stormTopology.get_bolts(); Set<String> terminalBoltNames = StormTopologyUtil.getTerminalUserBoltNames(stormTopology); for (String terminalBoltName : terminalBoltNames) { Serializable instance = Utils.javaDeserialize( bolts.get(terminalBoltName).get_bolt_object().get_serialized_java(), Serializable.class); String dataSetType = instance.getClass().getSimpleName(); final Referenceable datasetRef = createDataSet(dataSetType, topologyOwner, instance, stormConf, dependentEntities);/* w w w .java 2 s. com*/ if (datasetRef != null) { outputDataSets.add(datasetRef); } } topologyReferenceable.set("outputs", outputDataSets); }
From source file:org.alfresco.repo.action.executer.ContentMetadataExtracter.java
/** * Iterates the values of the taggable property which the metadata * extractor should have already attempted to convert values to {@link NodeRef}s. * <p>// ww w. j a va 2s . c o m * If conversion by the metadata extracter failed due to a MalformedNodeRefException * the taggable property should still contain raw string values. * <p> * Mixing of NodeRefs and string values is permitted so each raw value is * checked for a valid NodeRef representation and if so, converts to a NodeRef, * if not, adds as a tag via the {@link TaggingService}. * * @param actionedUponNodeRef The NodeRef being actioned upon * @param propertyDef the PropertyDefinition of the taggable property * @param rawValue the raw value from the metadata extracter */ @SuppressWarnings("unchecked") protected void addTags(NodeRef actionedUponNodeRef, PropertyDefinition propertyDef, Serializable rawValue) { List<String> tags = new ArrayList<String>(); if (logger.isDebugEnabled()) { logger.debug("converting " + rawValue.toString() + " of type " + rawValue.getClass().getCanonicalName() + " to tags"); } if (rawValue instanceof Collection<?>) { for (Object singleValue : (Collection<?>) rawValue) { if (singleValue instanceof String) { if (NodeRef.isNodeRef((String) singleValue)) { // Convert to a NodeRef Serializable convertedPropertyValue = (Serializable) DefaultTypeConverter.INSTANCE .convert(propertyDef.getDataType(), (String) singleValue); try { String tagName = (String) nodeService.getProperty((NodeRef) convertedPropertyValue, ContentModel.PROP_NAME); if (logger.isTraceEnabled()) { logger.trace("found tag '" + tagName + "' from tag nodeRef '" + (String) singleValue + "', " + "adding to " + actionedUponNodeRef.toString()); } if (tagName != null && !tagName.equals("")) { tags.add(tagName); } } catch (InvalidNodeRefException e) { if (logger.isWarnEnabled()) { logger.warn("tag nodeRef Invalid: " + e.getMessage()); } } } else { // Must be a simple string if (logger.isTraceEnabled()) { logger.trace("adding string tag '" + (String) singleValue + "' to " + actionedUponNodeRef.toString()); } tags.add((String) singleValue); } } else if (singleValue instanceof NodeRef) { String tagName = (String) nodeService.getProperty((NodeRef) singleValue, ContentModel.PROP_NAME); tags.add(tagName); } } } else if (rawValue instanceof String) { if (logger.isTraceEnabled()) { logger.trace("adding tag '" + (String) rawValue + "' to " + actionedUponNodeRef.toString()); } tags.add((String) rawValue); } taggingService.addTags(actionedUponNodeRef, tags); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCLogger.java
/** * Returns a loggable value using pseudo-SQL syntax. */// ww w . j ava2 s . co m @SuppressWarnings("boxing") public static String loggedValue(Serializable value) { if (value == null) { return "NULL"; } if (value instanceof String) { String v = (String) value; if (v.length() > DEBUG_MAX_STRING) { v = v.substring(0, DEBUG_MAX_STRING) + "...(" + v.length() + " chars)..."; } return "'" + v.replace("'", "''") + "'"; } if (value instanceof Calendar) { Calendar cal = (Calendar) value; char sign; int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()) / 60000; if (offset < 0) { offset = -offset; sign = '-'; } else { sign = '+'; } return String.format("TIMESTAMP '%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d'", cal.get(Calendar.YEAR), // cal.get(Calendar.MONTH) + 1, // cal.get(Calendar.DAY_OF_MONTH), // cal.get(Calendar.HOUR_OF_DAY), // cal.get(Calendar.MINUTE), // cal.get(Calendar.SECOND), // cal.get(Calendar.MILLISECOND), // sign, offset / 60, offset % 60); } if (value instanceof Binary) { return "'" + ((Binary) value).getDigest() + "'"; } if (value.getClass().isArray()) { Serializable[] v = (Serializable[]) value; StringBuilder b = new StringBuilder(); b.append('['); for (int i = 0; i < v.length; i++) { if (i > 0) { b.append(','); if (i > DEBUG_MAX_ARRAY) { b.append("...(" + v.length + " items)..."); break; } } b.append(loggedValue(v[i])); } b.append(']'); return b.toString(); } return value.toString(); }
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
private AclIdentifierConverter<?> resolveConverter(final ObjectIdentity identity) { Serializable identifier = identity.getIdentifier(); Assert.notNull(identifier, "Identifier must not be null"); Class<? extends Serializable> identifierClass = Primitives.wrap(identifier.getClass()); return aclIdentifierConverters.get(identifierClass); }
From source file:org.pentaho.platform.web.http.api.resources.services.SchedulerService.java
public Job getJobInfo(String jobId) throws SchedulerException { Job job = getJob(jobId);/*w w w .ja va 2 s . co m*/ if (getSecurityHelper().isPentahoAdministrator(getSession()) || getSession().getName().equals(job.getUserName())) { for (String key : job.getJobParams().keySet()) { Serializable value = job.getJobParams().get(key); if (value != null && value.getClass() != null && value.getClass().isArray()) { String[] sa = (new String[0]).getClass().cast(value); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < sa.length; i++) { list.add(sa[i]); } job.getJobParams().put(key, list); } } return job; } else { throw new RuntimeException("Job not found or improper credentials for access"); } }
From source file:grails.plugin.cache.web.GenericResponseWrapper.java
public Collection<Header<? extends Serializable>> getAllHeaders() { List<Header<? extends Serializable>> headers = new LinkedList<Header<? extends Serializable>>(); for (Map.Entry<String, List<Serializable>> headerEntry : headersMap.entrySet()) { String name = headerEntry.getKey(); for (Serializable value : headerEntry.getValue()) { // Null Check for value before doing value.getClass() // FIX for: http://jira.grails.org/browse/GPCACHE-37 if (value != null) { Type type = Header.Type.determineType(value.getClass()); switch (type) { case STRING: headers.add(new Header<String>(name, (String) value)); break; case DATE: headers.add(new Header<Long>(name, (Long) value)); break; case INT: headers.add(new Header<Integer>(name, (Integer) value)); break; default: throw new IllegalArgumentException("No mapping for Header.Type: " + type); }//from w ww. j av a 2 s. c om } } } return headers; }