/** {@inheritDoc} */ @Override Object convertToObject(SimpleType pType, Object pFrom) { return stringToObjectConverter.prepareValue(pType.getClassName(), pFrom); } }
/** * Add a JSON representation of a JMX OpenMBean SimpleType instance to an existing JSON Object. * * @param targetMap the target Map * @param key the key to use for the value of the SimpleType * @param value the SimpleType value */ public void addSimpleType(Map<String, Object> targetMap, String key, SimpleType value) { if (targetMap == null) { throw new NullPointerException("The target Map argument cannot be null"); } if (value == null) { if (includeNullAttributes) { targetMap.put(key, value); } } else { String valueString = value.toString(); if (valueString.isEmpty() && includeEmptyAttributes) { targetMap.put(key, valueString); } else { targetMap.put(key, valueString); } } }
private Object[] createTargetArray(OpenType pElementType, int pLength) { if (pElementType instanceof SimpleType) { try { SimpleType simpleType = (SimpleType) pElementType; Class elementClass = Class.forName(simpleType.getClassName()); return (Object[]) Array.newInstance(elementClass, pLength); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Can't find class " + pElementType.getClassName() + " for instantiating array: " + e.getMessage(),e); } } else if (pElementType instanceof CompositeType) { return new CompositeData[pLength]; } else { throw new UnsupportedOperationException("Unsupported array element type: " + pElementType); } } }
private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) { /* fields that were not given in the JSON must be added with * null for Objects and the default value for primitives */ for (String itemName : pType.keySet()) { if (!pCompositeValues.containsKey(itemName)) { Object itemValue = null; OpenType itemType = pType.getType(itemName); if (itemType instanceof SimpleType) { SimpleType sType = (SimpleType) itemType; itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName()); } pCompositeValues.put(itemName, itemValue); } } }
public JMXSupport() { classForSimpleTypeMap = new HashMap<String, SimpleType>(); for(SimpleType type : supportedSimpleTypes) { classForSimpleTypeMap.put(type.getClassName(), type); } }
/** {@inheritDoc} */ @Override Object convertToObject(SimpleType pType, Object pFrom) { return stringToObjectConverter.prepareValue(pType.getClassName(), pFrom); } }
@Override public String toString() { return "ResolvedSimpleAttribute [" + getOpenType().getClassName() + "]"; }
/** {@inheritDoc} */ @Override Object convertToObject(SimpleType pType, Object pFrom) { return stringToObjectConverter.deserialize(pType.getClassName(), pFrom); } }
/** {@inheritDoc} */ @Override Object convertToObject(SimpleType pType, Object pFrom) { return stringToObjectConverter.prepareValue(pType.getClassName(), pFrom); } }
@Nullable protected Class<?> tryLoadClassFor(@Nullable SimpleType<?> simpleType) { return tryLoadClassBy(simpleType != null ? simpleType.getClassName() : null); }
private Object[] createTargetArray(OpenType pElementType, int pLength) { if (pElementType instanceof SimpleType) { try { SimpleType simpleType = (SimpleType) pElementType; Class elementClass = Class.forName(simpleType.getClassName()); return (Object[]) Array.newInstance(elementClass, pLength); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Can't find class " + pElementType.getClassName() + " for instantiating array: " + e.getMessage(),e); } } else if (pElementType instanceof CompositeType) { return new CompositeData[pLength]; } else { throw new UnsupportedOperationException("Unsupported array element type: " + pElementType); } } }
@Override public Optional<String> mapAttribute(Object value) { if (value == null){ return Optional.absent(); } String expectedClass = getOpenType().getClassName(); String realClass = value.getClass().getName(); Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass + " but was " + realClass); WriterPlugin prefferedPlugin = writerPlugins.get(value.getClass().getCanonicalName()); prefferedPlugin = prefferedPlugin == null ? writerPlugins.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin; return Optional.of(prefferedPlugin.writeObject(value)); }
private Object[] createTargetArray(OpenType pElementType, int pLength) { if (pElementType instanceof SimpleType) { try { SimpleType simpleType = (SimpleType) pElementType; Class elementClass = Class.forName(simpleType.getClassName()); return (Object[]) Array.newInstance(elementClass, pLength); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Can't find class " + pElementType.getClassName() + " for instantiating array: " + e.getMessage(),e); } } else if (pElementType instanceof CompositeType) { return new CompositeData[pLength]; } else { throw new UnsupportedOperationException("Unsupported array element type: " + pElementType); } } }
private Object[] createTargetArray(OpenType pElementType, int pLength) { if (pElementType instanceof SimpleType) { try { SimpleType simpleType = (SimpleType) pElementType; Class elementClass = Class.forName(simpleType.getClassName()); return (Object[]) Array.newInstance(elementClass, pLength); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Can't find class " + pElementType.getClassName() + " for instantiating array: " + e.getMessage(),e); } } else if (pElementType instanceof CompositeType) { return new CompositeData[pLength]; } else { throw new UnsupportedOperationException("Unsupported array element type: " + pElementType); } } }
private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) { /* fields that were not given in the JSON must be added with * null for Objects and the default value for primitives */ for (String itemName : pType.keySet()) { if (!pCompositeValues.containsKey(itemName)) { Object itemValue = null; OpenType itemType = pType.getType(itemName); if (itemType instanceof SimpleType) { SimpleType sType = (SimpleType) itemType; itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName()); } pCompositeValues.put(itemName, itemValue); } } }
private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) { /* fields that were not given in the JSON must be added with * null for Objects and the default value for primitives */ for (String itemName : pType.keySet()) { if (!pCompositeValues.containsKey(itemName)) { Object itemValue = null; OpenType itemType = pType.getType(itemName); if (itemType instanceof SimpleType) { SimpleType sType = (SimpleType) itemType; itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName()); } pCompositeValues.put(itemName, itemValue); } } }
private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) { /* fields that were not given in the JSON must be added with * null for Objects and the default value for primitives */ for (String itemName : pType.keySet()) { if (!pCompositeValues.containsKey(itemName)) { Object itemValue = null; OpenType itemType = pType.getType(itemName); if (itemType instanceof SimpleType) { SimpleType sType = (SimpleType) itemType; itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName()); } pCompositeValues.put(itemName, itemValue); } } }
@Override public Optional<Object> parseAttribute(String attrName, Object value) throws NetconfDocumentedException { if (value == null) { return Optional.absent(); } Class<?> cls; try { cls = Class.forName(getOpenType().getClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to locate class for " + getOpenType().getClassName(), e); } Util.checkType(value, String.class); Resolver prefferedPlugin = resolverPlugins.get(cls.getCanonicalName()); prefferedPlugin = prefferedPlugin == null ? resolverPlugins.get(DEFAULT_RESOLVERS) : prefferedPlugin; Object parsedValue = prefferedPlugin.resolveObject(cls, attrName, (String) value); LOG.debug("Attribute {} : {} parsed to type {} with value {}", attrName, value, getOpenType(), parsedValue); return Optional.of(parsedValue); }
@Override public Optional<MappedDependency> mapAttribute(Object value) { if (value == null){ return Optional.absent(); } String expectedClass = getOpenType().getClassName(); String realClass = value.getClass().getName(); Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass + " but was " + realClass); Util.checkType(value, ObjectName.class); ObjectName on = (ObjectName) value; String refName = ObjectNameUtil.getReferenceName(on); //we want to use the exact service name that was configured in xml so services that are referencing it can be resolved return Optional.of(new MappedDependency(namespace, QName.create(ObjectNameUtil.getServiceQName(on)).getLocalName(), refName)); }