List of usage examples for java.util Map.Entry getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:coral.service.ExpTemplateUtil.java
public static String evalVM(String t, Map data, ErrorFlag error, ExpServiceImpl service, Map<String, Object>... adds) { /*// w w w . ja va 2 s . co m * Make a context object and populate with the data. This is where the * Velocity engine gets the data to resolve the references (ex. $list) * in the template */ VelocityContext context = new VelocityContext(); context.put("data", data); context.put("error", error); context.put("_coralhost", CoralUtils.getHostStr()); context.put("_math", new MathTool()); for (Map<String, Object> add : adds) { for (Map.Entry<String, Object> a : add.entrySet()) { context.put(a.getKey(), a.getValue()); } } if (service != null) { context.put("debug", service.debug); } for (Object o : data.entrySet()) { Map.Entry e = (Map.Entry) o; if (e != null && e.getKey() != null && !e.getKey().toString().equals("")) { Object value = data.get(e.getKey()); if (logger.isDebugEnabled()) { logger.debug("entered value: " + e.getKey() + " == " + e.getValue().toString() + " \t\t | " + e.getClass()); } context.put(e.getKey().toString(), value); } } /* * get the Template object. This is the parsed version of your template * input file. */ Template template = null; try { template = Velocity.getTemplate(t); } catch (ResourceNotFoundException rnfe) { logger.error("error : cannot find template " + t, rnfe); return errorPage(template + ": " + rnfe.getMessage()); } catch (ParseErrorException pee) { logger.error("Syntax error in template " + t + ":", pee); return errorPage(template + ": " + pee.getMessage()); } catch (Exception e) { logger.error("Velocity exception in template: " + t + ":", e); return errorPage(template + ": " + e.getMessage()); } /* * Now have the template engine process your template using the data * placed into the context. Think of it as a 'merge' of the template and * the data to produce the output stream. */ StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (ResourceNotFoundException e) { logger.error("vm file not found", e); return errorPage(template + ": " + e.getMessage()); } catch (ParseErrorException e) { logger.error("vm parsing problem", e); return errorPage(template + ": " + e.getMessage()); } catch (MethodInvocationException e) { logger.error("vm mie", e); return errorPage(template + ": " + e.getMessage()); } catch (Exception e) { logger.error("vm exp", e); return errorPage(template + ": " + e.getMessage()); } return writer.toString(); }
From source file:com.pandich.dropwizard.curator.PropertySources.java
@Override public String toString() { final ToStringBuilder builder = new ToStringBuilder(this, TO_STRING_STYLE); for (final Map.Entry<Class, ConcurrentMap<String, PropertySource>> classEntry : this.classPropertySources .entrySet()) {// www.j av a 2 s . c o m final ToStringBuilder classBuilder = new ToStringBuilder(classEntry.getClass(), TO_STRING_STYLE); for (final Map.Entry<String, PropertySource> propertyEntry : classEntry.getValue().entrySet()) { classBuilder.append(propertyEntry.getKey(), propertyEntry.getValue()); } builder.append(classBuilder.toString()); } return builder.build(); }
From source file:coral.service.ExpTemplateUtil.java
public static Object evalExp(String exp, Map<String, Object> data) { Context context = Context.enter(); Scriptable scope = context.initStandardObjects(); for (Map.Entry<String, Object> e : data.entrySet()) { if (e != null && e.getKey() != null && !e.getKey().toString().equals("")) { Object value = e.getValue(); try { try { value = Integer.parseInt(value.toString()); } catch (NumberFormatException ex) { double v = Double.parseDouble(value.toString()); if (Math.round(v) == v) { value = Math.round(v); } else { value = v;/* w ww . j a v a2 s . c o m*/ } } } catch (NumberFormatException ex) { // value = value; } if (logger.isDebugEnabled()) { logger.debug("entered value: " + e.getKey() + " == " + e.getValue().toString() + " \t\t | " + e.getClass()); } scope.put(e.getKey(), scope, value); } } Object o = null; try { o = context.evaluateString(scope, exp, "expression", 1, null); if (logger.isDebugEnabled()) logger.debug("JS OBJECT: " + o); } catch (Exception e) { logger.error("script failed", e); } return o; }
From source file:eu.project.ttc.engines.variant.VariantRuleYamlIO.java
private void fromYaml() { this.variantRules = Lists.newArrayList(); Object yaml = new Yaml().load(this.yaml); Preconditions.checkArgument(yaml instanceof LinkedHashMap, "Bad format for yaml rules file. Expected key-values, got: " + yaml.getClass()); Map<?, ?> map = (Map<?, ?>) yaml; for (Map.Entry<?, ?> entry : map.entrySet()) { String ruleName = (String) entry.getKey(); VariantRuleBuilder builder = VariantRuleBuilder.start(ruleName); Preconditions.checkArgument(entry.getValue() instanceof LinkedHashMap, String.format( "Bad format for rule %s. Expected key-values, got: %s", entry.getKey(), entry.getClass())); Map<?, ?> props = (Map<?, ?>) entry.getValue(); Preconditions.checkArgument(ALLOWED_PROPS.containsAll(props.keySet()), String.format( "Unexcpected property in rule %s. Allowed rule properties: %s", ruleName, ALLOWED_PROPS)); if (props.get(P_SOURCE) != null) parseSourceTarget(builder, ruleName, P_SOURCE, props.get(P_SOURCE)); if (props.get(P_TARGET) != null) parseSourceTarget(builder, ruleName, P_TARGET, props.get(P_TARGET)); if (props.get(P_RULE) != null) { parseRule(builder, ruleName, props.get(P_RULE)); }//from ww w . ja v a2 s.co m this.variantRules.add(builder.create()); } }
From source file:com.basho.riak.presto.CoverageRecordCursor.java
private OtpErlangTuple buildQuery() //List<RiakColumnHandle> columnHandles, //TupleDomain tupleDom) { // case where a='b' Map<ConnectorColumnHandle, Comparable<?>> fixedValues = tupleDomain.extractFixedValues(); for (Map.Entry<ConnectorColumnHandle, Comparable<?>> fixedValue : fixedValues.entrySet()) { log.debug("> %s (%s)", fixedValue, fixedValue.getClass()); log.debug(">> %s", fixedValue.getKey()); checkNotNull(fixedValue.getKey()); checkArgument(fixedValue.getKey() instanceof ConnectorColumnHandle); checkArgument(fixedValue.getKey() instanceof RiakColumnHandle); RiakColumnHandle c = (RiakColumnHandle) fixedValue.getKey(); for (RiakColumnHandle columnHandle : columnHandles) { if (c.getColumn().getName().equals(columnHandle.getColumn().getName()) && c.getColumn().getType().equals(columnHandle.getColumn().getType()) && columnHandle.getColumn().getIndex()) { String field = null; OtpErlangObject value;//w ww .jav a 2 s . c o m if (columnHandle.getColumn().getType() == BigintType.BIGINT) { field = columnHandle.getColumn().getName() + "_int"; Long l = (Long) fixedValue.getValue(); value = new OtpErlangLong(l); } else if (columnHandle.getColumn().getType() == VarcharType.VARCHAR) { field = columnHandle.getColumn().getName() + "_bin"; Slice s = (Slice) fixedValue.getValue(); value = new OtpErlangBinary(s.getBytes()); } else { continue; } OtpErlangObject[] t = { new OtpErlangAtom("eq"), new OtpErlangBinary(field.getBytes()), value }; return new OtpErlangTuple(t); } } } //case where a < b and ... blah Map<RiakColumnHandle, Domain> map = tupleDomain.getDomains(); for (Map.Entry<RiakColumnHandle, Domain> entry : map.entrySet()) { RiakColumnHandle c = entry.getKey(); for (RiakColumnHandle columnHandle : columnHandles) { if (c.getColumn().getName().equals(columnHandle.getColumn().getName()) && c.getColumn().getType().equals(columnHandle.getColumn().getType()) && columnHandle.getColumn().getIndex()) { String field = null; OtpErlangObject lhs, rhs; Range span = entry.getValue().getRanges().getSpan(); //log.debug("value:%s, range:%s, span:%s", // entry.getValue(), entry.getValue().getRanges(),span); //log.debug("min: %s max:%s", span.getLow(), span.getHigh()); if (columnHandle.getColumn().getType() == BigintType.BIGINT) { field = columnHandle.getColumn().getName() + "_int"; // NOTE: Both Erlang and JSON can express smaller integer than Long.MIN_VALUE Long l = Long.MIN_VALUE; if (!span.getLow().isLowerUnbounded()) { l = (Long) span.getLow().getValue(); } // NOTE: Both Erlang and JSON can express greater integer lang Long.MAX_VALUE Long r = Long.MAX_VALUE; if (!span.getHigh().isUpperUnbounded()) { r = (Long) span.getHigh().getValue(); } lhs = new OtpErlangLong(l); rhs = new OtpErlangLong(r); } else if (columnHandle.getColumn().getType() == VarcharType.VARCHAR) { field = columnHandle.getColumn().getName() + "_bin"; //Byte m = Byte.MIN_VALUE; byte[] l = { 0 }; if (!span.getLow().isLowerUnbounded()) { l = ((String) span.getLow().getValue()).getBytes(); } Byte m2 = Byte.MAX_VALUE; byte[] r = { m2 }; if (!span.getHigh().isUpperUnbounded()) { r = ((String) span.getHigh().getValue()).getBytes(); } lhs = new OtpErlangBinary(l); rhs = new OtpErlangBinary(r); } else { continue; } OtpErlangObject[] t = { new OtpErlangAtom("range"), new OtpErlangBinary(field.getBytes()), lhs, rhs }; return new OtpErlangTuple(t); } } } return null; }
From source file:com.adaptris.core.marshaller.xstream.AliasedElementReflectionConverter.java
protected void doMarshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final List<FieldInfo> fields = new ArrayList<>(); final Map<String, java.lang.reflect.Field> defaultFieldDefinition = new HashMap<>(); // Attributes might be preferred to child elements ... reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() { final Set<String> writtenAttributes = new HashSet<>(); public void visit(String fieldName, Class type, Class definedIn, Object value) { if (!mapper.shouldSerializeMember(definedIn, fieldName)) { return; }//from w w w. j a va 2 s. c om if (!defaultFieldDefinition.containsKey(fieldName)) { Class lookupType = source.getClass(); // See XSTR-457 and OmitFieldsTest if (definedIn != source.getClass() && !mapper.shouldSerializeMember(lookupType, fieldName)) { lookupType = definedIn; } defaultFieldDefinition.put(fieldName, reflectionProvider.getField(lookupType, fieldName)); } SingleValueConverter converter = mapper.getConverterFromItemType(fieldName, type, definedIn); if (converter != null) { final String attribute = mapper .aliasForAttribute(mapper.serializedMember(definedIn, fieldName)); if (value != null) { if (writtenAttributes.contains(fieldName)) { // TODO: use attribute throw new ConversionException("Cannot write field with name '" + fieldName + "' twice as attribute for object of type " + source.getClass().getName()); } final String str = converter.toString(value); if (str != null) { writer.addAttribute(attribute, str); } } writtenAttributes.add(fieldName); // TODO: use attribute } else { fields.add(new FieldInfo(fieldName, type, definedIn, value)); } } }); new Object() { { for (Iterator<FieldInfo> fieldIter = fields.iterator(); fieldIter.hasNext();) { FieldInfo info = (FieldInfo) fieldIter.next(); // Check if the field is not null, we don't output null fields if (info.value != null) { Mapper.ImplicitCollectionMapping mapping = mapper .getImplicitCollectionDefForFieldName(source.getClass(), info.fieldName); if (mapping != null) { if (context instanceof ReferencingMarshallingContext) { if (info.value != Collections.EMPTY_LIST && info.value != Collections.EMPTY_SET && info.value != Collections.EMPTY_MAP) { ReferencingMarshallingContext refContext = (ReferencingMarshallingContext) context; refContext.registerImplicit(info.value); } } final boolean isCollection = info.value instanceof Collection; final boolean isMap = info.value instanceof Map; final boolean isEntry = isMap && mapping.getKeyFieldName() == null; final boolean isArray = info.value.getClass().isArray(); for (Iterator iter = isArray ? new ArrayIterator(info.value) : isCollection ? ((Collection) info.value).iterator() : isEntry ? ((Map) info.value).entrySet().iterator() : ((Map) info.value).values().iterator(); iter.hasNext();) { Object obj = iter.next(); final String itemName; final Class itemType; if (obj == null) { itemType = Object.class; itemName = mapper.serializedClass(null); } else if (isEntry) { final String entryName = mapping.getItemFieldName() != null ? mapping.getItemFieldName() : mapper.serializedClass(Map.Entry.class); Map.Entry entry = (Map.Entry) obj; ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass()); writeItem(entry.getKey(), context, writer); writeItem(entry.getValue(), context, writer); writer.endNode(); continue; } else if (mapping.getItemFieldName() != null) { itemType = mapping.getItemType(); itemName = mapping.getItemFieldName(); } else { itemType = obj.getClass(); itemName = mapper.serializedClass(itemType); } writeField(info.fieldName, itemName, itemType, info.definedIn, obj); } } // Field is not an implicit collection else { writeField(info.fieldName, null, info.type, info.definedIn, info.value); } } } } // void writeFieldStandard(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) { // Class actualType = newObj != null ? newObj.getClass() : fieldType; // ExtendedHierarchicalStreamWriterHelper.startNode( // writer, // aliasName != null ? aliasName : mapper.serializedMember( // source.getClass(), fieldName), actualType); // // // We don't process null fields (field values) // if (newObj != null) { // Class defaultType = mapper.defaultImplementationOf(fieldType); // if (!actualType.equals(defaultType)) { // String serializedClassName = mapper.serializedClass(actualType); // if (!serializedClassName // .equals(mapper.serializedClass(defaultType))) { // String attributeName = mapper.aliasForSystemAttribute("class"); // if (attributeName != null) { // writer.addAttribute(attributeName, serializedClassName); // } // } // } // // final Field defaultField = (Field) defaultFieldDefinition // .get(fieldName); // if (defaultField.getDeclaringClass() != definedIn) { // String attributeName = mapper.aliasForSystemAttribute("defined-in"); // if (attributeName != null) { // writer.addAttribute(attributeName, // mapper.serializedClass(definedIn)); // } // } // // Field field = reflectionProvider.getField(definedIn, fieldName); // marshallField(context, newObj, field); // } // writer.endNode(); // } // Modified version of method from that super class void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) { Class<?> actualType = newObj != null ? newObj.getClass() : fieldType; String elementName = aliasName != null ? aliasName : mapper.serializedMember(source.getClass(), fieldName); String classAttributeName = null; String definedAttributeName = null; // We don't process null fields (field values) if (newObj != null) { Class defaultType = mapper.defaultImplementationOf(fieldType); if (!actualType.equals(defaultType)) { String serializedClassName = mapper.serializedClass(actualType); if (!serializedClassName.equals(mapper.serializedClass(defaultType))) { classAttributeName = mapper.aliasForSystemAttribute("class"); } } final Field defaultField = (Field) defaultFieldDefinition.get(fieldName); if (defaultField.getDeclaringClass() != definedIn) { definedAttributeName = mapper.aliasForSystemAttribute("defined-in"); } } writeOutElementBasedOnClassType(elementName, definedIn, actualType, classAttributeName, definedAttributeName); if (newObj != null) { Field field = reflectionProvider.getField(definedIn, fieldName); marshallField(context, newObj, field); } writer.endNode(); } // Now where the super class would have written out the field name // followed by a class attribute that contained the subclass name, // we will write out the subclass alias name as the element with no // class attribute at all. private void writeOutElementBasedOnClassType(String elementName, Class definedIn, Class<?> actualType, String classAttributeName, String definedAttributeName) { boolean isClassAttributeSet = !StringUtils.isBlank(classAttributeName); if (isClassAttributeSet) { String serializedClassName = mapper.serializedClass(actualType); ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedClassName, actualType); } else { String serializedClassName = mapper.serializedClass(actualType); ExtendedHierarchicalStreamWriterHelper.startNode(writer, elementName, actualType); if (classAttributeName != null) { writer.addAttribute(classAttributeName, serializedClassName); } if (definedAttributeName != null) { writer.addAttribute(definedAttributeName, mapper.serializedClass(definedIn)); } } } void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) { if (item == null) { String name = mapper.serializedClass(null); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class); writer.endNode(); } else { String name = mapper.serializedClass(item.getClass()); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass()); context.convertAnother(item); writer.endNode(); } } }; }
From source file:org.grycap.gpf4med.ext.GraphConnectorManager.java
public ImmutableList<GraphConnectorInformation> getConnectorsInformation() { final ImmutableList.Builder<GraphConnectorInformation> builder = new ImmutableList.Builder<GraphConnectorInformation>(); // get connectors for (final Map.Entry<String, GraphConnector> connector : connectors().entrySet()) { try {/* w ww. ja v a 2 s .com*/ // resource classes final Class<?> resourceDefinition = connector.getValue().restResourceDefinition(); final Class<?> resourceImplementation = connector.getValue().restResourceImplementation(); checkArgument(resourceDefinition.isAnnotationPresent(Path.class), "No @Path annotation found, resource definition must be a REST resource"); checkArgument(resourceDefinition.isInterface(), "Resource definition is not an interface"); checkArgument(resourceDefinition.isAssignableFrom(resourceImplementation), "Resource does not implements the definition"); // path final String path = connector.getKey(); checkArgument(path.equals(resourceDefinition.getAnnotation(Path.class).value()), "Path does not coincide with with @Path annotation"); checkArgument(path.matches(".*/v\\d+$"), "Path does not contain API version (e.g. resource/v1)"); // version String version = null; List<String> items = new ArrayList<String>( pluginInformation.getInformation(Information.VERSION, connector.getValue())); if (items != null && items.size() == 1) { version = formatVersion(items.get(0)); } else { throw new IllegalStateException("Cannot find version"); } // author String author = null; items = new ArrayList<String>( pluginInformation.getInformation(Information.AUTHORS, connector.getValue())); if (items != null && items.size() > 0) { String authors = ""; int i = 0; for (; i < items.size() - 1; i++) { authors += items.get(i) + "; "; } authors += items.get(i); author = authors; } // package name String packageName = getPluginPackagename(connector.getValue()); if (StringUtils.isNotBlank(packageName)) { packageName = FilenameUtils.getName(new URI(packageName).getPath()); } // description String description = null; if (StringUtils.isNotBlank(connector.getValue().getDescription())) { description = connector.getValue().getDescription(); } builder.add(new GraphConnectorInformation(path, resourceDefinition, resourceImplementation, version, author, packageName, description)); } catch (Exception e) { LOGGER.warn( "Incomplete information found in the connector: " + connector.getClass().getCanonicalName(), e); } } return builder.build(); }
From source file:org.jahia.services.content.JCRStoreService.java
@SuppressWarnings("unchecked") public void setValidators(Map<String, String> validators) { if (validators == null) { return;/*from w ww . j av a 2 s . c o m*/ } for (Map.Entry<String, String> validator : validators.entrySet()) { try { addValidator(validator.getKey(), (Class<? extends JCRNodeValidator>) Class.forName(validator.getValue())); } catch (ClassNotFoundException e) { logger.error("Unable to find the validator class " + validator.getClass() + " defined for node type " + validator.getKey(), e); } } }
From source file:podd.resources.services.TabImportService.java
/** * Creates a JSON object mapping temporary IDs to the newly created podd object IDs * @return/*ww w . ja v a2 s . c o m*/ */ private JSONObject createJsonIdMap() { JSONObject json = new JSONObject(); if (tabImporter != null) { try { Map<String, URI> tempIdMap = tabImporter.getTempIdMap(); if (tempIdMap != null) { for (Map.Entry<String, URI> entry : tempIdMap.entrySet()) { if (entry.getClass() != null && entry.getValue() != null) { json.put(entry.getKey(), entry.getValue().toString()); } } } } catch (JSONException e) { final String msg = "Error creating JSON object map. "; LOGGER.error(msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Tab import Service: " + msg, e.toString()); } } if (_DEBUG) { LOGGER.debug("json = " + json); } return json; }