Example usage for java.lang.reflect Type getClass

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.shaman.rpg.editor.objects.ui.properties.AdvancedLogicSupport.java

private static void resolveType(StringBuilder s, Type t) {
    if (t instanceof TypeVariable) {
        Type[] bounds = ((TypeVariable) t).getBounds();
        s.append("? extends ");
        for (int j = 0; j < bounds.length; ++j) {
            if (j > 0)
                s.append(", ");
            resolveType(s, bounds[j]);//from ww  w  . j  av a 2 s .co  m
        }
    } else if (t instanceof Class) {
        s.append(((Class) t).getCanonicalName());
    } else if (t instanceof ParameterizedType) {
        resolveType(s, ((ParameterizedType) t).getRawType());
        Type[] args = ((ParameterizedType) t).getActualTypeArguments();
        if (args.length > 0) {
            s.append("<");
            for (int j = 0; j < args.length; ++j) {
                if (j > 0)
                    s.append(", ");
                resolveType(s, args[j]);
            }
            s.append(">");
        }
    } else if (t instanceof WildcardType) {
        Type[] bounds = ((WildcardType) t).getUpperBounds();
        if (bounds.length > 0) {
            if (bounds.length == 1 && bounds[0].equals(Object.class)) {
                return; //no upper bound, this should not happen
            }
            s.append("? extends ");
            for (int j = 0; j < bounds.length; ++j) {
                if (j > 0)
                    s.append(", ");
                resolveType(s, bounds[j]);
            }
        }
    } else {
        LOG.info("unknown type: " + t + " of class " + t.getClass());
    }
}

From source file:com.proofpoint.jaxrs.JsonMapper.java

@Override
public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream)
        throws IOException {
    // Prevent broken browser from attempting to render the json as html
    httpHeaders.add(HttpHeaders.X_CONTENT_TYPE_OPTIONS, "nosniff");

    JsonFactory jsonFactory = objectMapper.getFactory();
    jsonFactory.setCharacterEscapes(HTMLCharacterEscapes.INSTANCE);

    JsonGenerator jsonGenerator = jsonFactory.createGenerator(outputStream, JsonEncoding.UTF8);

    // Important: we are NOT to close the underlying stream after
    // mapping, so we need to instruct generator:
    jsonGenerator.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

    // Pretty print?
    if (isPrettyPrintRequested()) {
        jsonGenerator.useDefaultPrettyPrinter();
    }//from   w  w  w.j  a va  2  s .c  o m

    // 04-Mar-2010, tatu: How about type we were given? (if any)
    JavaType rootType = null;
    if (genericType != null && value != null) {
        // 10-Jan-2011, tatu: as per [JACKSON-456], it's not safe to just force root
        //    type since it prevents polymorphic type serialization. Since we really
        //    just need this for generics, let's only use generic type if it's truly
        //    generic.
        if (genericType.getClass() != Class.class) { // generic types are other implementations of 'java.lang.reflect.Type'
            // This is still not exactly right; should root type be further
            // specialized with 'value.getClass()'? Let's see how well this works before
            // trying to come up with more complete solution.
            rootType = objectMapper.getTypeFactory().constructType(genericType);
            // 26-Feb-2011, tatu: To help with [JACKSON-518], we better recognize cases where
            //    type degenerates back into "Object.class" (as is the case with plain TypeVariable,
            //    for example), and not use that.
            //
            if (rootType.getRawClass() == Object.class) {
                rootType = null;
            }
        }
    }

    ObjectWriter writer;
    if (rootType != null) {
        writer = objectMapper.writerWithType(rootType);
    } else {
        writer = objectMapper.writer();
    }

    writer.writeValue(jsonGenerator, value);

    // add a newline so when you use curl it looks nice
    outputStream.write('\n');
}

From source file:io.airlift.jaxrs.JsonMapper.java

@Override
public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream)
        throws IOException {
    // Prevent broken browser from attempting to render the json as html
    httpHeaders.add(HttpHeaders.X_CONTENT_TYPE_OPTIONS, "nosniff");

    JsonFactory jsonFactory = objectMapper.getJsonFactory();
    jsonFactory.setCharacterEscapes(HTMLCharacterEscapes.INSTANCE);

    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(outputStream, JsonEncoding.UTF8);

    // Important: we are NOT to close the underlying stream after
    // mapping, so we need to instruct generator:
    jsonGenerator.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

    // Pretty print?
    if (isPrettyPrintRequested()) {
        jsonGenerator.useDefaultPrettyPrinter();
    }// ww  w.j  av  a2  s .c  om

    // 04-Mar-2010, tatu: How about type we were given? (if any)
    JavaType rootType = null;
    if (genericType != null && value != null) {
        // 10-Jan-2011, tatu: as per [JACKSON-456], it's not safe to just force root
        //    type since it prevents polymorphic type serialization. Since we really
        //    just need this for generics, let's only use generic type if it's truly
        //    generic.
        if (genericType.getClass() != Class.class) { // generic types are other implementations of 'java.lang.reflect.Type'
            // This is still not exactly right; should root type be further
            // specialized with 'value.getClass()'? Let's see how well this works before
            // trying to come up with more complete solution.
            rootType = objectMapper.getTypeFactory().constructType(genericType);
            // 26-Feb-2011, tatu: To help with [JACKSON-518], we better recognize cases where
            //    type degenerates back into "Object.class" (as is the case with plain TypeVariable,
            //    for example), and not use that.
            //
            if (rootType.getRawClass() == Object.class) {
                rootType = null;
            }
        }
    }

    String jsonpFunctionName = getJsonpFunctionName();
    if (jsonpFunctionName != null) {
        value = new JSONPObject(jsonpFunctionName, value, rootType);
        rootType = null;
    }

    ObjectWriter writer;
    if (rootType != null) {
        writer = objectMapper.writerWithType(rootType);
    } else {
        writer = objectMapper.writer();
    }

    writer.writeValue(jsonGenerator, value);

    // add a newline so when you use curl it looks nice
    outputStream.write('\n');
}

From source file:org.evosuite.utils.generic.GenericClass.java

/**
 * Returns the erasure of the given type.
 *///from   w ww  .  j a v  a 2  s .c om
private static Class<?> erase(Type type) {
    if (type instanceof Class) {
        return (Class<?>) type;
    } else if (type instanceof ParameterizedType) {
        return (Class<?>) ((ParameterizedType) type).getRawType();
    } else if (type instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) type;
        if (tv.getBounds().length == 0)
            return Object.class;
        else
            return erase(tv.getBounds()[0]);
    } else if (type instanceof GenericArrayType) {
        GenericArrayType aType = (GenericArrayType) type;
        return GenericArrayTypeImpl.createArrayType(erase(aType.getGenericComponentType()));
    } else if (type instanceof CaptureType) {
        CaptureType captureType = (CaptureType) type;
        if (captureType.getUpperBounds().length == 0)
            return Object.class;
        else
            return erase(captureType.getUpperBounds()[0]);
    } else {
        // TODO at least support CaptureType here
        throw new RuntimeException("not supported: " + type.getClass());
    }
}

From source file:com.wavemaker.json.type.reflect.ReflectTypeUtils.java

/**
 * Returns information about array or collection types.
 * /*from   w w w  .ja v  a  2 s. c o m*/
 * @param type The type to introspect.
 * @param typeState The current TypeState.
 * @param strict True indicates that processing should stop on ambiguous entries; false indicates that null should
 *        be entered.
 * @return A Tuple.Two containing:
 *         <ol>
 *         <li>The enclosed nested Type; String[][] would return String.class, while List<Map<String,String>> will
 *         return the Type of Map<String,String>.</li>
 *         <li>The list of all enclosing classes. String[][] will return [String[][].class, String[].class].</li>
 *         </ol>
 */
protected static Tuple.Two<TypeDefinition, List<ListTypeDefinition>> getArrayDimensions(Type type,
        TypeState typeState, boolean strict) {

    if (type instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) type;

        Type[] types = pt.getActualTypeArguments();
        if (1 == types.length) {
            Tuple.Two<TypeDefinition, List<ListTypeDefinition>> temp = getArrayDimensions(types[0], typeState,
                    strict);
            temp.v2.add(0, getListTypeDefinition(pt.getRawType(), typeState, strict));
            return temp;
        } else {
            return new Tuple.Two<TypeDefinition, List<ListTypeDefinition>>(
                    getTypeDefinition(pt, typeState, strict), new ArrayList<ListTypeDefinition>());
        }
    } else if (type instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) type;

        Class<?> klass;
        try {
            klass = ClassUtils.forName(gat.toString());
        } catch (ClassNotFoundException e) {
            klass = null;
        } catch (LinkageError e) {
            klass = null;
        }
        if (klass == null && gat.getGenericComponentType() instanceof Class) {
            klass = Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
        }
        if (klass == null) {
            throw new WMRuntimeException(MessageResource.JSON_FAILED_GENERICARRAYTYPE, gat,
                    gat.getGenericComponentType());
        }

        Tuple.Two<TypeDefinition, List<ListTypeDefinition>> temp = getArrayDimensions(
                gat.getGenericComponentType(), typeState, strict);
        temp.v2.add(0, getListTypeDefinition(klass, typeState, strict));

        return temp;
    } else if (type instanceof Class && ((Class<?>) type).isArray()) {
        Tuple.Two<TypeDefinition, List<ListTypeDefinition>> temp = getArrayDimensions(
                ((Class<?>) type).getComponentType(), typeState, strict);
        temp.v2.add(0, getListTypeDefinition(type, typeState, strict));

        return temp;
    } else if (type instanceof Class) {
        return new Tuple.Two<TypeDefinition, List<ListTypeDefinition>>(
                getTypeDefinition(type, typeState, strict), new ArrayList<ListTypeDefinition>());
    } else {
        throw new WMRuntimeException(MessageResource.JSON_TYPE_UNKNOWNPARAMTYPE, type,
                type != null ? type.getClass() : null);
    }
}

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

/**
 * <p>//from  www .  j a va 2 s.  c  o m
 * getClassName
 * </p>
 *
 * @param type
 *            a {@link Type} object.
 *
 */
private void getClassName(Type type) {
    if (type instanceof Class<?>) {
        getClassName((Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        getClassName((Class<?>) ((ParameterizedType) type).getRawType());
    } else if (type instanceof WildcardType) {
        for (Type bound : ((WildcardType) type).getLowerBounds()) {
            // If there are lower bounds we need to state them, even if Object
            if (bound == null) // || GenericTypeReflector.erase(bound).equals(Object.class))
                continue;

            getClassName(bound);
        }
        for (Type bound : ((WildcardType) type).getUpperBounds()) {
            if (bound == null || (!(bound instanceof CaptureType)
                    && GenericTypeReflector.erase(bound).equals(Object.class)))
                continue;

            getClassName(bound);
        }
    } else if (type instanceof TypeVariable) {
        // Do nothing
    } else if (type instanceof CaptureType) {
        CaptureType captureType = (CaptureType) type;
        if (!(captureType.getLowerBounds().length == 0))
            getClassName(captureType.getLowerBounds()[0]);
    } else if (type instanceof GenericArrayType) {
        getClassName(((GenericArrayType) type).getGenericComponentType());
    } else {
        throw new RuntimeException("Unsupported type:" + type + ", class" + type.getClass());
    }
}

From source file:com.wavemaker.json.type.reflect.ReflectTypeUtils.java

/**
 * Returns the FieldDefinition for a field of the specified type.
 * /* w w  w .  j a  v a  2 s  . c o  m*/
 * @param type
 * @param typeState
 * @param strict True if strict mode is on; not enough information will result in exceptions instead of warnings.
 * @param The name of this field (if known)
 * @return The corresponding fieldDefinition to the type.
 */
public static FieldDefinition getFieldDefinition(Type type, TypeState typeState, boolean strict, String name) {

    GenericFieldDefinition ret = new GenericFieldDefinition();
    ret.setName(name);

    if (type == null) {
        // do nothing, it's null, but do return a FieldDefinition
    } else if (type instanceof Class) {
        Class<?> returnTypeClass = (Class<?>) type;

        if (returnTypeClass.isArray()) {
            Tuple.Two<TypeDefinition, List<ListTypeDefinition>> dimAndClass = getArrayDimensions(
                    returnTypeClass, typeState, strict);
            ret.setTypeDefinition(dimAndClass.v1);
            ret.setArrayTypes(dimAndClass.v2);
        } else if (!strict && Collection.class.isAssignableFrom(returnTypeClass)) {
            if (!JSON.class.isAssignableFrom(returnTypeClass)) {
                logger.warn(MessageResource.JSON_TYPE_NOGENERICS.getMessage(returnTypeClass));
            }

            ret.setArrayTypes(new ArrayList<ListTypeDefinition>(1));
            ret.getArrayTypes().add(getListTypeDefinition(returnTypeClass, typeState, strict));
        } else if (ClassUtils.isPrimitiveOrWrapper(returnTypeClass)) {
            TypeDefinition td = getTypeDefinition(returnTypeClass, typeState, strict);
            ret.setTypeDefinition(td);
        } else {
            TypeDefinition td = getTypeDefinition(returnTypeClass, typeState, strict);
            ret.setTypeDefinition(td);
        }
    } else if (type instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) type;

        if (Class.class == pt.getRawType()) {
            TypeDefinition td = getTypeDefinition(Class.class, typeState, strict);
            ret.setTypeDefinition(td);
        } else if (pt.getRawType() instanceof Class
                && Collection.class.isAssignableFrom((Class<?>) pt.getRawType())) {
            Tuple.Two<TypeDefinition, List<ListTypeDefinition>> dimAndClass = getArrayDimensions(pt, typeState,
                    strict);
            ret.setTypeDefinition(dimAndClass.v1);
            ret.setArrayTypes(dimAndClass.v2);
        } else if (pt.getRawType() instanceof Class && Map.class.isAssignableFrom((Class<?>) pt.getRawType())) {
            TypeDefinition td = getTypeDefinition(pt, typeState, strict);
            ret.setTypeDefinition(td);
        } else {
            if (strict) {
                throw new WMRuntimeException(MessageResource.JSON_TYPE_UNKNOWNRAWTYPE, pt.getOwnerType(), pt);
            } else {
                logger.warn(MessageResource.JSON_TYPE_UNKNOWNRAWTYPE.getMessage(pt.getOwnerType(), pt));
            }
        }
    } else if (type instanceof GenericArrayType) {
        Tuple.Two<TypeDefinition, List<ListTypeDefinition>> dimAndClass = getArrayDimensions(type, typeState,
                strict);
        ret.setTypeDefinition(dimAndClass.v1);
        ret.setArrayTypes(dimAndClass.v2);
    } else {
        throw new WMRuntimeException(MessageResource.JSON_TYPE_UNKNOWNPARAMTYPE, type,
                type != null ? type.getClass() : null);
    }

    return ret;
}

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

/**
 * <p>// ww w  .  ja va 2  s .c  om
 * getTypeName
 * </p>
 *
 * @param type
 *            a {@link java.lang.reflect.Type} object.
 * @return a {@link java.lang.String} object.
 */
public String getTypeName(Type type) {
    if (type instanceof Class<?>) {
        return getClassName((Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        return getTypeName((ParameterizedType) type);
    } else if (type instanceof WildcardType) {
        String ret = "?";
        boolean first = true;
        for (Type bound : ((WildcardType) type).getLowerBounds()) {
            // If there are lower bounds we need to state them, even if Object
            if (bound == null) // || GenericTypeReflector.erase(bound).equals(Object.class))
                continue;

            if (!first)
                ret += ", ";
            ret += " super " + getTypeName(bound);
            first = false;
        }
        for (Type bound : ((WildcardType) type).getUpperBounds()) {
            if (bound == null || (!(bound instanceof CaptureType)
                    && GenericTypeReflector.erase(bound).equals(Object.class)))
                continue;

            if (!first)
                ret += ", ";
            ret += " extends " + getTypeName(bound);
            first = false;
        }
        return ret;
    } else if (type instanceof TypeVariable) {
        return "?";
    } else if (type instanceof CaptureType) {
        CaptureType captureType = (CaptureType) type;
        if (captureType.getLowerBounds().length == 0)
            return "?";
        else
            return getTypeName(captureType.getLowerBounds()[0]);
    } else if (type instanceof GenericArrayType) {
        return getTypeName(((GenericArrayType) type).getGenericComponentType()) + "[]";
    } else {
        throw new RuntimeException("Unsupported type:" + type + ", class" + type.getClass());
    }
}

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

public String getTypeName(Type type) {
    if (type instanceof Class<?>) {
        return getClassName((Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        return getTypeName((ParameterizedType) type);
    } else if (type instanceof WildcardType) {
        String ret = "?";
        boolean first = true;
        for (Type bound : ((WildcardType) type).getLowerBounds()) {
            // If there are lower bounds we need to state them, even if Object
            if (bound == null) // || GenericTypeReflector.erase(bound).equals(Object.class))
                continue;

            if (!first)
                ret += ", ";
            ret += " super " + getTypeName(bound);
            first = false;/*from  w w  w . j a v  a2 s. c  o m*/
        }
        for (Type bound : ((WildcardType) type).getUpperBounds()) {
            if (bound == null || (!(bound instanceof CaptureType)
                    && GenericTypeReflector.erase(bound).equals(Object.class)))
                continue;

            if (!first)
                ret += ", ";
            ret += " extends " + getTypeName(bound);
            first = false;
        }
        return ret;
    } else if (type instanceof TypeVariable) {
        return "?";
    } else if (type instanceof CaptureType) {
        CaptureType captureType = (CaptureType) type;
        if (captureType.getLowerBounds().length == 0)
            return "?";
        else
            return getTypeName(captureType.getLowerBounds()[0]);
    } else if (type instanceof GenericArrayType) {
        return getTypeName(((GenericArrayType) type).getGenericComponentType()) + "[]";
    } else {
        throw new RuntimeException("Unsupported type:" + type + ", class" + type.getClass());
    }
}

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 {//from  ww  w.  j a v  a 2 s .co  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;
}