Java Code Examples for javax.management.openmbean.OpenType

The following are top voted examples for showing how to use javax.management.openmbean.OpenType. 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: OpenJSharp   File: DefaultMXBeanMappingFactory.java   View source code 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 2
Project: jdk8u-jdk   File: LazyCompositeData.java   View source code 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 3
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   View source code 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 4
Project: openjdk-jdk10   File: TypeVersionMapper.java   View source code 6 votes vote down vote up
private ArrayType<?> getVersionedArrayType(ArrayType<?> type, String version)
    throws OpenDataException
{
    if (type.isPrimitiveArray()) {
        return type;
    }
    OpenType<?> ot = getVersionedType(
        type.getElementOpenType(),
        version
    );
    if (ot instanceof SimpleType) {
        return new ArrayType<>((SimpleType<?>)ot, type.isPrimitiveArray());
    } else {
        return new ArrayType<>(type.getDimension(), ot);
    }
}
 
Example 5
Project: openjdk-jdk10   File: LazyCompositeData.java   View source code 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 6
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   View source code 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 7
Project: hashsdn-controller   File: JavaAttribute.java   View source code 6 votes vote down vote up
@Override
public OpenType<?> getOpenType() {
    final TypeDefinition<?> baseTypeDefinition = getBaseType(this.typeProviderWrapper, this.typeDefinition);
    final Type baseType = this.typeProviderWrapper.getType(baseTypeDefinition, baseTypeDefinition);

    if (isArray()) {
        return getArrayType();
    } else if (isEnum()) {
        return getEnumType(baseTypeDefinition);
    } else if (isUnion()) {
        return getCompositeTypeForUnion(baseTypeDefinition);
    } else if (isDerivedType(baseType, getType())) {
        return getCompositeType(baseType, baseTypeDefinition);
    } else if (isIdentityRef()) {
        return getCompositeTypeForIdentity();
    }

    return getSimpleType(getType());
}
 
Example 8
Project: hashsdn-controller   File: JavaAttribute.java   View source code 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 9
Project: hashsdn-controller   File: InstanceConfig.java   View source code 6 votes vote down vote up
private void resolveConfiguration(final InstanceConfigElementResolved mappedConfig,
                                  final ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) {

    // TODO make field, resolvingStrategies can be instantiated only once
    Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(
            depTracker).prepareResolving(yangToAttrConfig, enumResolver);

    for (Entry<String, AttributeConfigElement> configDefEntry : mappedConfig.getConfiguration().entrySet()) {
        AttributeConfigElement value = configDefEntry.getValue();
        String attributeName = configDefEntry.getKey();
        try {
            AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy = resolvingStrategies
                    .get(attributeName);
            LOG.trace("Trying to set value {} of attribute {} with {}", value, attributeName,
                    attributeResolvingStrategy);

            value.resolveValue(attributeResolvingStrategy, attributeName);
            value.setJmxName(yangToAttrConfig.get(attributeName).getUpperCaseCammelCase());
        } catch (final DocumentedException e) {
            throw new IllegalStateException("Unable to resolve value " + value + " to attribute " + attributeName,
                    e);
        }
    }
}
 
Example 10
Project: hashsdn-controller   File: TOAttribute.java   View source code 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 11
Project: alfresco-core   File: JMXUtils.java   View source code 5 votes vote down vote up
public static OpenType<?> getOpenType(Object o)
{
    if(o instanceof Long)
    {
        return SimpleType.LONG;
    }
    else if(o instanceof String)
    {
        return SimpleType.STRING;
    }
    else if(o instanceof Date)
    {
        return SimpleType.DATE;
    }
    else if(o instanceof Integer)
    {
        return SimpleType.INTEGER;
    }
    else if(o instanceof Boolean)
    {
        return SimpleType.BOOLEAN;
    }
    else if(o instanceof Double)
    {
        return SimpleType.DOUBLE;
    }
    else if(o instanceof Float)
    {
        return SimpleType.FLOAT;
    }
    else
    {
        throw new IllegalArgumentException();
    }
}
 
Example 12
Project: hashsdn-controller   File: ObjectXmlReader.java   View source code 5 votes vote down vote up
@Override
protected AttributeReadingStrategy caseJavaIdentityRefAttribute(final OpenType<?> openType) {
    Preconditions.checkState(openType instanceof CompositeType);
    Set<String> keys = ((CompositeType) openType).keySet();
    Preconditions.checkState(keys.size() == 1, "Unexpected number of elements for open type %s, should be 1",
            openType);
    String mappingKey = keys.iterator().next();
    return new SimpleIdentityRefAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey,
            identityMap);
}
 
Example 13
Project: OpenJSharp   File: GcInfoCompositeData.java   View source code 5 votes vote down vote up
static synchronized OpenType[] getBaseGcInfoItemTypes() {
    if (baseGcInfoItemTypes == null) {
        OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
        baseGcInfoItemTypes = new OpenType<?>[] {
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,

            memoryUsageOpenType,
            memoryUsageOpenType,
        };
    }
    return baseGcInfoItemTypes;
}
 
Example 14
Project: OpenJSharp   File: LazyCompositeData.java   View source code 5 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.
 */
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;

    for (String item: allItems) {
        OpenType<?> ot1 = type1.getType(item);
        OpenType<?> ot2 = type2.getType(item);
        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.equals(ot2)) {
            return false;
        }
    }
    return true;
}
 
Example 15
Project: OpenJSharp   File: MXBeanIntrospector.java   View source code 5 votes vote down vote up
private static Descriptor typeDescriptor(OpenType<?> openType,
                                         Type originalType) {
    return new ImmutableDescriptor(
        new String[] {"openType",
                      "originalType"},
        new Object[] {openType,
                      originalTypeString(originalType)});
}
 
Example 16
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   View source code 5 votes vote down vote up
private MXBeanMapping
    makeArrayOrCollectionMapping(Type collectionType, Type elementType,
                                 MXBeanMappingFactory factory)
        throws OpenDataException {

    final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
    final OpenType<?> elementOpenType = elementMapping.getOpenType();
    final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
    final Class<?> elementOpenClass = elementMapping.getOpenClass();

    final Class<?> openArrayClass;
    final String openArrayClassName;
    if (elementOpenClass.isArray())
        openArrayClassName = "[" + elementOpenClass.getName();
    else
        openArrayClassName = "[L" + elementOpenClass.getName() + ";";
    try {
        openArrayClass = Class.forName(openArrayClassName);
    } catch (ClassNotFoundException e) {
        throw openDataException("Cannot obtain array class", e);
    }

    if (collectionType instanceof ParameterizedType) {
        return new CollectionMapping(collectionType,
                                     openType, openArrayClass,
                                     elementMapping);
    } else {
        if (isIdentity(elementMapping)) {
            return new IdentityMapping(collectionType,
                                       openType);
        } else {
            return new ArrayMapping(collectionType,
                                      openType,
                                      openArrayClass,
                                      elementMapping);
        }
    }
}
 
Example 17
Project: ysoserial-modified   File: JSON1.java   View source code 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 18
Project: monarch   File: OpenTypeConverter.java   View source code 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 19
Project: hashsdn-controller   File: ObjectResolver.java   View source code 5 votes vote down vote up
public Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> prepareResolving(
        final Map<String, AttributeIfc> configDefinition, final EnumResolver enumResolver) {
    this.enumResolver = enumResolver;

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

    for (Entry<String, AttributeIfc> attrEntry : configDefinition.entrySet()) {
        strategies.put(attrEntry.getKey(), prepareStrategy(attrEntry.getValue()));
    }

    return strategies;
}
 
Example 20
Project: ChronoBike   File: CompositeTypeDesc.java   View source code 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 21
Project: jdk8u-jdk   File: GcInfoCompositeData.java   View source code 5 votes vote down vote up
static synchronized OpenType[] getBaseGcInfoItemTypes() {
    if (baseGcInfoItemTypes == null) {
        OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
        baseGcInfoItemTypes = new OpenType<?>[] {
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,

            memoryUsageOpenType,
            memoryUsageOpenType,
        };
    }
    return baseGcInfoItemTypes;
}
 
Example 22
Project: jdk8u-jdk   File: MXBeanMapping.java   View source code 5 votes vote down vote up
private static Class<?> makeOpenClass(Type javaType, OpenType<?> openType) {
    if (javaType instanceof Class<?> && ((Class<?>) javaType).isPrimitive())
        return (Class<?>) javaType;
    try {
        String className = openType.getClassName();
        return Class.forName(className, false, MXBeanMapping.class.getClassLoader());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);  // should not happen
    }
}
 
Example 23
Project: jdk8u-jdk   File: MXBeanIntrospector.java   View source code 5 votes vote down vote up
private static Descriptor typeDescriptor(OpenType<?> openType,
                                         Type originalType) {
    return new ImmutableDescriptor(
        new String[] {"openType",
                      "originalType"},
        new Object[] {openType,
                      originalTypeString(originalType)});
}
 
Example 24
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   View source code 5 votes vote down vote up
private MXBeanMapping
    makeArrayOrCollectionMapping(Type collectionType, Type elementType,
                                 MXBeanMappingFactory factory)
        throws OpenDataException {

    final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
    final OpenType<?> elementOpenType = elementMapping.getOpenType();
    final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
    final Class<?> elementOpenClass = elementMapping.getOpenClass();

    final Class<?> openArrayClass;
    final String openArrayClassName;
    if (elementOpenClass.isArray())
        openArrayClassName = "[" + elementOpenClass.getName();
    else
        openArrayClassName = "[L" + elementOpenClass.getName() + ";";
    try {
        openArrayClass = Class.forName(openArrayClassName);
    } catch (ClassNotFoundException e) {
        throw openDataException("Cannot obtain array class", e);
    }

    if (collectionType instanceof ParameterizedType) {
        return new CollectionMapping(collectionType,
                                     openType, openArrayClass,
                                     elementMapping);
    } else {
        if (isIdentity(elementMapping)) {
            return new IdentityMapping(collectionType,
                                       openType);
        } else {
            return new ArrayMapping(collectionType,
                                      openType,
                                      openArrayClass,
                                      elementMapping);
        }
    }
}
 
Example 25
Project: jdk8u-jdk   File: MerlinMXBean.java   View source code 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 26
Project: hashsdn-controller   File: CompositeAttributeMappingStrategy.java   View source code 5 votes vote down vote up
public CompositeAttributeMappingStrategy(final CompositeType compositeType,
        final Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies,
        final Map<String, String> jmxToJavaNameMapping) {
    super(compositeType);
    this.innerStrategies = innerStrategies;
    this.jmxToJavaNameMapping = jmxToJavaNameMapping;
}
 
Example 27
Project: openjdk-jdk10   File: GcInfoCompositeData.java   View source code 5 votes vote down vote up
static synchronized OpenType<?>[] getBaseGcInfoItemTypes() {
    if (baseGcInfoItemTypes == null) {
        OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
        baseGcInfoItemTypes = new OpenType<?>[] {
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,
            SimpleType.LONG,

            memoryUsageOpenType,
            memoryUsageOpenType,
        };
    }
    return baseGcInfoItemTypes;
}
 
Example 28
Project: openjdk-jdk10   File: TypeVersionMapper.java   View source code 5 votes vote down vote up
/**
 * Retrieves the specified version of a {@linkplain CompositeType} instance.
 * @param type The current (latest) version of {@linkplain CompositeType}
 * @param version The version identifier (eg. {@linkplain TypeVersionMapper#V5})
 * @return Returns the {@linkplain CompositeType} corresponding to the requested
 *         version.
 * @throws OpenDataException
 */
CompositeType getVersionedCompositeType(CompositeType type, String version)
    throws OpenDataException
{
    Predicate<String> filter = getFilter(type.getTypeName(), version);
    if (filter == null) {
        return type;
    }

    List<String> itemNames = new ArrayList<>();
    List<String> itemDesc = new ArrayList<>();
    List<OpenType<?>> itemTypes = new ArrayList<>();

    for(String item : type.keySet()) {
        if (filter.test(item)) {
            itemNames.add(item);
            itemDesc.add(type.getDescription(item));
            itemTypes.add(getVersionedType(
                type.getType(item),
                version
            ));
        }
    }
    return new CompositeType(
        type.getTypeName(),
        version != null ? version + " " + type.getDescription() : type.getDescription(),
        itemNames.toArray(new String[itemNames.size()]),
        itemDesc.toArray(new String[itemDesc.size()]),
        itemTypes.toArray(new OpenType<?>[itemTypes.size()])
    );
}
 
Example 29
Project: openjdk-jdk10   File: TypeVersionMapper.java   View source code 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 30
Project: openjdk-jdk10   File: MXBeanMapping.java   View source code 5 votes vote down vote up
private static Class<?> makeOpenClass(Type javaType, OpenType<?> openType) {
    if (javaType instanceof Class<?> && ((Class<?>) javaType).isPrimitive())
        return (Class<?>) javaType;
    try {
        String className = openType.getClassName();
        return Class.forName(className, false, MXBeanMapping.class.getClassLoader());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);  // should not happen
    }
}
 
Example 31
Project: openjdk-jdk10   File: MXBeanIntrospector.java   View source code 5 votes vote down vote up
private static Descriptor typeDescriptor(OpenType<?> openType,
                                         Type originalType) {
    return new ImmutableDescriptor(
        new String[] {"openType",
                      "originalType"},
        new Object[] {openType,
                      originalTypeString(originalType)});
}
 
Example 32
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   View source code 5 votes vote down vote up
private MXBeanMapping
    makeArrayOrCollectionMapping(Type collectionType, Type elementType,
                                 MXBeanMappingFactory factory)
        throws OpenDataException {

    final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
    final OpenType<?> elementOpenType = elementMapping.getOpenType();
    final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
    final Class<?> elementOpenClass = elementMapping.getOpenClass();

    final Class<?> openArrayClass;
    final String openArrayClassName;
    if (elementOpenClass.isArray())
        openArrayClassName = "[" + elementOpenClass.getName();
    else
        openArrayClassName = "[L" + elementOpenClass.getName() + ";";
    try {
        openArrayClass = Class.forName(openArrayClassName);
    } catch (ClassNotFoundException e) {
        throw openDataException("Cannot obtain array class", e);
    }

    if (collectionType instanceof ParameterizedType) {
        return new CollectionMapping(collectionType,
                                     openType, openArrayClass,
                                     elementMapping);
    } else {
        if (isIdentity(elementMapping)) {
            return new IdentityMapping(collectionType,
                                       openType);
        } else {
            return new ArrayMapping(collectionType,
                                      openType,
                                      openArrayClass,
                                      elementMapping);
        }
    }
}
 
Example 33
Project: hashsdn-controller   File: CompositeAttributeResolvingStrategy.java   View source code 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 34
Project: openjdk-jdk10   File: MerlinMXBean.java   View source code 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 35
Project: openjdk-jdk10   File: MerlinMXBean.java   View source code 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 36
Project: hashsdn-controller   File: JavaAttribute.java   View source code 5 votes vote down vote up
private OpenType<?> getEnumType(final TypeDefinition<?> baseType) {
    final String fullyQualifiedName = this.typeProviderWrapper.getType(this.node, getTypeDefinition()).getFullyQualifiedName();
    final String[] items = {"instance"};
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

    try {
        return new CompositeType(fullyQualifiedName, description, items, items, new OpenType[]{SimpleType.STRING});
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create enum type" + fullyQualifiedName + " as open type", e);
    }
}
 
Example 37
Project: hashsdn-controller   File: CompositeAttributeMappingStrategy.java   View source code 5 votes vote down vote up
protected Optional<?> mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName,
        final String description) {
    Object innerValue = compositeData.get(jmxName);

    AttributeMappingStrategy<?, ? extends OpenType<?>> attributeMappingStrategy = innerStrategies.get(jmxName);
    return attributeMappingStrategy.mapAttribute(innerValue);
}
 
Example 38
Project: hashsdn-controller   File: JavaAttribute.java   View source code 5 votes vote down vote up
public OpenType<?> getCompositeTypeForIdentity() {
    final String[] itemNames = new String[]{IdentityAttributeRef.QNAME_ATTR_NAME};
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
    final OpenType<?>[] itemTypes = new OpenType[]{SimpleType.STRING};

    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 39
Project: hashsdn-controller   File: JavaAttribute.java   View source code 5 votes vote down vote up
private OpenType<?> getArrayOpenTypeForSimpleType(final String innerTypeFullyQName, final SimpleType<?> innerSimpleType) {
    try {
        final ArrayType<Object> arrayType = isPrimitive(innerTypeFullyQName) ? new ArrayType<>(innerSimpleType, true)
                : new ArrayType<>(1, innerSimpleType);
        return arrayType;
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create " + ArrayType.class + " with inner element of type "
                + innerSimpleType, e);
    }
}
 
Example 40
Project: hashsdn-controller   File: InstanceConfig.java   View source code 5 votes vote down vote up
@SuppressWarnings("IllegalCatch")
private Map<String, Object> getMappedConfiguration(final ObjectName on, final EnumResolver enumResolver) {

    // TODO make field, mappingStrategies can be instantiated only once
    Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> mappingStrategies = new ObjectMapper()
            .prepareMapping(jmxToAttrConfig, enumResolver);

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

    for (Entry<String, AttributeIfc> configDefEntry : jmxToAttrConfig.entrySet()) {
        // Skip children runtime beans as they are mapped by InstanceRuntime
        if (configDefEntry.getValue() instanceof RuntimeBeanEntry) {
            continue;
        }
        Object value = configRegistryClient.getAttributeCurrentValue(on, configDefEntry.getKey());
        try {
            AttributeMappingStrategy<?, ? extends OpenType<?>> attributeMappingStrategy = mappingStrategies
                    .get(configDefEntry.getKey());
            Optional<?> attribute = attributeMappingStrategy.mapAttribute(value);
            if (!attribute.isPresent()) {
                continue;
            }
            toXml.put(configDefEntry.getValue().getAttributeYangName(), attribute.get());
        } catch (final RuntimeException e) {
            throw new IllegalStateException("Unable to map value " + value + " to attribute "
                    + configDefEntry.getKey(), e);
        }
    }
    return toXml;
}