Example usage for java.lang.reflect Type equals

List of usage examples for java.lang.reflect Type equals

Introduction

In this page you can find the example usage for java.lang.reflect Type equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java

private boolean isCollection(Type claz) {
    return (claz.equals(List.class) || claz.equals(ArrayList.class) || claz.equals(LinkedList.class)
            || claz.equals(Set.class) || claz.equals(HashSet.class) || claz.equals(LinkedHashSet.class)
            || claz.equals(Collection.class));
}

From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java

private boolean isPrimitive(Type claz) {
    return (claz.equals(Integer.class) || claz.equals(String.class) || claz.equals(Short.class)
            || claz.equals(Long.class) || claz.equals(Double.class) || claz.equals(Float.class)
            || claz.equals(Boolean.class) || claz.equals(int.class) || claz.equals(short.class)
            || claz.equals(long.class) || claz.equals(double.class) || claz.equals(float.class)
            || claz.equals(boolean.class) || claz.equals(Number.class) || claz.equals(Date.class)
            || claz.equals(BigInteger.class) || claz.equals(BigDecimal.class));
}

From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java

@Override
public final boolean isSubschema(final Type base, final Type sub) {

    // Neither may be null
    if (base == null || sub == null) {
        return false;
    }//from  w w w  .  j  a  v a 2s.c  om

    if (base.equals(sub)) {
        return false;
    }

    // Both must be models
    if (!TypeUtils.isAssignable(base, Model.class) || !TypeUtils.isAssignable(sub, Model.class)) {
        return false;
    }

    return TypeUtils.isAssignable(sub, base);
}

From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java

private Object getPrimitiveValue(Type claz) {
    if (isPrimitive(claz)) {
        if (claz.equals(boolean.class) || claz.equals(Boolean.class)) {
            Random rand = new Random();
            return rand.nextBoolean();
        } else if (claz.equals(Date.class)) {
            return new Date();
        } else if (claz.equals(Double.class) || claz.equals(double.class)) {
            Random rand = new Random(12345678L);
            return rand.nextDouble();
        } else if (claz.equals(Float.class) || claz.equals(float.class)) {
            Random rand = new Random(12345678L);
            return rand.nextFloat();
        } else if (claz.equals(String.class)) {
            return RandomStringUtils.randomAlphabetic(10);
        } else if (claz.equals(Long.class) || claz.equals(long.class) || claz.equals(Number.class)) {
            Random rand = new Random();
            return new Long(rand.nextInt(123));
        } else if (claz.equals(Integer.class) || claz.equals(int.class)) {
            Random rand = new Random();
            return new Integer(rand.nextInt(123));
        } else if (claz.equals(BigInteger.class)) {
            Random rand = new Random();
            return new BigInteger(new BigInteger("1234567890123456789").bitLength(), rand);
        } else if (claz.equals(BigDecimal.class)) {
            Random rand = new Random();
            return new BigDecimal(rand.nextInt(123));
        } else if (claz.equals(Short.class) || claz.equals(short.class)) {
            Random rand = new Random();
            return new Short((short) rand.nextInt(123));
        }//from   w ww . ja v a 2s  .c  o m
    }
    return null;
}

From source file:org.rapla.rest.gwtjsonrpc.server.JsonServlet.java

public void mapRequestToCall(final ActiveCall call, final HttpServletRequest req, String body) {
    final Gson gs = createGsonBuilder().create();
    String methodName = (String) req.getAttribute(JSON_METHOD);
    if (methodName != null) {
        call.versionName = "jsonrpc";
        call.versionValue = new JsonPrimitive("2.0");
    } else {/*  w  w w .  j  ava2s  . c o m*/
        methodName = req.getParameter("method");
        call.versionName = "version";
        call.versionValue = new JsonPrimitive("1.1");
    }
    call.method = lookupMethod(methodName);
    if (call.method == null) {
        throw new NoSuchRemoteMethodException(getInterfaceClass() + "." + methodName);
    }
    final Type[] paramTypes = call.method.getParamTypes();
    String[] paramNames = call.method.getParamNames();

    final Object[] r = new Object[paramTypes.length];
    for (int i = 0; i < r.length; i++) {
        Type type = paramTypes[i];
        String name = paramNames[i];
        if (name == null && !call.versionName.equals("jsonrpc")) {
            name = "param" + i;
        }
        {
            // First search in the request attributes
            Object attribute = req.getAttribute(name);
            Object paramValue;
            if (attribute != null) {
                paramValue = attribute;
                Class attributeClass = attribute.getClass();
                // we try to convert string and jsonelements to the parameter type (if the parameter type is not string or jsonelement)
                if (attributeClass.equals(String.class) && !type.equals(String.class)) {
                    JsonParser parser = new JsonParser();
                    JsonElement parsed = parser.parse((String) attribute);
                    paramValue = gs.fromJson(parsed, type);

                } else if (JsonElement.class.isAssignableFrom(attributeClass)
                        && !type.equals(JsonElement.class)) {
                    JsonElement parsed = (JsonElement) attribute;
                    paramValue = gs.fromJson(parsed, type);
                } else {
                    paramValue = attribute;
                }
            }
            // then in request parameters
            else {
                String v = null;
                v = req.getParameter(name);
                // if not found in request use body
                if (v == null && body != null && !body.isEmpty()) {
                    v = body;
                }
                if (v == null) {
                    paramValue = null;
                } else if (type == String.class) {
                    paramValue = v;
                } else if (type == Date.class) {
                    // special case for handling date parameters with the
                    // ':' char i it
                    try {
                        paramValue = SerializableDateTimeFormat.INSTANCE.parseTimestamp(v);
                    } catch (ParseDateException e) {
                        throw new JsonSyntaxException(v, e);
                    }
                } else if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) {
                    // Primitive type, use the JSON representation of that
                    // type.
                    //
                    paramValue = gs.fromJson(v, type);
                } else {
                    // Assume it is like a java.sql.Timestamp or something
                    // and treat
                    // the value as JSON string.
                    //
                    JsonParser parser = new JsonParser();
                    JsonElement parsed = parser.parse(v);
                    paramValue = gs.fromJson(parsed, type);
                }
            }
            r[i] = paramValue;
        }
    }
    call.params = r;
}

From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getListSetValue(Type type, Type[] types, List<Type> heirarchies) throws Exception {

    Class claz = null;//  w w  w  . j  a va2  s . c o m
    if (type.equals(List.class) || type.equals(Collection.class) || type.equals(ArrayList.class)
            || type.equals(LinkedList.class)) {
        if (type.equals(List.class) || type.equals(Collection.class)) {
            claz = ArrayList.class;
        } else {
            claz = (Class) type;
        }
    } else if (type.equals(Set.class) || type.equals(HashSet.class) || type.equals(LinkedHashSet.class)) {
        if (type.equals(Set.class)) {
            claz = HashSet.class;
        } else {
            claz = (Class) type;
        }
    }

    Constructor cons = claz.getConstructor(new Class[] {});
    Object object = cons.newInstance(new Object[] {});

    if (types.length == 1) {
        for (int i = 0; i < 1; i++) {
            Object v = null;
            if (isPrimitive(types[0])) {
                v = getPrimitiveValue(types[0]);
            } else if (!heirarchies.contains(types[0])) {
                if (types[0] instanceof Class)
                    v = getObject((Class) types[0], heirarchies);
                else
                    v = getObject(types[0], heirarchies);
                heirarchies.remove(types[0]);
            }
            ((Collection) object).add(v);
        }
        if (!isPrimitive(types[0])) {
            heirarchies.add(types[0]);
        }
    }
    return object;
}

From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getMapValue(Type type, Type[] types, List<Type> heirarchies) throws Exception {

    Class claz = null;//from  w w  w.  ja  v  a2  s  .  c  om
    if (type.equals(Map.class) || type.equals(HashMap.class) || type.equals(LinkedHashMap.class)) {
        if (type.equals(Map.class)) {
            claz = HashMap.class;
        } else {
            claz = (Class) type;
        }
    }

    Constructor cons = claz.getConstructor(new Class[] {});
    Object object = cons.newInstance(new Object[] {});

    for (int i = 0; i < 1; i++) {
        Object k = null;
        if (isPrimitive(types[0])) {
            k = getPrimitiveValue(types[0]);
        } else if (!heirarchies.contains(types[0])) {
            if (types[0] instanceof Class)
                k = getObject((Class) types[0], heirarchies);
            else
                k = getObject(types[0], heirarchies);
            heirarchies.remove(types[0]);
        }
        Object v = null;
        if (isPrimitive(types[1])) {
            v = getPrimitiveValue(types[1]);
        } else if (!heirarchies.contains(types[1])) {
            if (types[1] instanceof Class)
                v = getObject((Class) types[1], heirarchies);
            else
                v = getObject(types[1], heirarchies);
            heirarchies.remove(types[1]);
        }
        if (k == null && isDebugEnabled()) {
            getLog().info(types[0].toString());
            getLog().info(types[1].toString());
            getLog().error("Null key " + types[0]);
        }
        ((Map) object).put(k, v);
    }
    if (!isPrimitive(types[0])) {
        heirarchies.add(types[0]);
    }
    if (!isPrimitive(types[1])) {
        heirarchies.add(types[1]);
    }
    return object;
}

From source file:org.apache.bval.jsr.ConstraintValidation.java

private <A extends Annotation> ConstraintValidator<A, ? super T> getConstraintValidator(
        ConstraintValidatorFactory factory, A annotation,
        Class<? extends ConstraintValidator<A, ?>>[] constraintClasses, Class<?> owner, AccessStrategy access) {
    if (ArrayUtils.isNotEmpty(constraintClasses)) {
        final Type type = determineTargetedType(owner, access);

        /**//from  w  w w  . j av a  2 s .c  o m
         * spec says in chapter 3.5.3.: The ConstraintValidator chosen to
         * validate a declared type T is the one where the type supported by
         * the ConstraintValidator is a supertype of T and where there is no
         * other ConstraintValidator whose supported type is a supertype of
         * T and not a supertype of the chosen ConstraintValidator supported
         * type.
         */
        final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> validatorTypes = getValidatorsTypes(
                constraintClasses);
        reduceTarget(validatorTypes, access);

        final List<Type> assignableTypes = new ArrayList<Type>(constraintClasses.length);
        fillAssignableTypes(type, validatorTypes.keySet(), assignableTypes);
        reduceAssignableTypes(assignableTypes);
        checkOneType(assignableTypes, type, owner, annotation, access);

        if ((type.equals(Object.class) || type.equals(Object[].class))
                && validatorTypes.containsKey(Object.class) && validatorTypes.containsKey(Object[].class)) {
            throw new ConstraintDefinitionException(
                    "Only a validator for Object or Object[] should be provided for cross-parameter validators");
        }

        final Collection<Class<? extends ConstraintValidator<A, ?>>> key = validatorTypes
                .get(assignableTypes.get(0));
        if (key.size() > 1) {
            final String message = "Factory returned " + key.size() + " validators";
            if (ParametersAccess.class.isInstance(access)) { // cross parameter
                throw new ConstraintDefinitionException(message);
            }
            throw new UnexpectedTypeException(message);
        }

        @SuppressWarnings("unchecked")
        final ConstraintValidator<A, ? super T> validator = (ConstraintValidator<A, ? super T>) factory
                .getInstance(key.iterator().next());
        if (validator == null) {
            throw new ValidationException("Factory returned null validator for: " + key);

        }
        return validator;
        // NOTE: validator initialization deferred until append phase
    }
    return null;
}

From source file:com.cisco.dvbu.ps.common.util.CommonUtils.java

public static HashMap<String, String> assembleArgs(Object object) throws CompositeException {

    HashMap<String, String> retval = new HashMap<String, String>();

    Method[] methods = object.getClass().getMethods();
    for (Method method : methods) {
        String methodName = method.getName();
        Type returnType = method.getReturnType();
        if (methodName.startsWith("get") && returnType.equals(String.class)) {
            try {
                // -- strip "get"
                String argName = methodName.substring(3);
                // -- initial lower case
                argName = argName.substring(0, 1).toLowerCase() + argName.substring(1);
                retval.put(argName, (String) method.invoke(object));
            } catch (IllegalArgumentException e) {
                throw new CompositeException(e);
            } catch (IllegalAccessException e) {
                throw new CompositeException(e);
            } catch (InvocationTargetException e) {
                throw new CompositeException(e);
            }//from  w  ww.  j a  v a  2  s. co m
        }
    }

    return retval;

}

From source file:com.evolveum.midpoint.prism.parser.PrismBeanConverter.java

public <T> T unmarshall(MapXNode xnode, Class<T> beanClass) throws SchemaException {

    if (PolyStringType.class.equals(beanClass)) {
        PolyString polyString = unmarshalPolyString(xnode);
        return (T) polyString; // violates the method interface but ... TODO fix it
    } else if (ProtectedStringType.class.equals(beanClass)) {
        ProtectedStringType protectedType = new ProtectedStringType();
        XNodeProcessorUtil.parseProtectedType(protectedType, xnode, prismContext);
        return (T) protectedType;
    } else if (ProtectedByteArrayType.class.equals(beanClass)) {
        ProtectedByteArrayType protectedType = new ProtectedByteArrayType();
        XNodeProcessorUtil.parseProtectedType(protectedType, xnode, prismContext);
        return (T) protectedType;
    } else if (SchemaDefinitionType.class.equals(beanClass)) {
        SchemaDefinitionType schemaDefType = unmarshalSchemaDefinitionType(xnode);
        return (T) schemaDefType;
    } else if (prismContext.getSchemaRegistry().determineDefinitionFromClass(beanClass) != null) {
        return (T) prismContext.getXnodeProcessor().parseObject(xnode).asObjectable();
    } else if (XmlAsStringType.class.equals(beanClass)) {
        // reading a string represented a XML-style content
        // used e.g. when reading report templates (embedded XML)
        // A necessary condition: there may be only one map entry.
        if (xnode.size() > 1) {
            throw new SchemaException("Map with more than one item cannot be parsed as a string: " + xnode);
        } else if (xnode.isEmpty()) {
            return (T) new XmlAsStringType();
        } else {// www. jav a  2 s . c  o  m
            Map.Entry<QName, XNode> entry = xnode.entrySet().iterator().next();
            DomParser domParser = prismContext.getParserDom();
            String value = domParser.serializeToString(entry.getValue(), entry.getKey());
            return (T) new XmlAsStringType(value);
        }
    }
    T bean;
    Set<String> keysToParse; // only these keys will be parsed (null if all)
    if (SearchFilterType.class.isAssignableFrom(beanClass)) {
        keysToParse = Collections.singleton("condition"); // TODO fix this BRUTAL HACK - it is here because of c:ConditionalSearchFilterType
        bean = (T) unmarshalSearchFilterType(xnode, (Class<? extends SearchFilterType>) beanClass);
    } else {
        keysToParse = null;
        try {
            bean = beanClass.newInstance();
        } catch (InstantiationException e) {
            throw new SystemException("Cannot instantiate bean of type " + beanClass + ": " + e.getMessage(),
                    e);
        } catch (IllegalAccessException e) {
            throw new SystemException("Cannot instantiate bean of type " + beanClass + ": " + e.getMessage(),
                    e);
        }
    }

    if (ProtectedDataType.class.isAssignableFrom(beanClass)) {
        ProtectedDataType protectedDataType = null;
        if (bean instanceof ProtectedStringType) {
            protectedDataType = new ProtectedStringType();
        } else if (bean instanceof ProtectedByteArrayType) {
            protectedDataType = new ProtectedByteArrayType();
        } else {
            throw new SchemaException("Unexpected subtype of protected data type: " + bean.getClass());
        }
        XNodeProcessorUtil.parseProtectedType(protectedDataType, xnode, prismContext);
        return (T) protectedDataType;
    }

    for (Entry<QName, XNode> entry : xnode.entrySet()) {
        QName key = entry.getKey();
        if (keysToParse != null && !keysToParse.contains(key.getLocalPart())) {
            continue;
        }
        XNode xsubnode = entry.getValue();
        String propName = key.getLocalPart();
        Field field = inspector.findPropertyField(beanClass, propName);
        Method propertyGetter = null;
        if (field == null) {
            propertyGetter = inspector.findPropertyGetter(beanClass, propName);
        }

        Method elementMethod = null;
        Object objectFactory = null;
        if (field == null && propertyGetter == null) {
            // We have to try to find a more generic field, such as xsd:any or substitution element
            // check for global element definition first
            Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage());
            objectFactory = instantiateObjectFactory(objectFactoryClass);
            elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass, propName);
            if (elementMethod == null) {
                // Check for "any" method
                elementMethod = inspector.findAnyMethod(beanClass);
                if (elementMethod == null) {
                    String m = "No field " + propName + " in class " + beanClass
                            + " (and no element method in object factory too)";
                    if (mode == XNodeProcessorEvaluationMode.COMPAT) {
                        LOGGER.warn("{}", m);
                        continue;
                    } else {
                        throw new SchemaException(m);
                    }
                }
                unmarshallToAny(bean, elementMethod, key, xsubnode);
                continue;

            }
            field = inspector.lookupSubstitution(beanClass, elementMethod);
            if (field == null) {
                // Check for "any" field
                field = inspector.findAnyField(beanClass);
                if (field == null) {
                    elementMethod = inspector.findAnyMethod(beanClass);
                    if (elementMethod == null) {
                        String m = "No field " + propName + " in class " + beanClass
                                + " (and no element method in object factory too)";
                        if (mode == XNodeProcessorEvaluationMode.COMPAT) {
                            LOGGER.warn("{}", m);
                            continue;
                        } else {
                            throw new SchemaException(m);
                        }
                    }
                    unmarshallToAny(bean, elementMethod, key, xsubnode);
                    continue;
                    //                  throw new SchemaException("No field "+propName+" in class "+beanClass+" (no suitable substitution and no 'any' field)");
                }
                unmarshallToAny(bean, field, key, xsubnode);
                continue;
            }
        }

        boolean storeAsRawType;
        if (elementMethod != null) {
            storeAsRawType = elementMethod.getAnnotation(Raw.class) != null;
        } else if (propertyGetter != null) {
            storeAsRawType = propertyGetter.getAnnotation(Raw.class) != null;
        } else {
            storeAsRawType = field.getAnnotation(Raw.class) != null;
        }

        String fieldName;
        if (field != null) {
            fieldName = field.getName();
        } else {
            fieldName = propName;
        }

        Method setter = inspector.findSetter(beanClass, fieldName);
        Method getter = null;
        boolean wrapInJaxbElement = false;
        Class<?> paramType = null;
        if (setter == null) {
            // No setter. But if the property is multi-value we need to look
            // for a getter that returns a collection (Collection<Whatever>)
            getter = inspector.findPropertyGetter(beanClass, fieldName);
            if (getter == null) {
                String m = "Cannot find setter or getter for field " + fieldName + " in " + beanClass;
                if (mode == XNodeProcessorEvaluationMode.COMPAT) {
                    LOGGER.warn("{}", m);
                    continue;
                } else {
                    throw new SchemaException(m);
                }
            }
            Class<?> getterReturnType = getter.getReturnType();
            if (!Collection.class.isAssignableFrom(getterReturnType)) {
                throw new SchemaException("Cannot find getter for field " + fieldName + " in " + beanClass
                        + " does not return collection, cannot use it to set value");
            }
            Type genericReturnType = getter.getGenericReturnType();
            Type typeArgument = getTypeArgument(genericReturnType,
                    "for field " + fieldName + " in " + beanClass + ", cannot determine collection type");
            //         System.out.println("type argument " + typeArgument);
            if (typeArgument instanceof Class) {
                paramType = (Class<?>) typeArgument;
            } else if (typeArgument instanceof ParameterizedType) {
                ParameterizedType paramTypeArgument = (ParameterizedType) typeArgument;
                Type rawTypeArgument = paramTypeArgument.getRawType();
                if (rawTypeArgument.equals(JAXBElement.class)) {
                    // This is the case of Collection<JAXBElement<....>>
                    wrapInJaxbElement = true;
                    Type innerTypeArgument = getTypeArgument(typeArgument, "for field " + fieldName + " in "
                            + beanClass + ", cannot determine collection type (inner type argument)");
                    if (innerTypeArgument instanceof Class) {
                        // This is the case of Collection<JAXBElement<Whatever>>
                        paramType = (Class<?>) innerTypeArgument;
                    } else if (innerTypeArgument instanceof WildcardType) {
                        // This is the case of Collection<JAXBElement<?>>
                        // we need to exctract the specific type from the factory method
                        if (elementMethod == null) {
                            // TODO: TEMPORARY CODE!!!!!!!!!! fix in 3.1 [med]
                            Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage());
                            objectFactory = instantiateObjectFactory(objectFactoryClass);
                            elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass,
                                    propName);
                            if (elementMethod == null) {
                                throw new IllegalArgumentException(
                                        "Wildcard type in JAXBElement field specification and no factory method found for field "
                                                + fieldName + " in " + beanClass
                                                + ", cannot determine collection type (inner type argument)");
                            }
                        }
                        Type factoryMethodGenericReturnType = elementMethod.getGenericReturnType();
                        Type factoryMethodTypeArgument = getTypeArgument(factoryMethodGenericReturnType,
                                "in factory method " + elementMethod + " return type for field " + fieldName
                                        + " in " + beanClass + ", cannot determine collection type");
                        if (factoryMethodTypeArgument instanceof Class) {
                            // This is the case of JAXBElement<Whatever>
                            paramType = (Class<?>) factoryMethodTypeArgument;
                            if (Object.class.equals(paramType) && !storeAsRawType) {
                                throw new IllegalArgumentException("Factory method " + elementMethod
                                        + " type argument is Object (and not @Raw) for field " + fieldName
                                        + " in " + beanClass + ", property " + propName);
                            }
                        } else {
                            throw new IllegalArgumentException(
                                    "Cannot determine factory method return type, got "
                                            + factoryMethodTypeArgument + " - for field " + fieldName + " in "
                                            + beanClass
                                            + ", cannot determine collection type (inner type argument)");
                        }
                    } else {
                        throw new IllegalArgumentException("Ejha! " + innerTypeArgument + " "
                                + innerTypeArgument.getClass() + " from " + getterReturnType + " from "
                                + fieldName + " in " + propName + " " + beanClass);
                    }
                } else {
                    // The case of Collection<Whatever<Something>>
                    if (rawTypeArgument instanceof Class) {
                        paramType = (Class<?>) rawTypeArgument;
                    } else {
                        throw new IllegalArgumentException("EH? Eh!? " + typeArgument + " "
                                + typeArgument.getClass() + " from " + getterReturnType + " from " + fieldName
                                + " in " + propName + " " + beanClass);
                    }
                }
            } else {
                throw new IllegalArgumentException(
                        "EH? " + typeArgument + " " + typeArgument.getClass() + " from " + getterReturnType
                                + " from " + fieldName + " in " + propName + " " + beanClass);
            }
        } else {
            Class<?> setterType = setter.getParameterTypes()[0];
            if (JAXBElement.class.equals(setterType)) {
                //               TODO some handling for the returned generic parameter types
                Type[] genericTypes = setter.getGenericParameterTypes();
                if (genericTypes.length != 1) {
                    throw new IllegalArgumentException("Too lazy to handle this.");
                }
                Type genericType = genericTypes[0];
                if (genericType instanceof ParameterizedType) {
                    Type actualType = getTypeArgument(genericType, "add some description");
                    if (actualType instanceof WildcardType) {
                        if (elementMethod == null) {
                            Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage());
                            objectFactory = instantiateObjectFactory(objectFactoryClass);
                            elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass,
                                    propName);
                        }
                        // This is the case of Collection<JAXBElement<?>>
                        // we need to exctract the specific type from the factory method
                        if (elementMethod == null) {
                            throw new IllegalArgumentException(
                                    "Wildcard type in JAXBElement field specification and no facotry method found for field "
                                            + fieldName + " in " + beanClass
                                            + ", cannot determine collection type (inner type argument)");
                        }
                        Type factoryMethodGenericReturnType = elementMethod.getGenericReturnType();
                        Type factoryMethodTypeArgument = getTypeArgument(factoryMethodGenericReturnType,
                                "in factory method " + elementMethod + " return type for field " + fieldName
                                        + " in " + beanClass + ", cannot determine collection type");
                        if (factoryMethodTypeArgument instanceof Class) {
                            // This is the case of JAXBElement<Whatever>
                            paramType = (Class<?>) factoryMethodTypeArgument;
                            if (Object.class.equals(paramType) && !storeAsRawType) {
                                throw new IllegalArgumentException("Factory method " + elementMethod
                                        + " type argument is Object (without @Raw) for field " + fieldName
                                        + " in " + beanClass + ", property " + propName);
                            }
                        } else {
                            throw new IllegalArgumentException(
                                    "Cannot determine factory method return type, got "
                                            + factoryMethodTypeArgument + " - for field " + fieldName + " in "
                                            + beanClass
                                            + ", cannot determine collection type (inner type argument)");
                        }
                    }
                }
                //               Class enclosing = paramType.getEnclosingClass();
                //               Class clazz = paramType.getClass();
                //               Class declaring = paramType.getDeclaringClass();
                wrapInJaxbElement = true;
            } else {
                paramType = setterType;
            }
        }

        if (Element.class.isAssignableFrom(paramType)) {
            // DOM!
            throw new IllegalArgumentException("DOM not supported in field " + fieldName + " in " + beanClass);
        }

        //check for subclasses???
        if (!storeAsRawType && xsubnode.getTypeQName() != null) {
            Class explicitParamType = getSchemaRegistry().determineCompileTimeClass(xsubnode.getTypeQName());
            if (explicitParamType == null) {
                explicitParamType = XsdTypeMapper.toJavaTypeIfKnown(xsubnode.getTypeQName());
            }

            if (explicitParamType != null) {
                paramType = explicitParamType;
            }
        }

        if (!(xsubnode instanceof ListXNode) && Object.class.equals(paramType) && !storeAsRawType) {
            throw new IllegalArgumentException(
                    "Object property (without @Raw) not supported in field " + fieldName + " in " + beanClass);
        }

        String paramNamespace = inspector.determineNamespace(paramType);

        boolean problem = false;
        Object propValue = null;
        Collection<Object> propValues = null;
        if (xsubnode instanceof ListXNode) {
            ListXNode xlist = (ListXNode) xsubnode;
            if (setter != null) {
                try {
                    propValue = convertSinglePropValue(xsubnode, fieldName, paramType, storeAsRawType,
                            beanClass, paramNamespace);
                } catch (SchemaException e) {
                    problem = processSchemaException(e, xsubnode);
                }
            } else {
                // No setter, we have to use collection getter
                propValues = new ArrayList<>(xlist.size());
                for (XNode xsubsubnode : xlist) {
                    try {
                        propValues.add(convertSinglePropValue(xsubsubnode, fieldName, paramType, storeAsRawType,
                                beanClass, paramNamespace));
                    } catch (SchemaException e) {
                        problem = processSchemaException(e, xsubsubnode);
                    }
                }
            }
        } else {
            try {
                propValue = convertSinglePropValue(xsubnode, fieldName, paramType, storeAsRawType, beanClass,
                        paramNamespace);
            } catch (SchemaException e) {
                problem = processSchemaException(e, xsubnode);
            }
        }

        if (setter != null) {
            try {
                setter.invoke(bean, prepareValueToBeStored(propValue, wrapInJaxbElement, objectFactory,
                        elementMethod, propName, beanClass));
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new SystemException("Cannot invoke setter " + setter + " on bean of type " + beanClass
                        + ": " + e.getMessage(), e);
            }
        } else if (getter != null) {
            Object getterReturn;
            Collection<Object> col;
            try {
                getterReturn = getter.invoke(bean);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new SystemException("Cannot invoke getter " + getter + " on bean of type " + beanClass
                        + ": " + e.getMessage(), e);
            }
            try {
                col = (Collection<Object>) getterReturn;
            } catch (ClassCastException e) {
                throw new SystemException("Getter " + getter + " on bean of type " + beanClass + " returned "
                        + getterReturn + " instead of collection");
            }
            if (propValue != null) {
                col.add(prepareValueToBeStored(propValue, wrapInJaxbElement, objectFactory, elementMethod,
                        propName, beanClass));
            } else if (propValues != null) {
                for (Object propVal : propValues) {
                    col.add(prepareValueToBeStored(propVal, wrapInJaxbElement, objectFactory, elementMethod,
                            propName, beanClass));
                }
            } else if (!problem) {
                throw new IllegalStateException("Strange. Multival property " + propName + " in " + beanClass
                        + " produced null values list, parsed from " + xnode);
            }
            checkJaxbElementConsistence(col);
        } else {
            throw new IllegalStateException("Uh? No setter nor getter.");
        }
    }

    if (prismContext != null && bean instanceof Revivable) {
        ((Revivable) bean).revive(prismContext);
    }

    return bean;
}