Example usage for java.lang Class getComponentType

List of usage examples for java.lang Class getComponentType

Introduction

In this page you can find the example usage for java.lang Class getComponentType.

Prototype

public Class<?> getComponentType() 

Source Link

Document

Returns the Class representing the component type of an array.

Usage

From source file:org.apache.axis.encoding.TypeMappingImpl.java

public DeserializerFactory finalGetDeserializer(Class javaType, QName xmlType, TypeMappingDelegate start) {
    DeserializerFactory df = null;//ww  w  .  ja v a  2s  .  com
    if (javaType != null && javaType.isArray()) {
        Class componentType = javaType.getComponentType();

        // HACK ALERT - Don't return the ArrayDeserializer IF
        // the xmlType matches the component type of the array
        // or if the componentType is the wrappertype of the
        // xmlType, because that means we're using maxOccurs 
        // and/or nillable and we'll want the higher layers to 
        // get the component type deserializer... (sigh)
        if (xmlType != null) {
            Class actualClass = start.getClassForQName(xmlType);
            if (actualClass == componentType
                    || (actualClass != null && (componentType.isAssignableFrom(actualClass)
                            || Utils.getWrapperType(actualClass.getName()).equals(componentType.getName())))) {
                return null;
            }
        }
        Pair pair = (Pair) qName2Pair.get(Constants.SOAP_ARRAY);
        df = (DeserializerFactory) pair2DF.get(pair);
        if (df instanceof ArrayDeserializerFactory && javaType.isArray()) {
            QName componentXmlType = start.getTypeQName(componentType);
            if (componentXmlType != null) {
                df = new ArrayDeserializerFactory(componentXmlType);
            }
        }
    }
    return df;
}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Convert an array of specified values to an array of objects of the
 * specified class (if possible).  If the specified Java class is itself
 * an array class, this class will be the type of the returned value.
 * Otherwise, an array will be constructed whose component type is the
 * specified class.//from w  ww. j  av  a2  s .c  om
 *
 * @param values Array of values to be converted
 * @param clazz Java array or element class to be converted to
 * @return The converted value
 *
 * @exception ConversionException if thrown by an underlying Converter
 */
public Object convert(String[] values, Class clazz) {

    Class type = clazz;
    if (clazz.isArray()) {
        type = clazz.getComponentType();
    }
    if (log.isDebugEnabled()) {
        log.debug("Convert String[" + values.length + "] to class '" + type.getName() + "[]'");
    }
    Converter converter = lookup(type);
    if (converter == null) {
        converter = lookup(String.class);
    }
    if (log.isTraceEnabled()) {
        log.trace("  Using converter " + converter);
    }
    Object array = Array.newInstance(type, values.length);
    for (int i = 0; i < values.length; i++) {
        Array.set(array, i, converter.convert(type, values[i]));
    }
    return (array);

}

From source file:com.bstek.dorado.view.output.ClientOutputHelper.java

protected Map<String, PropertyConfig> doGetPropertyConfigs(Class<?> beanType) throws Exception {
    beanType = ProxyBeanUtils.getProxyTargetType(beanType);
    Map<String, PropertyConfig> propertyConfigs = new HashMap<String, PropertyConfig>();

    ClientObjectInfo clientObjectInfo = getClientObjectInfo(beanType);
    if (clientObjectInfo != null) {
        for (Map.Entry<String, ClientProperty> entry : clientObjectInfo.getPropertyConfigs().entrySet()) {
            String property = entry.getKey();
            ClientProperty clientProperty = entry.getValue();

            PropertyConfig propertyConfig = new PropertyConfig();
            if (clientProperty.ignored()) {
                propertyConfig.setIgnored(true);
            } else {
                if (StringUtils.isNotEmpty(clientProperty.outputter())) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(clientProperty.outputter(),
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                }/*w w w.ja v  a 2  s . com*/

                if (clientProperty.alwaysOutput()) {
                    propertyConfig.setEscapeValue(FAKE_ESCAPE_VALUE);
                } else if (StringUtils.isNotEmpty(clientProperty.escapeValue())) {
                    propertyConfig.setEscapeValue(clientProperty.escapeValue());
                }
            }
            propertyConfigs.put(property, propertyConfig);
        }
    }

    boolean isAssembledComponent = (AssembledComponent.class.isAssignableFrom(beanType));
    Class<?> superComponentType = null;
    if (isAssembledComponent) {
        superComponentType = beanType;
        while (superComponentType != null && AssembledComponent.class.isAssignableFrom(superComponentType)) {
            superComponentType = superComponentType.getSuperclass();
            Assert.notNull(superComponentType);
        }
    }

    for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors(beanType)) {
        String property = propertyDescriptor.getName();
        Method readMethod = propertyDescriptor.getReadMethod();
        if (readMethod.getDeclaringClass() != beanType) {
            try {
                readMethod = beanType.getMethod(readMethod.getName(), readMethod.getParameterTypes());
            } catch (NoSuchMethodException e) {
                // do nothing
            }
        }

        TypeInfo typeInfo;
        Class<?> propertyType = propertyDescriptor.getPropertyType();
        if (Collection.class.isAssignableFrom(propertyType)) {
            typeInfo = TypeInfo.parse((ParameterizedType) readMethod.getGenericReturnType(), true);
            if (typeInfo != null) {
                propertyType = typeInfo.getType();
            }
        } else if (propertyType.isArray()) {
            typeInfo = new TypeInfo(propertyType.getComponentType(), true);
        } else {
            typeInfo = new TypeInfo(propertyType, false);
        }

        PropertyConfig propertyConfig = null;
        ClientProperty clientProperty = readMethod.getAnnotation(ClientProperty.class);
        if (clientProperty != null) {
            propertyConfig = new PropertyConfig();
            if (clientProperty.ignored()) {
                propertyConfig.setIgnored(true);
            } else {
                if (StringUtils.isNotEmpty(clientProperty.outputter())) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(clientProperty.outputter(),
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (Component.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (DataControl.class.isAssignableFrom(propertyType)
                        || FloatControl.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (DataType.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(DATA_TYPE_PROPERTY_OUTPUTTER,
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (Object.class.equals(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(DATA_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (!EntityUtils.isSimpleType(propertyType) && !propertyType.isArray()) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(OBJECT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                }

                if (!clientProperty.evaluateExpression()) {
                    propertyConfig.setEvaluateExpression(false);
                }

                if (clientProperty.alwaysOutput()) {
                    propertyConfig.setEscapeValue(FAKE_ESCAPE_VALUE);
                } else if (StringUtils.isNotEmpty(clientProperty.escapeValue())) {
                    propertyConfig.setEscapeValue(clientProperty.escapeValue());
                }
            }
        } else if (isAssembledComponent && readMethod.getDeclaringClass() == beanType
                && EntityUtils.isSimpleType(propertyType)) {
            if (BeanUtils.getPropertyDescriptor(superComponentType, property) == null) {
                propertyConfig = new PropertyConfig();
                propertyConfig.setIgnored(true);
            }
        }

        ComponentReference componentReference = readMethod.getAnnotation(ComponentReference.class);
        if (componentReference != null && String.class.equals(propertyType)) {
            if (propertyConfig == null) {
                propertyConfig = new PropertyConfig();
            }
            if (propertyConfig.getOutputter() == null) {
                BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_REFERENCE_OUTPUTTER,
                        Scope.instant);
                propertyConfig.setOutputter(beanWrapper.getBean());
            }
        }

        if (!propertyType.isPrimitive() && (Number.class.isAssignableFrom(propertyType)
                || Boolean.class.isAssignableFrom(propertyType))) {
            if (propertyConfig == null) {
                propertyConfig = new PropertyConfig();
            }
            if (propertyConfig.getEscapeValue() == PropertyConfig.NONE_VALUE) {
                propertyConfig.setEscapeValue(null);
            }
        }

        if (propertyConfig != null) {
            propertyConfigs.put(property, propertyConfig);
        }
    }
    return (propertyConfigs.isEmpty()) ? null : propertyConfigs;
}

From source file:com.browseengine.bobo.serialize.JSONSerializer.java

private static void loadObject(Object array, Class type, int index, JSONArray jsonArray)
        throws JSONSerializationException, JSONException {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            Array.setInt(array, index, jsonArray.getInt(index));
        } else if (type == Long.TYPE) {
            Array.setLong(array, index, jsonArray.getInt(index));
        } else if (type == Short.TYPE) {
            Array.setShort(array, index, (short) jsonArray.getInt(index));
        } else if (type == Boolean.TYPE) {
            Array.setBoolean(array, index, jsonArray.getBoolean(index));
        } else if (type == Double.TYPE) {
            Array.setDouble(array, index, jsonArray.getDouble(index));
        } else if (type == Float.TYPE) {
            Array.setFloat(array, index, (float) jsonArray.getDouble(index));
        } else if (type == Character.TYPE) {
            char ch = jsonArray.getString(index).charAt(0);
            Array.setChar(array, index, ch);
        } else if (type == Byte.TYPE) {
            Array.setByte(array, index, (byte) jsonArray.getInt(index));
        } else {/*w  w w . j av a2 s  .co  m*/
            throw new JSONSerializationException("Unknown primitive: " + type);
        }
    } else if (type == String.class) {
        Array.set(array, index, jsonArray.getString(index));
    } else if (JSONSerializable.class.isAssignableFrom(type)) {
        JSONObject jObj = jsonArray.getJSONObject(index);
        JSONSerializable serObj = deSerialize(type, jObj);
        Array.set(array, index, serObj);
    } else if (type.isArray()) {
        Class componentClass = type.getComponentType();
        JSONArray subArray = jsonArray.getJSONArray(index);
        int len = subArray.length();

        Object newArray = Array.newInstance(componentClass, len);
        for (int k = 0; k < len; ++k) {
            loadObject(newArray, componentClass, k, subArray);
        }
    }
}

From source file:com.medallia.spider.api.DynamicInputImpl.java

private static Object parseSingleValue(Class<?> rt, String v, AnnotatedElement anno,
        Map<Class<?>, InputArgParser<?>> inputArgParsers) {
    if (rt.isEnum()) {
        String vlow = v.toLowerCase();
        for (Enum e : rt.asSubclass(Enum.class).getEnumConstants()) {
            if (e.name().toLowerCase().equals(vlow))
                return e;
        }//w w  w .  j  a  v a2 s  .co  m
        throw new AssertionError("Enum constant not found: " + v);
    } else if (rt == Integer.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Integer.valueOf(v) : null;
    } else if (rt == Integer.TYPE) {
        // primitive int must have a value
        return Integer.valueOf(v);
    } else if (rt == Long.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Long.valueOf(v) : null;
    } else if (rt == Long.TYPE) {
        // primitive long must have a value
        return Long.valueOf(v);
    } else if (rt == Double.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Double.valueOf(v) : null;
    } else if (rt == Double.TYPE) {
        // primitive double must have a value
        return Double.valueOf(v);
    } else if (rt == String.class) {
        return v;
    } else if (rt.isArray()) {
        Input.List ann = anno.getAnnotation(Input.List.class);
        if (ann == null)
            throw new AssertionError("Array type but no annotation (see " + Input.class + "): " + anno);
        String separator = ann.separator();
        String[] strVals = v.split(separator, -1);
        Class<?> arrayType = rt.getComponentType();
        Object a = Array.newInstance(arrayType, strVals.length);
        for (int i = 0; i < strVals.length; i++) {
            Array.set(a, i, parseSingleValue(arrayType, strVals[i], anno, inputArgParsers));
        }
        return a;
    } else if (inputArgParsers != null) {
        InputArgParser<?> argParser = inputArgParsers.get(rt);
        if (argParser != null) {
            return argParser.parse(v);
        }
    }
    throw new AssertionError("Unknown return type " + rt + " (val: " + v + ")");
}

From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Converts the supplied object to the specified
 * type. Throws a runtime exception if the conversion is
 * not possible.//from w ww .j a  v  a  2s  .  c om
 * @param object to convert
 * @param toType destination class
 * @return converted object
 */
public Object convert(Object object, final Class toType) {
    if (object == null) {
        return toType.isPrimitive() ? convertNullToPrimitive(toType) : null;
    }

    if (toType == Object.class) {
        if (object instanceof NodeSet) {
            return convert(((NodeSet) object).getValues(), toType);
        }
        if (object instanceof Pointer) {
            return convert(((Pointer) object).getValue(), toType);
        }
        return object;
    }
    final Class useType = TypeUtils.wrapPrimitive(toType);
    Class fromType = object.getClass();

    if (useType.isAssignableFrom(fromType)) {
        return object;
    }

    if (fromType.isArray()) {
        int length = Array.getLength(object);
        if (useType.isArray()) {
            Class cType = useType.getComponentType();

            Object array = Array.newInstance(cType, length);
            for (int i = 0; i < length; i++) {
                Object value = Array.get(object, i);
                Array.set(array, i, convert(value, cType));
            }
            return array;
        }
        if (Collection.class.isAssignableFrom(useType)) {
            Collection collection = allocateCollection(useType);
            for (int i = 0; i < length; i++) {
                collection.add(Array.get(object, i));
            }
            return unmodifiableCollection(collection);
        }
        if (length > 0) {
            Object value = Array.get(object, 0);
            return convert(value, useType);
        }
        return convert("", useType);
    }
    if (object instanceof Collection) {
        int length = ((Collection) object).size();
        if (useType.isArray()) {
            Class cType = useType.getComponentType();
            Object array = Array.newInstance(cType, length);
            Iterator it = ((Collection) object).iterator();
            for (int i = 0; i < length; i++) {
                Object value = it.next();
                Array.set(array, i, convert(value, cType));
            }
            return array;
        }
        if (Collection.class.isAssignableFrom(useType)) {
            Collection collection = allocateCollection(useType);
            collection.addAll((Collection) object);
            return unmodifiableCollection(collection);
        }
        if (length > 0) {
            Object value;
            if (object instanceof List) {
                value = ((List) object).get(0);
            } else {
                Iterator it = ((Collection) object).iterator();
                value = it.next();
            }
            return convert(value, useType);
        }
        return convert("", useType);
    }
    if (object instanceof NodeSet) {
        return convert(((NodeSet) object).getValues(), useType);
    }
    if (object instanceof Pointer) {
        return convert(((Pointer) object).getValue(), useType);
    }
    if (useType == String.class) {
        return object.toString();
    }
    if (object instanceof Boolean) {
        if (Number.class.isAssignableFrom(useType)) {
            return allocateNumber(useType, ((Boolean) object).booleanValue() ? 1 : 0);
        }
        if ("java.util.concurrent.atomic.AtomicBoolean".equals(useType.getName())) {
            try {
                return useType.getConstructor(new Class[] { boolean.class })
                        .newInstance(new Object[] { object });
            } catch (Exception e) {
                throw new JXPathTypeConversionException(useType.getName(), e);
            }
        }
    }
    if (object instanceof Number) {
        double value = ((Number) object).doubleValue();
        if (useType == Boolean.class) {
            return value == 0.0 ? Boolean.FALSE : Boolean.TRUE;
        }
        if (Number.class.isAssignableFrom(useType)) {
            return allocateNumber(useType, value);
        }
    }
    if (object instanceof String) {
        Object value = convertStringToPrimitive(object, useType);
        if (value != null || "".equals(object)) {
            return value;
        }
    }

    Converter converter = ConvertUtils.lookup(useType);
    if (converter != null) {
        return converter.convert(useType, object);
    }

    throw new JXPathTypeConversionException("Cannot convert " + object.getClass() + " to " + useType);
}

From source file:org.crank.javax.faces.component.MenuRenderer.java

protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class<?> arrayClass,
        String[] newValues) throws ConverterException {

    Object result = null;/*from  ww  w.j  a v  a2  s.  com*/
    Converter converter = null;
    int len = (null != newValues ? newValues.length : 0);

    Class<?> elementType = arrayClass.getComponentType();

    // Optimization: If the elementType is String, we don't need
    // conversion.  Just return newValues.
    if (elementType.equals(String.class)) {
        return newValues;
    }

    try {
        result = Array.newInstance(elementType, len);
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    // bail out now if we have no new values, returning our
    // oh-so-useful zero-length array.
    if (null == newValues) {
        return result;
    }

    // obtain a converter.

    // attached converter takes priority
    if (null == (converter = uiSelectMany.getConverter())) {
        // Otherwise, look for a by-type converter
        if (null == (converter = Util.getConverterForClass(elementType, context))) {
            // if that fails, and the attached values are of Object type,
            // we don't need conversion.
            if (elementType.equals(Object.class)) {
                return newValues;
            }
            StringBuffer valueStr = new StringBuffer();
            for (int i = 0; i < len; i++) {
                if (i == 0) {
                    valueStr.append(newValues[i]);
                } else {
                    valueStr.append(' ').append(newValues[i]);
                }
            }
            Object[] params = { valueStr.toString(), "null Converter" };

            throw new ConverterException(
                    MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params));
        }
    }

    assert (null != result);
    if (elementType.isPrimitive()) {
        for (int i = 0; i < len; i++) {
            if (elementType.equals(Boolean.TYPE)) {
                Array.setBoolean(result, i,
                        ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Byte.TYPE)) {
                Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Double.TYPE)) {
                Array.setDouble(result, i,
                        ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Float.TYPE)) {
                Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Integer.TYPE)) {
                Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Character.TYPE)) {
                Array.setChar(result, i,
                        ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Short.TYPE)) {
                Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Long.TYPE)) {
                Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])));
            }
        }
    } else {
        for (int i = 0; i < len; i++) {
            if (logger.isLoggable(Level.FINE)) {
                Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]);
                logger.fine("String value: " + newValues[i] + " converts to : " + converted.toString());
            }
            Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i]));
        }
    }
    return result;

}

From source file:org.dozer.util.ReflectionUtils.java

public static DeepHierarchyElement[] getDeepFieldHierarchy(Class<?> parentClass, String field,
        HintContainer deepIndexHintContainer) {
    if (!MappingUtils.isDeepMapping(field)) {
        MappingUtils.throwMappingException("Field does not contain deep field delimitor");
    }/*w w  w.  j  a  va2s  .  com*/

    StringTokenizer toks = new StringTokenizer(field, DozerConstants.DEEP_FIELD_DELIMITER);
    Class<?> latestClass = parentClass;
    DeepHierarchyElement[] hierarchy = new DeepHierarchyElement[toks.countTokens()];
    int index = 0;
    int hintIndex = 0;
    while (toks.hasMoreTokens()) {
        String aFieldName = toks.nextToken();
        String theFieldName = aFieldName;
        int collectionIndex = -1;

        if (aFieldName.contains("[")) {
            theFieldName = aFieldName.substring(0, aFieldName.indexOf("["));
            collectionIndex = Integer
                    .parseInt(aFieldName.substring(aFieldName.indexOf("[") + 1, aFieldName.indexOf("]")));
        }

        PropertyDescriptor propDescriptor = findPropertyDescriptor(latestClass, theFieldName,
                deepIndexHintContainer);
        DeepHierarchyElement r = new DeepHierarchyElement(propDescriptor, collectionIndex);

        if (propDescriptor == null) {
            MappingUtils
                    .throwMappingException("Exception occurred determining deep field hierarchy for Class --> "
                            + parentClass.getName() + ", Field --> " + field
                            + ".  Unable to determine property descriptor for Class --> "
                            + latestClass.getName() + ", Field Name: " + aFieldName);
        }

        latestClass = propDescriptor.getPropertyType();
        if (toks.hasMoreTokens()) {
            if (latestClass.isArray()) {
                latestClass = latestClass.getComponentType();
            } else if (Collection.class.isAssignableFrom(latestClass)) {
                Class<?> genericType = determineGenericsType(parentClass.getClass(), propDescriptor);

                if (genericType == null && deepIndexHintContainer == null) {
                    MappingUtils.throwMappingException(
                            "Hint(s) or Generics not specified.  Hint(s) or Generics must be specified for deep mapping with indexed field(s). Exception occurred determining deep field hierarchy for Class --> "
                                    + parentClass.getName() + ", Field --> " + field
                                    + ".  Unable to determine property descriptor for Class --> "
                                    + latestClass.getName() + ", Field Name: " + aFieldName);
                }
                if (genericType != null) {
                    latestClass = genericType;
                } else {
                    latestClass = deepIndexHintContainer.getHint(hintIndex);
                    hintIndex += 1;
                }
            }
        }
        hierarchy[index++] = r;
    }

    return hierarchy;
}

From source file:net.yasion.common.core.bean.wrapper.ExtendedBeanInfo.java

private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
    for (PropertyDescriptor pd : this.propertyDescriptors) {
        final Class<?> candidateType;
        final String candidateName = pd.getName();
        if (pd instanceof IndexedPropertyDescriptor) {
            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
            candidateType = ipd.getIndexedPropertyType();
            if (candidateName.equals(propertyName) && (candidateType.equals(propertyType)
                    || candidateType.equals(propertyType.getComponentType()))) {
                return pd;
            }/*from   w w  w. j  a  v  a 2 s . c o  m*/
        } else {
            candidateType = pd.getPropertyType();
            if (candidateName.equals(propertyName) && (candidateType.equals(propertyType)
                    || propertyType.equals(candidateType.getComponentType()))) {
                return pd;
            }
        }
    }
    return null;
}

From source file:org.energy_home.jemma.osgi.ah.felix.console.web.HacWebCommandProvider.java

private void renderClusterCommands(String appRoot, IApplianceConfiguration config, IEndPoint endPoint,
        String clusterName, String methodName, String[] params, PrintWriter pw)
        throws SecurityException, InstantiationException, NoSuchFieldException, IllegalAccessException {
    IAppliance appliance = endPoint.getAppliance();
    String appliancePid = appliance.getPid();
    Integer endPointId = new Integer(endPoint.getId());
    String endPointType = endPoint.getType();
    String name = null;//  w  w  w.j  a va 2  s . c  o  m
    ICategory category = null;
    ILocation location = null;
    if (config != null) {
        name = config.getName(null);
        category = appliancesProxy.getCategory(config.getCategoryPid(null));
        location = appliancesProxy.getLocation(config.getLocationPid(null));
    }
    pw.println((appliance.isDriver() ? "<br><b><u>DRIVER APPLIANCE CLUSTER</u>"
            : "<br><b>VIRTUAL APPLIANCE CLUSTER</u>") + "&nbsp;&nbsp;(<a <a href=\"" + appRoot + "/" + LABEL
            + "/" + appliancePid + "/" + endPointId + "/" + clusterName + "\">Reload page</a>"
            + "&nbsp;&nbsp;&nbsp;<a href=\"" + appRoot + "/" + LABEL + "/" + appliancePid
            + "\">Go to appliance details</a>)</br><hr/>");

    pw.println("<br>APPLIANCE<br/>&nbsp;&nbsp;&nbsp;PID: " + appliance.getPid()
            + "<br/>&nbsp;&nbsp;&nbsp;TYPE: " + appliance.getDescriptor().getType()
            + ((name != null) ? "<br/>&nbsp;&nbsp;&nbsp;Name: " + name : "")
            + ((category != null) ? "<br/>&nbsp;&nbsp;&nbsp;Category: " + category.getName() : "")
            + ((location != null) ? "<br/>&nbsp;&nbsp;&nbsp;Location: " + location.getName() : "")
            + "<br/><br/>");

    if (config != null) {
        name = config.getName(endPointId);
        category = appliancesProxy.getCategory(config.getCategoryPid(endPointId));
        location = appliancesProxy.getLocation(config.getLocationPid(endPointId));
    }

    pw.println("<br/>END POINT" + "<br/>&nbsp;&nbsp;&nbsp;ID: " + endPointId + "<br/>&nbsp;&nbsp;&nbsp;TYPE: "
            + endPointType + ((name != null) ? "<br/>&nbsp;&nbsp;&nbsp;Name: " + name : "")
            + ((category != null) ? "<br/>&nbsp;&nbsp;&nbsp;Category: " + category.getName() : "")
            + ((location != null) ? "<br/>&nbsp;&nbsp;&nbsp;Location: " + location.getName() : "")
            + "<br/>&nbsp;&nbsp;&nbsp;Cluster: " + clusterName + "</b><br/>");

    String result = null;
    long timestamp = System.currentTimeMillis();
    try {
        ISubscriptionParameters sp = null;
        if (methodName != null && methodName.equals(GET_ATTRIBUTE_SUBSCRIPTION_METHOD)) {
            sp = appliancesProxy.getAttributeSubscription(appliancePid, endPointId, clusterName, params[0]);
            result = TextConverter.getTextRepresentation(sp);
        } else if (methodName != null && methodName.equals(SET_ATTRIBUTE_SUBSCRIPTION_METHOD)) {
            if (!isEmpty(params[1]) || !isEmpty(params[2]) || !isEmpty(params[3])) {
                long minReportingInterval = isEmpty(params[1]) ? 0 : Long.parseLong(params[1]);
                long maxReportingInterval = isEmpty(params[2]) ? 0 : Long.parseLong(params[2]);
                double reportableChange = isEmpty(params[3]) ? 0 : Double.parseDouble(params[3]);
                sp = new SubscriptionParameters(minReportingInterval, maxReportingInterval, reportableChange);
            }
            result = TextConverter.getTextRepresentation(appliancesProxy.setAttributeSubscription(appliancePid,
                    endPointId, clusterName, params[0], sp));
        } else if (methodName != null) {
            result = invokeClusterMethod(appliancesProxy, appliancePid, new Integer(endPointId), clusterName,
                    methodName, params);
        }
    } catch (Exception e) {
        e.printStackTrace();
        result = "ERROR: " + e.getMessage();
    }

    Method[] methods;

    try {
        pw.print("<br/><br/><hr/><b><i>ATTRIBUTE SUBSCRIPTIONS:</i></b><hr/>");
        renderGetSubscriptionCommand(appRoot, appliancePid, endPointId, clusterName, methodName, result, pw);
        renderSetSubscriptionCommand(appRoot, appliancePid, endPointId, clusterName, methodName, result, pw);
        Map lastNotifiedAttributeValues = appliancesProxy.getLastNotifiedAttributeValues(appliancePid,
                endPointId, clusterName);
        if (lastNotifiedAttributeValues != null && lastNotifiedAttributeValues.size() > 0) {
            pw.println("<br/><table id=\"lastNotifiedAttributeValues\" class=\"nicetable\"><tbody>");
            pw.println("<tr><td width=\"50%\"><b>Last notified attribute values:</b></td><td>&nbsp;</td></tr>");
            for (Iterator iterator = lastNotifiedAttributeValues.entrySet().iterator(); iterator.hasNext();) {
                Entry entry = (Entry) iterator.next();
                pw.println("<tr><td width=\"30%\"><b><font color=\"red\">" + entry.getKey()
                        + ":</font></b></td><td><b><font color=\"red\">"
                        + TextConverter.getTextRepresentation(entry.getValue()) + "</font></b></td></tr>");
            }
        }
        pw.println("</tbody></table>");
        pw.print("<br/><br/><hr/><b><i>ATTRIBUTES AND COMMANDS:</i></b><hr/>");
        methods = Class.forName(clusterName).getMethods();
        //         methods = new Method[specificMethods.length + 2];
        //         methods[0] = IServiceCluster.class.getMethod(GET_ATTRIBUTE_SUBSCRIPTION_METHOD, new Class[] {String.class, IEndPointRequestContext.class});
        //         methods[1] = IServiceCluster.class.getMethod(SET_ATTRIBUTE_SUBSCRIPTION_METHOD, new Class[] {String.class, ISubscriptionParameters.class, IEndPointRequestContext.class});
        //         System.arraycopy(specificMethods, 0, methods, 2, specificMethods.length);
        Class[] parameters = null;
        for (int i = 0; i < methods.length; i++) {
            pw.println("<br/><form name=\"" + methods[i].getName() + i + "\"" + " action=\"" + appRoot + "/"
                    + LABEL + "/" + appliancePid + "/" + endPointId + "/" + clusterName + "/"
                    + methods[i].getName() + "#" + methods[i].getName() + "\" method=\"get\">");
            pw.println("<table id=\"" + methods[i].getName() + i + "\" class=\"nicetable\"><tbody>");
            pw.println(
                    "<tr><td width=\"50%\"><b><a name=\"" + methods[i].getName() + "\">" + methods[i].getName()
                            + "</a></b></td><td><input type=\"submit\" value=\"invoke\"/></td></tr>");
            parameters = methods[i].getParameterTypes();
            for (int j = 0; j < parameters.length - 1; j++) {
                if (parameters[j].isArray()) {
                    pw.println("<tr><td width=\"50%\">Param" + (j + 1) + " (array["
                            + parameters[j].getComponentType().getName()
                            + "]):</td><td><input type=\"text\" name=\"param\" size=\"100\"/></td></tr>");
                } else {
                    pw.println("<tr><td width=\"50%\">Param" + (j + 1) + " (" + parameters[j].getName()
                            + "):</td><td><input type=\"text\" name=\"param\" size=\"100\"/></td></tr>");
                }
            }
            pw.println("<input type=\"hidden\" name=\"ts\" value=\"" + timestamp + "\")");
            Class resultClass = methods[i].getReturnType();
            String resultClassStr;
            if (resultClass.isArray()) {
                resultClassStr = "array[" + resultClass.getComponentType().getName() + "]";
            } else {
                resultClassStr = resultClass.getName();
            }
            if (methodName != null && methods[i].getName().equals(methodName)) {
                pw.println("<tr><td><b><font color=\"red\">Result (" + resultClassStr
                        + "):</font></b></td><td><b><font color=\"red\">" + formatResult(result)
                        + "</font></b></td></tr>");
            } else
                pw.println("<tr><td>Result (" + resultClassStr + "):</td><td>&nbsp;</td>");
            pw.println("</tbody></table></form>");
            pw.println("<br/><br/>");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}