Package javax.management.openmbean

Examples of javax.management.openmbean.OpenType


        MBeanAttributeInfo[] mbais = mbi.getAttributes();
        for (int i = 0; i < mbais.length; i++) {
            MBeanAttributeInfo mbai = mbais[i];
            String name = mbai.getName();
            Field typeField = c.getField(name + "Type");
            OpenType typeValue = (OpenType) typeField.get(null);
            OpenType openType =
                (OpenType) mbai.getDescriptor().getFieldValue("openType");
            if (typeValue.equals(openType))
                success("attribute " + name);
            else {
                final String msg =
                    "Wrong type attribute " + name + ": " +
                    openType + " should be " + typeValue;
                failure(msg);
            }
        }

        MBeanOperationInfo[] mbois = mbi.getOperations();
        for (int i = 0; i < mbois.length; i++) {
            MBeanOperationInfo mboi = mbois[i];
            String oname = mboi.getName();
            if (!oname.startsWith("op"))
                throw new Error();
            OpenType retType =
                (OpenType) mboi.getDescriptor().getFieldValue("openType");
            MBeanParameterInfo[] params = mboi.getSignature();
            MBeanParameterInfo p1i = params[0];
            MBeanParameterInfo p2i = params[1];
            OpenType p1Type =
                (OpenType) p1i.getDescriptor().getFieldValue("openType");
            OpenType p2Type =
                (OpenType) p2i.getDescriptor().getFieldValue("openType");
            if (!retType.equals(p1Type) || !p1Type.equals(p2Type)) {
                final String msg =
                    "Parameter and return open types should all be same " +
                    "but are not: " + retType + " " + oname + "(" + p1Type +
                    ", " + p2Type + ")";
                failure(msg);
                continue;
            }
            String name = oname.substring(2);
            Field typeField = c.getField(name + "Type");
            OpenType typeValue = (OpenType) typeField.get(null);
            if (typeValue.equals(retType))
                success("operation " + oname);
            else {
                final String msg =
                    "Wrong type operation " + oname + ": " +
                    retType + " should be " + typeValue;
                failure(msg);
            }
        }


        System.out.println("Mapping check...");

        Object proxy =
            JMX.newMXBeanProxy(mbsc, on, c);

        Method[] methods = c.getMethods();
        for (int i = 0; i < methods.length; i++) {
            final Method method = methods[i];
            if (method.getDeclaringClass() != c)
                continue; // skip hashCode() etc inherited from Object
            final String mname = method.getName();
            final int what = getType(method);
            final String name = getName(method);
            final Field refField = c.getField(name);
            if (nullTest && refField.getType().isPrimitive())
                continue;
            final Field openTypeField = c.getField(name + "Type");
            final OpenType openType = (OpenType) openTypeField.get(null);
            final Object refValue = nullTest ? null : refField.get(null);
            Object setValue = refValue;
            try {
                Field onField = c.getField(name + "ObjectName");
                String refName = (String) onField.get(null);
                ObjectName refObjName = ObjectName.getInstance(refName);
                Class<?> mxbeanInterface = refField.getType();
                setValue = nullTest ? null :
                    JMX.newMXBeanProxy(mbsc, refObjName, mxbeanInterface);
            } catch (Exception e) {
                // no xObjectName field, setValue == refValue
            }
            boolean ok = true;
            try {
                switch (what) {
                case GET:
                    final Object gotOpen = mbsc.getAttribute(on, name);
                    if (nullTest) {
                        if (gotOpen != null) {
                            failure(mname + " got non-null value " +
                                    gotOpen);
                            ok = false;
                        }
                    } else if (!openType.isValue(gotOpen)) {
                        if (gotOpen instanceof TabularData) {
                            // detail the mismatch
                            TabularData gotTabular = (TabularData) gotOpen;
                            compareTabularType((TabularType) openType,
                                               gotTabular.getTabularType());
View Full Code Here


/*      */   public static OpenType getOpenType(Type type)
/*      */   {
/*   92 */     if (type == null) {
/*   93 */       throw new IllegalArgumentException("Null type");
/*      */     }
/*   95 */     OpenType result = checkType(type);
/*   96 */     if (result != null)
/*   97 */       return result;
/*   98 */     Class clazz = (Class)type;
/*   99 */     return CompositeTypeMetaDataFactory.getCompositeType(clazz);
/*      */   }
View Full Code Here

/*  114 */     return simpleType;
/*      */   }
/*      */
/*      */   public static OpenType checkType(Type type)
/*      */   {
/*  125 */     OpenType result = checkSimpleType(type);
/*  126 */     if (result != null)
/*  127 */       return result;
/*  128 */     result = checkEnum(type);
/*  129 */     if (result != null)
/*  130 */       return result;
View Full Code Here

/*      */   }
/*      */
/*      */   public static Object construct(Type type, Object value, Object context)
/*      */     throws Exception
/*      */   {
/*  168 */     OpenType openType = getOpenType(type);
/*  169 */     return construct(openType, value, context);
/*      */   }
View Full Code Here

/*      */   }
/*      */
/*      */   public static Object reconstruct(Type type, Object value, Object context)
/*      */     throws Exception
/*      */   {
/*  203 */     OpenType openType = getOpenType(type);
/*  204 */     return reconstruct(openType, type, value, context);
/*      */   }
View Full Code Here

/*  363 */       while (componentType.isArray())
/*      */       {
/*  365 */         dimension++;
/*  366 */         componentType = componentType.getComponentType();
/*      */       }
/*  368 */       OpenType componentOpenType = getOpenType(componentType);
/*      */       try
/*      */       {
/*  371 */         return new ArrayType(dimension, componentOpenType);
/*      */       }
/*      */       catch (RuntimeException e)
/*      */       {
/*  375 */         throw e;
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  379 */         throw new RuntimeException(e);
/*      */       }
/*      */     }
/*  382 */     if ((type instanceof GenericArrayType))
/*      */     {
/*  384 */       GenericArrayType arrayType = (GenericArrayType)type;
/*  385 */       int dimension = 1;
/*  386 */       Type componentType = arrayType.getGenericComponentType();
/*  387 */       while ((componentType instanceof GenericArrayType))
/*      */       {
/*  389 */         dimension++;
/*  390 */         arrayType = (GenericArrayType)componentType;
/*  391 */         componentType = arrayType.getGenericComponentType();
/*      */       }
/*  393 */       OpenType componentOpenType = getOpenType(componentType);
/*      */       try
/*      */       {
/*  396 */         return new ArrayType(dimension, componentOpenType);
/*      */       }
/*      */       catch (RuntimeException e)
View Full Code Here

/*  428 */       return null;
/*  429 */     Class rawClass = (Class)rawType;
/*  430 */     if (!Collection.class.isAssignableFrom(rawClass))
/*  431 */       return null;
/*  432 */     Type componentType = parameterizedType.getActualTypeArguments()[0];
/*  433 */     OpenType componentOpenType = getOpenType(componentType);
/*      */     try
/*      */     {
/*  436 */       return new ArrayType(1, componentOpenType);
/*      */     }
/*      */     catch (RuntimeException e)
View Full Code Here

/*      */
/*      */   public static ArrayType checkCollectionClass(Class clazz)
/*      */   {
/*  456 */     if (!Collection.class.isAssignableFrom(clazz))
/*  457 */       return null;
/*  458 */     OpenType componentOpenType = getOpenType(Object.class);
/*      */     try
/*      */     {
/*  461 */       return new ArrayType(1, componentOpenType);
/*      */     }
/*      */     catch (RuntimeException e)
View Full Code Here

/*      */   {
/*  484 */     if (value == null) {
/*  485 */       return null;
/*      */     }
/*  487 */     ArrayType arrayType = (ArrayType)openType;
/*  488 */     OpenType elementType = arrayType.getElementOpenType();
/*  489 */     int dimension = arrayType.getDimension();
/*      */
/*  491 */     Class clazz = value.getClass();
/*  492 */     if (clazz.isArray())
/*      */     {
View Full Code Here

/*      */   {
/*  562 */     if (value == null) {
/*  563 */       return null;
/*      */     }
/*  565 */     ArrayType arrayType = (ArrayType)getOpenType(type);
/*  566 */     OpenType elementType = arrayType.getElementOpenType();
/*  567 */     int dimension = arrayType.getDimension();
/*  568 */     Object[] oldArray = (Object[])(Object[])value;
/*  569 */     if ((type instanceof Class))
/*      */     {
/*  571 */       Class clazz = (Class)type;
View Full Code Here

TOP

Related Classes of javax.management.openmbean.OpenType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.