Search in sources :

Example 1 with SimpleType

use of javax.management.openmbean.SimpleType in project tomcat by apache.

the class JMXAccessorTask method createProperty.

/**
     * create result as property with name from property prefix When result is
     * an array and isSeparateArrayResults is true, resultproperty used as
     * prefix (<code>resultproperty.0-array.length</code> and store the
     * result array length at <code>resultproperty.length</code>. Other
     * option is that you delimit your result with a delimiter
     * (java.util.StringTokenizer is used).
     *
     * @param propertyPrefix Prefix for the property
     * @param result The result
     */
protected void createProperty(String propertyPrefix, Object result) {
    if (propertyPrefix == null)
        propertyPrefix = "";
    if (result instanceof CompositeDataSupport) {
        CompositeDataSupport data = (CompositeDataSupport) result;
        CompositeType compositeType = data.getCompositeType();
        Set<String> keys = compositeType.keySet();
        for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
            String key = iter.next();
            Object value = data.get(key);
            OpenType<?> type = compositeType.getType(key);
            if (type instanceof SimpleType<?>) {
                setProperty(propertyPrefix + "." + key, value);
            } else {
                createProperty(propertyPrefix + "." + key, value);
            }
        }
    } else if (result instanceof TabularDataSupport) {
        TabularDataSupport data = (TabularDataSupport) result;
        for (Iterator<Object> iter = data.keySet().iterator(); iter.hasNext(); ) {
            Object key = iter.next();
            for (Iterator<?> iter1 = ((List<?>) key).iterator(); iter1.hasNext(); ) {
                Object key1 = iter1.next();
                CompositeData valuedata = data.get(new Object[] { key1 });
                Object value = valuedata.get("value");
                OpenType<?> type = valuedata.getCompositeType().getType("value");
                if (type instanceof SimpleType<?>) {
                    setProperty(propertyPrefix + "." + key1, value);
                } else {
                    createProperty(propertyPrefix + "." + key1, value);
                }
            }
        }
    } else if (result.getClass().isArray()) {
        if (isSeparatearrayresults()) {
            int size = 0;
            for (int i = 0; i < Array.getLength(result); i++) {
                if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
                    size++;
                }
            }
            if (size > 0) {
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
            }
        }
    } else {
        String delim = getDelimiter();
        if (delim != null) {
            StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
            int size = 0;
            for (; tokenizer.hasMoreTokens(); ) {
                String token = tokenizer.nextToken();
                if (setProperty(propertyPrefix + "." + size, token)) {
                    size++;
                }
            }
            if (size > 0)
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
        } else {
            setProperty(propertyPrefix, result.toString());
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeData(javax.management.openmbean.CompositeData) SimpleType(javax.management.openmbean.SimpleType) StringTokenizer(java.util.StringTokenizer) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Iterator(java.util.Iterator) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

Iterator (java.util.Iterator)1 StringTokenizer (java.util.StringTokenizer)1 CompositeData (javax.management.openmbean.CompositeData)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenType (javax.management.openmbean.OpenType)1 SimpleType (javax.management.openmbean.SimpleType)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1