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:com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.java

public Object convertSelectValue(FacesContext facesContext, UISelectMany uiSelectMany,
        String[] newSubmittedValues) throws ConverterException {

    ValueBinding valueBinding = uiSelectMany.getValueBinding("value");
    if (valueBinding == null) {
        Class componentType = (new Object[1]).getClass().getComponentType();
        return convertArray(facesContext, uiSelectMany, componentType, newSubmittedValues);
    }//www.java  2 s  .c  o  m
    Class valueBindingClass = valueBinding.getType(facesContext);
    if (valueBindingClass == null) {
        throw new ConverterException("Inconvertible type in value binding");
    }
    if (List.class.isAssignableFrom(valueBindingClass)) {
        Converter converter = uiSelectMany.getConverter();
        if (converter == null) {
            // Determine if there is a default converter for the class
            converter = getConverterForClass(valueBindingClass);
        }

        ArrayList submittedValuesAsList = new ArrayList(newSubmittedValues.length);
        for (int index = 0; index < newSubmittedValues.length; index++) {
            Object convertedValue = newSubmittedValues[index];
            if (converter != null) {
                convertedValue = converter.getAsObject(facesContext, uiSelectMany, newSubmittedValues[index]);
            }
            submittedValuesAsList.add(convertedValue);
        }
        return submittedValuesAsList;
    }
    if (valueBindingClass.isArray()) {
        Class componentType = valueBindingClass.getComponentType();
        return convertArray(facesContext, uiSelectMany, componentType, newSubmittedValues);
    }
    throw new ConverterException("Non-list and Non-array values are inconvertible");
}

From source file:org.enerj.apache.commons.beanutils.PropertyUtilsBean.java

/**
 * Return the Java Class representing the property type of the specified
 * property, or <code>null</code> if there is no such property for the
 * specified bean.  This method follows the same name resolution rules
 * used by <code>getPropertyDescriptor()</code>, so if the last element
 * of a name reference is indexed, the type of the property itself will
 * be returned.  If the last (or only) element has no property with the
 * specified name, <code>null</code> is returned.
 *
 * @param bean Bean for which a property descriptor is requested
 * @param name Possibly indexed and/or nested name of the property for
 *  which a property descriptor is requested
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception IllegalArgumentException if a nested reference to a
 *  property returns null//from   w  w w  .  ja v a2 s  . co m
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public Class getPropertyType(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified");
    }

    // Special handling for DynaBeans
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            return (null);
        }
        Class type = descriptor.getType();
        if (type == null) {
            return (null);
        } else if (type.isArray()) {
            return (type.getComponentType());
        } else {
            return (type);
        }
    }

    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        return (null);
    } else if (descriptor instanceof IndexedPropertyDescriptor) {
        return (((IndexedPropertyDescriptor) descriptor).getIndexedPropertyType());
    } else if (descriptor instanceof MappedPropertyDescriptor) {
        return (((MappedPropertyDescriptor) descriptor).getMappedPropertyType());
    } else {
        return (descriptor.getPropertyType());
    }

}

From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java

private QName generateSchemaForType(XmlSchemaSequence sequence, Type genericType, String partName,
        boolean isArrayType) throws Exception {

    Class<?> type;//  www  .ja va 2 s . c  om
    // This fix is for java7 onwards, refer CARBON-15182
    if ((genericType instanceof Class<?>) && (((Class<?>) genericType).isArray())) {
        // this is a double array element
        Class<?> simpleType = ((Class<?>) genericType).getComponentType();
        String simpleTypeName = "";
        while (simpleType.isArray()) {
            simpleTypeName += "ArrayOf";
            simpleType = simpleType.getComponentType();
        }
        simpleTypeName += simpleType.getSimpleName();

        XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
        if (xmlSchema.getTypeByName(simpleTypeName) == null) {
            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
            generateSchemaForType(xmlSchemaSequence, simpleType, "array", true);
            xmlSchemaComplexType.setName(simpleTypeName);
            xmlSchema.getItems().add(xmlSchemaComplexType);
            xmlSchema.getSchemaTypes().add(new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                    xmlSchemaComplexType);
        }

        if (isGenerateWrappedArrayTypes) {
            XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
            xmlSchemaElement.setName(partName + "Wrapper");
            xmlSchemaElement.setNillable(true);
            sequence.getItems().add(xmlSchemaElement);

            String complexTypeName = simpleTypeName + "Wrapper";

            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
            xmlSchemaComplexType.setName(complexTypeName);

            xmlSchema.getItems().add(xmlSchemaComplexType);
            xmlSchema.getSchemaTypes().add(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
                    xmlSchemaComplexType);
            addContentToMethodSchemaType(xmlSchemaSequence,
                    new QName(xmlSchema.getTargetNamespace(), simpleTypeName), "array", true);

            xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
            xmlSchemaElement
                    .setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
            return new QName(xmlSchema.getTargetNamespace(), complexTypeName);
        } else {
            addContentToMethodSchemaType(sequence, new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                    partName, true);
            return new QName(xmlSchema.getTargetNamespace(), simpleTypeName);
        }

    } else {
        type = (Class<?>) genericType;
    }
    if (AxisFault.class.getName().equals(type)) {
        return null;
    }
    String classTypeName;
    if (type == null) {
        classTypeName = "java.lang.Object";
    } else {
        classTypeName = type.getName();
    }
    if (isArrayType && "byte".equals(classTypeName)) {
        classTypeName = "base64Binary";
        isArrayType = false;
    }

    if (isDataHandler(type)) {
        classTypeName = "base64Binary";
    }

    return generateSchemaTypeforNameCommon(sequence, partName, isArrayType, type, classTypeName);
}

From source file:org.apache.sling.stanbol.rest.ported.JerseyUtils.java

/**
 * Tests if a generic type (may be &lt;?&gt;, &lt;? extends {required}&gt; 
 * or &lt;? super {required}&gt;) is compatible with the required one.
 * TODO: Should be moved to an utility class
 * @param required the required class the generic type MUST BE compatible with
 * @param genericType the required class
 * @return if the generic type is compatible with the required class
 *///from  w  w  w . j  av  a2 s  .  c  o m
public static boolean testType(Class<?> required, Type genericType) {
    //for the examples let assume that a Set is the raw type and the
    //requested generic type is a Representation with the following class
    //hierarchy:
    // Object
    //     -> Representation
    //         -> RdfRepresentation
    //         -> InMemoryRepresentation
    //     -> InputStream
    //     -> Collection<T>
    boolean typeOK;
    if (genericType instanceof Class<?>) {
        //OK
        //  Set<Representation>
        //  Set<Object>
        //NOT OK
        //  Set<RdfRepresentation>
        //  Set<InputStream>
        typeOK = ((Class<?>) genericType).isAssignableFrom(required);
    } else if (genericType instanceof WildcardType) {
        //In cases <? super {class}>, <? extends {class}, <?>
        WildcardType wildcardSetType = (WildcardType) genericType;
        if (wildcardSetType.getLowerBounds().length > 0) {
            Type lowerBound = wildcardSetType.getLowerBounds()[0];
            //OK
            //  Set<? super RdfRepresentation>
            //  Set<? super Representation>
            //NOT OK
            //  Set<? super InputStream>
            //  Set<? super Collection<Representation>>
            typeOK = lowerBound instanceof Class<?> && required.isAssignableFrom((Class<?>) lowerBound);
        } else if (wildcardSetType.getUpperBounds().length > 0) {
            Type upperBound = wildcardSetType.getUpperBounds()[0];
            //OK
            //  Set<? extends Representation>
            //  Set<? extends Object>
            //NOT OK
            //  Set<? extends RdfRepresentation>
            //  Set<? extends InputStream>
            //  Set<? extends Collection<Representation>
            typeOK = upperBound instanceof Class<?> && ((Class<?>) upperBound).isAssignableFrom(required);
        } else { //no upper nor lower bound
            // Set<?>
            typeOK = true;
        }
    } else if (required.isArray() && genericType instanceof GenericArrayType) {
        //In case the required type is an array we need also to support 
        //possible generic Array specifications
        GenericArrayType arrayType = (GenericArrayType) genericType;
        typeOK = testType(required.getComponentType(), arrayType.getGenericComponentType());
    } else {
        //GenericArrayType but !required.isArray() -> incompatible
        //TypeVariable -> no variables define -> incompatible
        typeOK = false;
    }
    return typeOK;
}

From source file:javadz.beanutils.locale.LocaleBeanUtilsBean.java

/**
 * Convert the specified value to the required type using the
 * specified conversion pattern.//from   w  ww .  j  a va2 s .co m
 *
 * @param type The Java type of target property
 * @param index The indexed subscript value (if any)
 * @param value The value to be converted
 * @param pattern The conversion pattern
 * @return The converted value
 */
protected Object convert(Class type, int index, Object value, String pattern) {

    if (log.isTraceEnabled()) {
        log.trace("Converting value '" + value + "' to type:" + type);
    }

    Object newValue = null;

    if (type.isArray() && (index < 0)) { // Scalar value into array
        if (value instanceof String) {
            String[] values = new String[1];
            values[0] = (String) value;
            newValue = getLocaleConvertUtils().convert(values, type, pattern);
        } else if (value instanceof String[]) {
            newValue = getLocaleConvertUtils().convert((String[]) value, type, pattern);
        } else {
            newValue = value;
        }
    } else if (type.isArray()) { // Indexed value into array
        if (value instanceof String) {
            newValue = getLocaleConvertUtils().convert((String) value, type.getComponentType(), pattern);
        } else if (value instanceof String[]) {
            newValue = getLocaleConvertUtils().convert(((String[]) value)[0], type.getComponentType(), pattern);
        } else {
            newValue = value;
        }
    } else { // Value into scalar
        if (value instanceof String) {
            newValue = getLocaleConvertUtils().convert((String) value, type, pattern);
        } else if (value instanceof String[]) {
            newValue = getLocaleConvertUtils().convert(((String[]) value)[0], type, pattern);
        } else {
            newValue = value;
        }
    }
    return newValue;
}

From source file:org.evosuite.testcase.TestCodeVisitor.java

/**
 * <p>//from w  ww. ja v  a 2s  . c om
 * getClassName
 * </p>
 * 
 * @param clazz
 *            a {@link java.lang.Class} object.
 * @return a {@link java.lang.String} object.
 */
public String getClassName(Class<?> clazz) {
    if (classNames.containsKey(clazz))
        return classNames.get(clazz);

    if (clazz.isArray()) {
        return getClassName(clazz.getComponentType()) + "[]";
    }

    GenericClass c = new GenericClass(clazz);
    String name = c.getSimpleName();
    if (classNames.values().contains(name)) {
        name = clazz.getCanonicalName();
    } else {
        /*
         * If e.g. there is a foo.bar.IllegalStateException with
         * foo.bar being the SUT package, then we need to use the
         * full package name for java.lang.IllegalStateException
         */
        String fullName = Properties.CLASS_PREFIX + "." + name;
        if (!fullName.equals(clazz.getCanonicalName())) {
            try {
                if (ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT())
                        .hasClass(fullName)) {
                    name = clazz.getCanonicalName();
                }
            } catch (IllegalArgumentException e) {
                // If the classpath is not correct, then we just don't check 
                // because that cannot happen in regular EvoSuite use, only
                // from test cases
            }
        }
    }
    // Ensure outer classes are imported as well
    Class<?> outerClass = clazz.getEnclosingClass();
    if (outerClass != null) {
        String enclosingName = getClassName(outerClass);
        String simpleOuterName = outerClass.getSimpleName();
        if (simpleOuterName.equals(enclosingName)) {
            name = enclosingName + name.substring(simpleOuterName.length());
        } else {
            name = enclosingName + name.substring(name.lastIndexOf(simpleOuterName) + simpleOuterName.length());
        }
    }

    Class<?> declaringClass = clazz.getDeclaringClass();
    if (declaringClass != null) {
        getClassName(declaringClass);
    }

    // We can't use "Test" because of JUnit 
    if (name.equals("Test")) {
        name = clazz.getCanonicalName();
    }
    classNames.put(clazz, name);

    return name;
}

From source file:com.github.helenusdriver.driver.impl.ClassInfoImpl.java

/**
 * Finds an initial objects factory method for the POJO if configured.
 *
 * @author paouelle/*from  w w w  . ja v  a 2  s  .co m*/
 *
 * @return the initial objects factory method or <code>null</code> if none
 *         configured
 * @throws IllegalArgumentException if the initial objects method is not
 *         properly defined
 */
private Method findInitial() {
    final InitialObjects io = clazz.getAnnotation(InitialObjects.class);

    if (io != null) {
        final String mname = io.staticMethod();

        try {
            final Method m = (suffixesByType.isEmpty() ? clazz.getMethod(mname)
                    : clazz.getMethod(mname, Map.class));

            // validate the method is static
            if (!Modifier.isStatic(m.getModifiers())) {
                throw new IllegalArgumentException("initial objects method '" + mname
                        + "' is not static in class: " + clazz.getSimpleName());
            }
            // validate the return type is compatible with this class and is an array
            final Class<?> type = m.getReturnType();

            if (!type.isArray()) {
                throw new IllegalArgumentException("initial objects method '" + mname
                        + "' doesn't return an array in class: " + clazz.getSimpleName());
            }
            final Class<?> ctype = type.getComponentType();

            if (!ctype.isAssignableFrom(clazz)) {
                throw new IllegalArgumentException("incompatible returned class '" + ctype.getName()
                        + "' for initial objects method '" + mname + "' in class: " + clazz.getSimpleName());
            }
            // validate that if suffixes are defined, the method expects a Map<String, String>
            // to provide the values for the suffixes when initializing objects
            final Class<?>[] cparms = m.getParameterTypes();

            if (suffixesByType.isEmpty()) {
                // should always be 0 as we used no classes in getMethod()
                if (cparms.length != 0) {
                    throw new IllegalArgumentException("expecting no parameters for initial objects method '"
                            + mname + "' in class: " + clazz.getSimpleName());
                }
            } else {
                // should always be 1 as we used only 1 class in getMethod()
                if (cparms.length != 1) {
                    throw new IllegalArgumentException(
                            "expecting one Map<String, String> parameter for initial objects method '" + mname
                                    + "' in class: " + clazz.getSimpleName());
                }
                // should always be a map as we used a Map to find the method
                if (!Map.class.isAssignableFrom(cparms[0])) {
                    throw new IllegalArgumentException("expecting parameter for initial objects method '"
                            + mname + "' to be of type Map<String, String> in class: " + clazz.getSimpleName());
                }
                final Type[] tparms = m.getGenericParameterTypes();

                // should always be 1 as we used only 1 class in getMethod()
                if (tparms.length != 1) { // should always be 1 as it was already tested above
                    throw new IllegalArgumentException(
                            "expecting one Map<String, String> parameter for initial objects method '" + mname
                                    + "' in class: " + clazz.getSimpleName());
                }
                if (tparms[0] instanceof ParameterizedType) {
                    final ParameterizedType ptype = (ParameterizedType) tparms[0];

                    // maps will always have 2 arguments
                    for (final Type atype : ptype.getActualTypeArguments()) {
                        final Class<?> aclazz = ReflectionUtils.getRawClass(atype);

                        if (String.class != aclazz) {
                            throw new IllegalArgumentException(
                                    "expecting a Map<String, String> parameter for initial objects method '"
                                            + mname + "' in class: " + clazz.getSimpleName());
                        }
                    }
                } else {
                    throw new IllegalArgumentException(
                            "expecting a Map<String, String> parameter for initial objects method '" + mname
                                    + "' in class: " + clazz.getSimpleName());
                }
            }
            return m;
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(
                    "missing initial objects method '" + mname + "' in class: " + clazz.getSimpleName(), e);
        }
    }
    return null;
}

From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java

protected void generateSchemaforGenericFields(XmlSchema xmlSchema, XmlSchemaSequence sequence, Type genericType,
        String name) throws Exception {
    String propertyName;//from  w  w w. j av  a 2 s .  co m
    Class<?> type;
    boolean isArrayType = true;
    // This fix is for java7 onwards, refer CARBON-15182
    if ((genericType instanceof Class<?>) && (((Class<?>) genericType).isArray())) {
        Class<?> simpleType = ((Class<?>) genericType).getComponentType();
        propertyName = simpleType.getName();
        // this is a doble array element
        String simpleTypeName = "";
        while (simpleType.isArray()) {
            simpleTypeName += "ArrayOf";
            simpleType = simpleType.getComponentType();
        }
        simpleTypeName += simpleType.getSimpleName();

        if (xmlSchema.getTypeByName(simpleTypeName) == null) {
            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
            generateSchemaforGenericFields(xmlSchema, xmlSchemaSequence, simpleType, "array");

            xmlSchemaComplexType.setName(simpleTypeName);
            xmlSchema.getItems().add(xmlSchemaComplexType);
            xmlSchema.getSchemaTypes().add(new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                    xmlSchemaComplexType);
        }

        if (isGenerateWrappedArrayTypes) {
            XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
            xmlSchemaElement.setName(name + "Wrapper");
            xmlSchemaElement.setNillable(true);
            sequence.getItems().add(xmlSchemaElement);

            String complexTypeName = simpleTypeName + "Wrapper";

            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
            xmlSchemaComplexType.setName(complexTypeName);

            xmlSchema.getItems().add(xmlSchemaComplexType);
            xmlSchema.getSchemaTypes().add(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
                    xmlSchemaComplexType);
            addContentToMethodSchemaType(xmlSchemaSequence,
                    new QName(xmlSchema.getTargetNamespace(), simpleTypeName), "array", true);

            xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
            xmlSchemaElement
                    .setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));

        } else {
            addContentToMethodSchemaType(sequence, new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                    name, true);

        }
        return;
    } else {
        //            isArrayType = false;
        type = (Class<?>) genericType;
        propertyName = type.getName();
    }

    if (isArrayType && "byte".equals(propertyName)) {
        propertyName = "base64Binary";
    }
    if (isDataHandler(type)) {
        propertyName = "base64Binary";
    }
    if (typeTable.isSimpleType(propertyName)) {

        if (isGenerateWrappedArrayTypes && isArrayType) {

            processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType, propertyName);

        } else {
            addElementToSequence(name, typeTable.getSimpleSchemaTypeName(propertyName), sequence,
                    propertyName.equals("base64Binary"), isArrayType, type.isPrimitive());
        }

    } else {
        if (isArrayType) {
            generateSchema(type.getComponentType());
        } else {
            generateSchema(type);
        }

        if (isGenerateWrappedArrayTypes && isArrayType) {

            processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType, propertyName);

        } else {
            addElementToSequence(name, typeTable.getComplexSchemaType(propertyName), sequence, false,
                    isArrayType, type.isPrimitive());
        }

        if (typeTable.getComplexSchemaType(propertyName) != null
                && !((NamespaceMap) xmlSchema.getNamespaceContext()).values()
                        .contains(typeTable.getComplexSchemaType(propertyName).getNamespaceURI())) {
            XmlSchemaImport importElement = new XmlSchemaImport();
            importElement.setNamespace(typeTable.getComplexSchemaType(propertyName).getNamespaceURI());
            xmlSchema.getItems().add(importElement);
            ((NamespaceMap) xmlSchema.getNamespaceContext()).put(generatePrefix(),
                    typeTable.getComplexSchemaType(propertyName).getNamespaceURI());
        }
    }

}

From source file:com.fengduo.bee.commons.component.FormModelMethodArgumentResolver.java

/**
 * {@inheritDoc}/*from   w w w. j av a 2 s  .  com*/
 * <p>
 * Downcast {@link org.springframework.web.bind.WebDataBinder} to
 * {@link org.springframework.web.bind.ServletRequestDataBinder} before binding.
 * 
 * @throws Exception
 * @see org.springframework.web.servlet.mvc.method.annotation.ServletRequestDataBinderFactory
 */
protected void bindRequestParameters(ModelAndViewContainer mavContainer, WebDataBinderFactory binderFactory,
        WebDataBinder binder, NativeWebRequest request, MethodParameter parameter) throws Exception {

    // Map<String, Boolean> hasProcessedPrefixMap = new HashMap<String, Boolean>();
    //
    // Class<?> targetType = binder.getTarget().getClass();
    // WebDataBinder simpleBinder = binderFactory.createBinder(request, null, null);
    Collection target = (Collection) binder.getTarget();

    Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
    Method method = parameter.getMethod();
    Object[] args = new Object[paramTypes.length];
    Map<String, Object> argMap = new HashMap<String, Object>(args.length);
    MapBindingResult errors = new MapBindingResult(argMap, "");
    ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();

    for (int i = 0; i < paramTypes.length; i++) {
        Class<?> paramType = paramTypes[i];

        MethodParameter methodParam = new MethodParameter(method, i);
        methodParam.initParameterNameDiscovery(parameterNameDiscoverer);
        String paramName = methodParam.getParameterName();
        // ??
        if (BeanUtils.isSimpleProperty(paramType)) {
            SimpleTypeConverter converter = new SimpleTypeConverter();
            Object value;
            // ?
            if (paramType.isArray()) {
                value = request.getParameterValues(paramName);
            } else {
                value = request.getParameter(paramName);
            }
            try {
                args[i] = converter.convertIfNecessary(value, paramType, methodParam);
            } catch (TypeMismatchException e) {
                errors.addError(new FieldError(paramName, paramName, e.getMessage()));
            }
        } else {
            // ???POJO
            if (paramType.isArray()) {
                ObjectArrayDataBinder binders = new ObjectArrayDataBinder(paramType.getComponentType(),
                        paramName);
                target.addAll(ArrayUtils.arrayConvert(binders.bind(request)));
            }
        }
    }

    // if (Collection.class.isAssignableFrom(targetType)) {// bind collection or array
    //
    // Type type = parameter.getGenericParameterType();
    // Class<?> componentType = Object.class;
    //
    // Collection target = (Collection) binder.getTarget();
    //
    // List targetList = new ArrayList(target);
    //
    // if (type instanceof ParameterizedType) {
    // componentType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
    // }
    //
    // if (parameter.getParameterType().isArray()) {
    // componentType = parameter.getParameterType().getComponentType();
    // }
    //
    // for (Object key : servletRequest.getParameterMap().keySet()) {
    // String prefixName = getPrefixName((String) key);
    //
    // // ?prefix ??
    // if (hasProcessedPrefixMap.containsKey(prefixName)) {
    // continue;
    // } else {
    // hasProcessedPrefixMap.put(prefixName, Boolean.TRUE);
    // }
    //
    // if (isSimpleComponent(prefixName)) { // bind simple type
    // Map<String, Object> paramValues = WebUtils.getParametersStartingWith(servletRequest, prefixName);
    // Matcher matcher = INDEX_PATTERN.matcher(prefixName);
    // if (!matcher.matches()) { // ? array=1&array=2
    // for (Object value : paramValues.values()) {
    // targetList.add(simpleBinder.convertIfNecessary(value, componentType));
    // }
    // } else { // ? array[0]=1&array[1]=2
    // int index = Integer.valueOf(matcher.group(1));
    //
    // if (targetList.size() <= index) {
    // growCollectionIfNecessary(targetList, index);
    // }
    // targetList.set(index, simpleBinder.convertIfNecessary(paramValues.values(), componentType));
    // }
    // } else { // ? votes[1].title=votes[1].title&votes[0].title=votes[0].title&votes[0].id=0&votes[1].id=1
    // Object component = null;
    // // ? ?????
    // Matcher matcher = INDEX_PATTERN.matcher(prefixName);
    // if (!matcher.matches()) {
    // throw new IllegalArgumentException("bind collection error, need integer index, key:" + key);
    // }
    // int index = Integer.valueOf(matcher.group(1));
    // if (targetList.size() <= index) {
    // growCollectionIfNecessary(targetList, index);
    // }
    // Iterator iterator = targetList.iterator();
    // for (int i = 0; i < index; i++) {
    // iterator.next();
    // }
    // component = iterator.next();
    //
    // if (component == null) {
    // component = BeanUtils.instantiate(componentType);
    // }
    //
    // WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
    // component = componentBinder.getTarget();
    //
    // if (component != null) {
    // ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(
    // servletRequest,
    // prefixName,
    // "");
    // componentBinder.bind(pvs);
    // validateIfApplicable(componentBinder, parameter);
    // if (componentBinder.getBindingResult().hasErrors()) {
    // if (isBindExceptionRequired(componentBinder, parameter)) {
    // throw new BindException(componentBinder.getBindingResult());
    // }
    // }
    // targetList.set(index, component);
    // }
    // }
    // target.clear();
    // target.addAll(targetList);
    // }
    // } else if (MapWapper.class.isAssignableFrom(targetType)) {
    //
    // Type type = parameter.getGenericParameterType();
    // Class<?> keyType = Object.class;
    // Class<?> valueType = Object.class;
    //
    // if (type instanceof ParameterizedType) {
    // keyType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
    // valueType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[1];
    // }
    //
    // MapWapper mapWapper = ((MapWapper) binder.getTarget());
    // Map target = mapWapper.getInnerMap();
    // if (target == null) {
    // target = new HashMap();
    // mapWapper.setInnerMap(target);
    // }
    //
    // for (Object key : servletRequest.getParameterMap().keySet()) {
    // String prefixName = getPrefixName((String) key);
    //
    // // ?prefix ??
    // if (hasProcessedPrefixMap.containsKey(prefixName)) {
    // continue;
    // } else {
    // hasProcessedPrefixMap.put(prefixName, Boolean.TRUE);
    // }
    //
    // Object keyValue = simpleBinder.convertIfNecessary(getMapKey(prefixName), keyType);
    //
    // if (isSimpleComponent(prefixName)) { // bind simple type
    // Map<String, Object> paramValues = WebUtils.getParametersStartingWith(servletRequest, prefixName);
    //
    // for (Object value : paramValues.values()) {
    // target.put(keyValue, simpleBinder.convertIfNecessary(value, valueType));
    // }
    // } else {
    //
    // Object component = target.get(keyValue);
    // if (component == null) {
    // component = BeanUtils.instantiate(valueType);
    // }
    //
    // WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
    // component = componentBinder.getTarget();
    //
    // if (component != null) {
    // ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(
    // servletRequest,
    // prefixName,
    // "");
    // componentBinder.bind(pvs);
    //
    // validateComponent(componentBinder, parameter);
    //
    // target.put(keyValue, component);
    // }
    // }
    // }
    // } else {// bind model
    // ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
    // servletBinder.bind(servletRequest);
    // }
}

From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java

private QName processParameterArrayTypes(XmlSchemaSequence sequence, Class<?> type, String partName,
        String simpleTypeName) throws Exception {
    XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
    if (xmlSchema.getTypeByName(simpleTypeName) == null) {
        XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
        XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
        xmlSchemaComplexType.setParticle(xmlSchemaSequence);
        generateSchemaForType(xmlSchemaSequence, type.getComponentType(), "array");
        xmlSchemaComplexType.setName(simpleTypeName);
        xmlSchema.getItems().add(xmlSchemaComplexType);
        xmlSchema.getSchemaTypes().add(new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                xmlSchemaComplexType);//  w  w w  . j  a v  a  2s.c om
    }

    if (isGenerateWrappedArrayTypes) {
        XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
        xmlSchemaElement.setName(partName + "Wrapper");
        xmlSchemaElement.setNillable(true);
        sequence.getItems().add(xmlSchemaElement);

        String complexTypeName = simpleTypeName + "Wrapper";

        XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
        XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
        xmlSchemaComplexType.setParticle(xmlSchemaSequence);
        xmlSchemaComplexType.setName(complexTypeName);

        xmlSchema.getItems().add(xmlSchemaComplexType);
        xmlSchema.getSchemaTypes().add(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
                xmlSchemaComplexType);
        addContentToMethodSchemaType(xmlSchemaSequence,
                new QName(xmlSchema.getTargetNamespace(), simpleTypeName), "array", true);

        xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
        xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
        return new QName(xmlSchema.getTargetNamespace(), complexTypeName);
    } else {
        addContentToMethodSchemaType(sequence, new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
                partName, true);
        return new QName(xmlSchema.getTargetNamespace(), simpleTypeName);
    }
}