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   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 2
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 3
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 4
Project: openjdk-jdk10   File: TypeVersionMapper.java   Source Code and License 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   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 6
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 7
Project: hashsdn-controller   File: JavaAttribute.java   Source Code and License 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   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 9
Project: hashsdn-controller   File: InstanceConfig.java   Source Code and License 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   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 11
Project: alfresco-core   File: JMXUtils.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   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 18
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 19
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 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   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 21
Project: jdk8u-jdk   File: GcInfoCompositeData.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   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 26
Project: hashsdn-controller   File: CompositeAttributeMappingStrategy.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   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 30
Project: openjdk-jdk10   File: MXBeanMapping.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   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 34
Project: openjdk-jdk10   File: MerlinMXBean.java   Source Code and License 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   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 36
Project: hashsdn-controller   File: JavaAttribute.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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;
}
 
Example 41
Project: hashsdn-controller   File: ObjectMapper.java   Source Code and License 5 votes vote down vote up
public Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> prepareMapping(
        final Map<String, AttributeIfc> configDefinition, final EnumResolver enumResolver) {
    this.enumResolver = Preconditions.checkNotNull(enumResolver);
    Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> strategies = Maps.newHashMap();

    for (Entry<String, AttributeIfc> attrEntry : configDefinition.entrySet()) {
        strategies.put(attrEntry.getKey(), prepareStrategy(attrEntry.getValue()));
    }
    return strategies;
}
 
Example 42
Project: hashsdn-controller   File: ObjectMapper.java   Source Code and License 5 votes vote down vote up
public AttributeMappingStrategy<?, ? extends OpenType<?>> prepareStrategy(final AttributeIfc attributeIfc) {

        if (attributeIfc instanceof DependencyAttribute) {
            namespaceOfDepAttr = ((DependencyAttribute) attributeIfc).getDependency().getSie().getQName().getNamespace()
                    .toString();
        } else if (attributeIfc instanceof ListDependenciesAttribute) {
            namespaceOfDepAttr = ((ListDependenciesAttribute) attributeIfc).getDependency().getSie().getQName()
                    .getNamespace().toString();
        }
        return switchAttribute(attributeIfc);
    }
 
Example 43
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 5 votes vote down vote up
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(final ArrayType<?> openType) {

    SimpleType<?> innerType = (SimpleType<?>) openType.getElementOpenType();
    AttributeResolvingStrategy<?, ? extends OpenType<?>> strat = new SimpleAttributeResolvingStrategy(innerType);
    return new ArrayAttributeResolvingStrategy(strat, openType);
}
 
Example 44
Project: hashsdn-controller   File: ObjectMapper.java   Source Code and License 5 votes vote down vote up
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(
        final CompositeType openType) {
    Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();

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

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

        innerStrategies.put(innerAttributeKey, caseJavaAttribute(openType.getType(innerAttributeKey)));
        attributeMapping.put(innerAttributeKey, innerAttributeKey);
    }
    return new CompositeAttributeMappingStrategy(openType, innerStrategies, attributeMapping);
}
 
Example 45
Project: hashsdn-controller   File: ObjectMapper.java   Source Code and License 5 votes vote down vote up
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(final OpenType<?> openType) {
    Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();

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

    CompositeType compositeType = (CompositeType) openType;
    for (String innerAttributeKey : compositeType.keySet()) {

        innerStrategies.put(innerAttributeKey, caseJavaAttribute(compositeType.getType(innerAttributeKey)));
        attributeMapping.put(innerAttributeKey, innerAttributeKey);
    }
    return new UnionCompositeAttributeMappingStrategy(compositeType, innerStrategies, attributeMapping);
}
 
Example 46
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 4 votes vote down vote up
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(
        final SimpleType<?> openType) {
    return new SimpleAttributeResolvingStrategy(openType);
}
 
Example 47
Project: tomcat7   File: SlowQueryReport.java   Source Code and License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public static OpenType[] getFieldTypes() {
    return FIELD_TYPES;
}
 
Example 48
Project: lams   File: SimpleTriggerSupport.java   Source Code and License 4 votes vote down vote up
public static OpenType[] getItemTypes() {
    List<OpenType> l = new ArrayList<OpenType>(Arrays.asList(ITEM_TYPES));
    l.addAll(Arrays.asList(TriggerSupport.getItemTypes()));
    return l.toArray(new OpenType[l.size()]);
}
 
Example 49
Project: hashsdn-controller   File: ObjectResolver.java   Source Code and License 4 votes vote down vote up
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
        final SimpleType<?> openType) {
    return new ObjectNameAttributeResolvingStrategy(serviceTracker);
}
 
Example 50
Project: OpenJSharp   File: ConvertingMethod.java   Source Code and License 4 votes vote down vote up
OpenType<?> getOpenReturnType() {
    return returnMapping.getOpenType();
}
 
Example 51
Project: OpenJSharp   File: ConvertingMethod.java   Source Code and License 4 votes vote down vote up
OpenType<?>[] getOpenParameterTypes() {
    final OpenType<?>[] types = new OpenType<?>[paramMappings.length];
    for (int i = 0; i < paramMappings.length; i++)
        types[i] = paramMappings[i].getOpenType();
    return types;
}
 
Example 52
Project: hashsdn-controller   File: ObjectXmlReader.java   Source Code and License 4 votes vote down vote up
@Override
protected AttributeReadingStrategy caseJavaUnionAttribute(final OpenType<?> openType) {
    String mappingKey = JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION;
    return new SimpleUnionAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey);
}
 
Example 53
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 4 votes vote down vote up
NonNullMXBeanMapping(Type javaType, OpenType<?> openType) {
    super(javaType, openType);
}
 
Example 54
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 4 votes vote down vote up
private MXBeanMapping makeCompositeMapping(Class<?> c,
                                           MXBeanMappingFactory factory)
        throws OpenDataException {

    // For historical reasons GcInfo implements CompositeData but we
    // shouldn't count its CompositeData.getCompositeType() field as
    // an item in the computed CompositeType.
    final boolean gcInfoHack =
        (c.getName().equals("com.sun.management.GcInfo") &&
            c.getClassLoader() == null);

    ReflectUtil.checkPackageAccess(c);
    final List<Method> methods =
            MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
    final SortedMap<String,Method> getterMap = newSortedMap();

    /* Select public methods that look like "T getX()" or "boolean
       isX()", where T is not void and X is not the empty
       string.  Exclude "Class getClass()" inherited from Object.  */
    for (Method method : methods) {
        final String propertyName = propertyName(method);

        if (propertyName == null)
            continue;
        if (gcInfoHack && propertyName.equals("CompositeType"))
            continue;

        Method old =
            getterMap.put(decapitalize(propertyName),
                        method);
        if (old != null) {
            final String msg =
                "Class " + c.getName() + " has method name clash: " +
                old.getName() + ", " + method.getName();
            throw new OpenDataException(msg);
        }
    }

    final int nitems = getterMap.size();

    if (nitems == 0) {
        throw new OpenDataException("Can't map " + c.getName() +
                                    " to an open data type");
    }

    final Method[] getters = new Method[nitems];
    final String[] itemNames = new String[nitems];
    final OpenType<?>[] openTypes = new OpenType<?>[nitems];
    int i = 0;
    for (Map.Entry<String,Method> entry : getterMap.entrySet()) {
        itemNames[i] = entry.getKey();
        final Method getter = entry.getValue();
        getters[i] = getter;
        final Type retType = getter.getGenericReturnType();
        openTypes[i] = factory.mappingForType(retType, factory).getOpenType();
        i++;
    }

    CompositeType compositeType =
        new CompositeType(c.getName(),
                          c.getName(),
                          itemNames, // field names
                          itemNames, // field descriptions
                          openTypes);

    return new CompositeMapping(c,
                                compositeType,
                                itemNames,
                                getters,
                                factory);
}
 
Example 55
Project: hashsdn-controller   File: ObjectXmlWriter.java   Source Code and License 4 votes vote down vote up
@Override
protected AttributeWritingStrategy caseJavaEnumAttribute(final OpenType<?> openType) {
    return new SimpleAttributeWritingStrategy(document, key);
}
 
Example 56
Project: monarch   File: OpenTypeConverter.java   Source Code and License 4 votes vote down vote up
protected OpenTypeConverter(Type targetType, OpenType openType, Class openClass) {
  this.targetType = targetType;
  this.openType = openType;
  this.openClass = openClass;
}
 
Example 57
Project: monarch   File: OpenTypeConverter.java   Source Code and License 4 votes vote down vote up
final OpenType getOpenType() {
  return openType;
}
 
Example 58
Project: hashsdn-controller   File: AttributeConfigElement.java   Source Code and License 4 votes vote down vote up
public void resolveValue(final AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
        final String attrName) throws DocumentedException {
    resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
    Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, defaultValue);
    resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
}
 
Example 59
Project: monarch   File: IdentityConverter.java   Source Code and License 4 votes vote down vote up
IdentityConverter(Type targetType, OpenType openType, Class openClass) {
  super(targetType, openType, openClass);
}
 
Example 60
Project: hashsdn-controller   File: AttributeIfcSwitchStatement.java   Source Code and License 4 votes vote down vote up
protected T caseJavaBinaryAttribute(final OpenType<?> openType) {
    return caseJavaAttribute(openType);
}