Java Code Examples for javax.management.openmbean.CompositeType

The following are top voted examples for showing how to use javax.management.openmbean.CompositeType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: tomcat7   File: SlowQueryReport.java   Source Code and License 6 votes vote down vote up
public CompositeDataSupport getCompositeData(final CompositeType type) throws OpenDataException{
    Object[] values = new Object[] {
            query,
            Integer.valueOf(nrOfInvocations),
            Long.valueOf(maxInvocationTime),
            Long.valueOf(maxInvocationDate),
            Long.valueOf(minInvocationTime),
            Long.valueOf(minInvocationDate),
            Long.valueOf(totalInvocationTime),
            Long.valueOf(failures),
            Integer.valueOf(prepareCount),
            Long.valueOf(prepareTime),
            Long.valueOf(lastInvocation)
    };
    return new CompositeDataSupport(type,FIELD_NAMES,values);
}
 
Example 2
Project: OpenJSharp   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 3
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example 4
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 5
Project: hashsdn-controller   File: UnionCompositeAttributeResolvingStrategy.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> preprocessValueMap(final Map<?, ?> valueMap) {
    CompositeType openType = getOpenType();

    Preconditions.checkArgument(
            valueMap.size() == 1 && valueMap.containsKey(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION),
            "Unexpected structure of incoming map, expecting one element under %s, but was %s",
            JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION, valueMap);

    Map<String, Object> newMap = Maps.newHashMap();

    for (String key : openType.keySet()) {
        if (openType.getDescription(key).equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)) {
            newMap.put(key, valueMap.get(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION));
        } else {
            newMap.put(key, null);
        }
    }
    return newMap;
}
 
Example 6
Project: monarch   File: CompositeConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Converts to open value
 */
final Object toNonNullOpenValue(Object value) throws OpenDataException {
  CompositeType ct = (CompositeType) getOpenType();
  if (value instanceof CompositeDataView)
    return ((CompositeDataView) value).toCompositeData(ct);
  if (value == null)
    return null;

  Object[] values = new Object[getters.length];
  for (int i = 0; i < getters.length; i++) {
    try {
      Object got = getters[i].invoke(value, (Object[]) null);
      values[i] = getterConverters[i].toOpenValue(got);
    } catch (Exception e) {
      throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e);
    }
  }
  return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 7
Project: ChronoBike   File: BaseOpenMBean.java   Source Code and License 6 votes vote down vote up
protected void addOpenAttribute(String csDescription, Class cls, String csMethodName, CompositeType compositeType)
{
	Method methodGet = MethodFinder.getMethod(cls, "get"+csMethodName);
	boolean bCanGet = true;
	if(methodGet == null)
		bCanGet = false;
	Method methodSet = MethodFinder.getMethod(cls, "set"+csMethodName, CompositeData.class);
	boolean bCanSet = true;
	if(methodSet == null)
		bCanSet = false;

	OpenMBeanAttributeInfoSupport attrOpen = new OpenMBeanAttributeInfoSupport(csMethodName, csDescription, compositeType, bCanGet, bCanSet, false); 
	OpenMBeanAttributeInfoWrapper attr = new OpenMBeanAttributeInfoWrapper(csMethodName, csDescription, attrOpen, methodGet, methodSet);
	
	if(m_arrOpenMBeanAttributeInfosWrapper == null)
		m_arrOpenMBeanAttributeInfosWrapper = new ArrayList<OpenMBeanAttributeInfoWrapper>();
	m_arrOpenMBeanAttributeInfosWrapper.add(attr);
}
 
Example 8
Project: apache-tomcat-7.0.73-with-comment   File: SlowQueryReport.java   Source Code and License 6 votes vote down vote up
public CompositeDataSupport getCompositeData(final CompositeType type) throws OpenDataException{
    Object[] values = new Object[] {
            query,
            Integer.valueOf(nrOfInvocations),
            Long.valueOf(maxInvocationTime),
            Long.valueOf(maxInvocationDate),
            Long.valueOf(minInvocationTime),
            Long.valueOf(minInvocationDate),
            Long.valueOf(totalInvocationTime),
            Long.valueOf(failures),
            Integer.valueOf(prepareCount),
            Long.valueOf(prepareTime),
            Long.valueOf(lastInvocation)
    };
    return new CompositeDataSupport(type,FIELD_NAMES,values);
}
 
Example 9
Project: jdk8u-jdk   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 10
Project: jdk8u-jdk   File: LazyCompositeData.java   Source Code and License 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code true} if all items in type1 exist in type2 and their item
 *         types are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 11
Project: jdk8u-jdk   File: LazyCompositeData.java   Source Code and License 6 votes vote down vote up
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) {
    if (ot1 instanceof CompositeType) {
        if (! (ot2 instanceof CompositeType))
            return false;
        if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
            return false;
    } else if (ot1 instanceof TabularType) {
        if (! (ot2 instanceof TabularType))
            return false;
        if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
            return false;
    } else if (ot1 instanceof ArrayType) {
        if (! (ot2 instanceof ArrayType))
            return false;
        if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) {
            return false;
        }
    } else if (!ot1.equals(ot2)) {
        return false;
    }
    return true;
}
 
Example 12
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example 13
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example 14
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 15
Project: openjdk-jdk10   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 16
Project: openjdk-jdk10   File: LazyCompositeData.java   Source Code and License 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code true} if all items in type1 exist in type2 and their item
 *         types are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 17
Project: openjdk-jdk10   File: LazyCompositeData.java   Source Code and License 6 votes vote down vote up
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) {
    if (ot1 instanceof CompositeType) {
        if (! (ot2 instanceof CompositeType))
            return false;
        if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
            return false;
    } else if (ot1 instanceof TabularType) {
        if (! (ot2 instanceof TabularType))
            return false;
        if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
            return false;
    } else if (ot1 instanceof ArrayType) {
        if (! (ot2 instanceof ArrayType))
            return false;
        if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) {
            return false;
        }
    } else if (!ot1.equals(ot2)) {
        return false;
    }
    return true;
}
 
Example 18
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example 19
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example 20
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 21
Project: hashsdn-controller   File: JavaAttribute.java   Source Code and License 6 votes vote down vote up
private OpenType<?> getCompositeType(final Type baseType, final TypeDefinition<?> baseTypeDefinition) {

        final SimpleType<?> innerItemType = SimpleTypeResolver.getSimpleType(baseType);
        final String innerItemName = this.typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);

        final String[] itemNames = new String[]{innerItemName};
        final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

        final OpenType<?>[] itemTypes = new OpenType[]{innerItemType};
        try {
            return new CompositeType(getUpperCaseCammelCase(), description, itemNames, itemNames, itemTypes);
        } catch (final OpenDataException e) {
            throw new RuntimeException("Unable to create " + CompositeType.class + " with inner element of type "
                    + itemTypes, e);
        }
    }
 
Example 22
Project: hashsdn-controller   File: TOAttribute.java   Source Code and License 6 votes vote down vote up
@Override
public CompositeType getOpenType() {
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

    final FunctionImpl functionImpl = new FunctionImpl();
    final Map<String, AttributeIfc> jmxPropertiesToTypesMap = getJmxPropertiesToTypesMap();
    final OpenType<?>[] itemTypes = Collections2.transform(
            jmxPropertiesToTypesMap.entrySet(), functionImpl).toArray(
            new OpenType<?>[] {});
    final String[] itemNames = functionImpl.getItemNames();
    try {
        // TODO add package name to create fully qualified name for this
        // type
        final CompositeType compositeType = new CompositeType(
                getUpperCaseCammelCase(), description, itemNames,
                itemNames, itemTypes);
        return compositeType;
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create CompositeType for "
                + this, e);
    }
}
 
Example 23
Project: hadoop-oss   File: JMXJsonServlet.java   Source Code and License 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example 24
Project: APacheSynapseSimplePOC   File: JSON1.java   Source Code and License 5 votes vote down vote up
/**
 * Will call all getter methods on payload that are defined in the given interfaces
 */
public static Map makeCallerChain ( Object payload, Class... ifaces ) throws OpenDataException, NoSuchMethodException, InstantiationException,
        IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
    CompositeType rt = new CompositeType("a", "b", new String[] {
        "a"
    }, new String[] {
        "a"
    }, new OpenType[] {
        javax.management.openmbean.SimpleType.INTEGER
    });
    TabularType tt = new TabularType("a", "b", rt, new String[] {
        "a"
    });
    TabularDataSupport t1 = new TabularDataSupport(tt);
    TabularDataSupport t2 = new TabularDataSupport(tt);

    // we need to make payload implement composite data
    // it's very likely that there are other proxy impls that could be used
    AdvisedSupport as = new AdvisedSupport();
    as.setTarget(payload);
    InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections
            .getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
    InvocationHandler cdsInvocationHandler = Gadgets.createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
    CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
    invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
    invocationHandler.setDefaultHandler(delegateInvocationHandler);
    final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);

    JSONObject jo = new JSONObject();
    Map m = new HashMap();
    m.put("t", cdsProxy);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(t1, "dataMap", jo);
    Reflections.setFieldValue(t2, "dataMap", jo);
    return Gadgets.makeMap(t1, t2);
}
 
Example 25
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 5 votes vote down vote up
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(final OpenType<?> openType) {

    Preconditions.checkState(openType instanceof CompositeType, "Unexpected open type, expected %s but was %s");
    CompositeType compositeType = (CompositeType) openType;

    Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap = Maps.newHashMap();
    Map<String, String> yangToJmxMapping = Maps.newHashMap();
    fillMappingForComposite(compositeType, innerMap, yangToJmxMapping);

    return new UnionCompositeAttributeResolvingStrategy(innerMap, compositeType, yangToJmxMapping);
}
 
Example 26
Project: hashsdn-controller   File: CompositeAttributeResolvingStrategy.java   Source Code and License 5 votes vote down vote up
CompositeAttributeResolvingStrategy(
        final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
        final CompositeType openType, final Map<String, String> yangToJavaAttrMapping) {
    super(openType);
    this.innerTypes = innerTypes;
    this.yangToJavaAttrMapping = yangToJavaAttrMapping;
}
 
Example 27
Project: monarch   File: OpenTypeConverter.java   Source Code and License 5 votes vote down vote up
private static OpenTypeConverter makeTabularConverter(Type objType, boolean sortedMap,
    Type keyType, Type valueType) throws OpenDataException {

  final String objTypeName = objType.toString();
  final OpenTypeConverter keyConverter = toConverter(keyType);
  final OpenTypeConverter valueConverter = toConverter(valueType);
  final OpenType keyOpenType = keyConverter.getOpenType();
  final OpenType valueOpenType = valueConverter.getOpenType();
  final CompositeType rowType = new CompositeType(objTypeName, objTypeName, keyValueArray,
      keyValueArray, new OpenType[] {keyOpenType, valueOpenType});
  final TabularType tabularType = new TabularType(objTypeName, objTypeName, rowType, keyArray);
  return new TableConverter(objType, sortedMap, tabularType, keyConverter, valueConverter);
}
 
Example 28
Project: monarch   File: CompositeConverter.java   Source Code and License 5 votes vote down vote up
CompositeConverter(Class targetClass, CompositeType compositeType, String[] itemNames,
    Method[] getters) throws OpenDataException {
  super(targetClass, compositeType, CompositeData.class);

  assert (itemNames.length == getters.length);

  this.itemNames = itemNames;
  this.getters = getters;
  this.getterConverters = new OpenTypeConverter[getters.length];
  for (int i = 0; i < getters.length; i++) {
    Type retType = getters[i].getGenericReturnType();
    getterConverters[i] = OpenTypeConverter.toConverter(retType);
  }
}
 
Example 29
Project: ChronoBike   File: LogCenter.java   Source Code and License 5 votes vote down vote up
public CompositeType getStateType()
{
	CompositeTypeDesc compositeTypeDesc = new CompositeTypeDesc("LogCenterCompositeType", "LogCenterCompositeType Desc");
	compositeTypeDesc.addItem("Enable", "EnableDesc", SimpleType.BOOLEAN);
	compositeTypeDesc.addItem("Level", "LevelDesc", SimpleType.STRING);
	return compositeTypeDesc.generateCompositeType();
}
 
Example 30
Project: ChronoBike   File: LogCenter.java   Source Code and License 5 votes vote down vote up
public CompositeData getState()
{
	CompositeType compositeType = getStateType();
	CompositeDataDesc compositeDataDesc = new CompositeDataDesc(compositeType);
	compositeDataDesc.setItemValue("Enable", getEnable());
	compositeDataDesc.setItemValue("Level", getLevel());
	return compositeDataDesc.generateCompositeData();
}
 
Example 31
Project: ChronoBike   File: CompositeTypeDesc.java   Source Code and License 5 votes vote down vote up
public CompositeType generateCompositeType()
{
	try
	{
		int nNbItems = m_arrItemDesc.size();
		OpenType [] openTypes = new OpenType [nNbItems];
		String [] itemTypeNames = new String [nNbItems];
		String [] itemTypeDescriptions = new String [nNbItems];
		for(int n=0; n<nNbItems; n++)
		{
			CompositeTypeDescItem itemDesc = m_arrItemDesc.get(n);
			openTypes[n] = itemDesc.m_openType;
			itemTypeNames[n] = itemDesc.m_csName;
			itemTypeDescriptions[n] = itemDesc.m_csDescription;			
		}
		
		CompositeType compositeType = new CompositeType(
			m_csName,
		    m_csDescription,
		    itemTypeNames,
		    itemTypeDescriptions,
		    openTypes);
		return compositeType;
	}
	catch (OpenDataException e)
	{
		e.printStackTrace();
	}
	return null;
}
 
Example 32
Project: hadoop   File: JMXJsonServlet.java   Source Code and License 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example 33
Project: jdk8u-jdk   File: TigerMXBean.java   Source Code and License 5 votes vote down vote up
static TabularType make(String typeName, String description,
                        CompositeType rowType, String[] indexNames) {
    try {
        return new TabularType(typeName, description, rowType,
                               indexNames);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 34
Project: jdk8u-jdk   File: MerlinMXBean.java   Source Code and License 5 votes vote down vote up
static CompositeType make(String className,
                          String description,
                          String[] itemNames,
                          String[] itemDescriptions,
                          OpenType[] itemTypes) {
    try {
        return new CompositeType(className,
                                 description,
                                 itemNames,
                                 itemDescriptions,
                                 itemTypes);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 35
Project: jdk8u-jdk   File: MerlinMXBean.java   Source Code and License 5 votes vote down vote up
public CompositeData toCompositeData(CompositeType ct) {
    try {
        return new CompositeDataSupport(ct, new String[] {"whatsit"},
                                        new String[] {"!" + whatsit});
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 36
Project: jdk8u-jdk   File: AttributeArbitraryDataTypeTest.java   Source Code and License 5 votes vote down vote up
public CompositeData getCompositeDataAttribute()
    throws OpenDataException {
    CompositeType ct = new CompositeType("CompositeDataAttribute",
                                         "Composite Data Attribute",
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
    Object itemValues[] = { ia, da, sa };
    return new CompositeDataSupport(ct, itemNames, itemValues);
}
 
Example 37
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 5 votes vote down vote up
private void fillMappingForComposite(final CompositeType openType,
        final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap,
        final Map<String, String> yangToJmxMapping) {
    for (String innerAttributeKey : openType.keySet()) {
        innerMap.put(innerAttributeKey, caseJavaAttribute(openType.getType(innerAttributeKey)));
        yangToJmxMapping.put(innerAttributeKey, innerAttributeKey);
    }
}
 
Example 38
Project: hashsdn-controller   File: AttributeIfcSwitchStatement.java   Source Code and License 5 votes vote down vote up
public final T caseJavaAttribute(final OpenType<?> openType) {
    if (openType instanceof SimpleType<?>) {
        return caseJavaSimpleAttribute((SimpleType<?>) openType);
    } else if (openType instanceof ArrayType<?>) {
        return caseJavaArrayAttribute((ArrayType<?>) openType);
    } else if (openType instanceof CompositeType) {
        return caseJavaCompositeAttribute((CompositeType) openType);
    }

    throw new UnknownOpenTypeException("Unknown attribute open type " + openType);
}
 
Example 39
Project: openjdk-jdk10   File: TypeVersionMapper.java   Source Code and License 5 votes vote down vote up
private OpenType<?> getVersionedType(OpenType<?> type, String version)
    throws OpenDataException
{
    if (type instanceof ArrayType) {
        return getVersionedArrayType((ArrayType)type, version);
    }
    if (type instanceof CompositeType) {
        return getVersionedCompositeType((CompositeType)type, version);
    }
    if (type instanceof TabularType) {
        return getVersionedTabularType((TabularType)type, version);
    }
    return type;
}
 
Example 40
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 5 votes vote down vote up
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseTOAttribute(final CompositeType openType) {
    Preconditions.checkState(getLastAttribute() instanceof TOAttribute);
    TOAttribute toAttribute = (TOAttribute) getLastAttribute();

    Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap = Maps.newHashMap();

    for (String innerName : openType.keySet()) {

        AttributeIfc innerAttributeIfc = toAttribute.getJmxPropertiesToTypesMap().get(innerName);
        innerMap.put(innerAttributeIfc.getAttributeYangName(), prepareStrategy(innerAttributeIfc));
    }
    return new CompositeAttributeResolvingStrategy(innerMap, openType, createYangToJmxMapping(toAttribute));
}