Example usage for java.lang Class isInterface

List of usage examples for java.lang Class isInterface

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInterface();

Source Link

Document

Determines if the specified Class object represents an interface type.

Usage

From source file:org.broadleafcommerce.common.util.BLCFieldUtils.java

protected Class<?> getClassForField(DynamicDaoHelper helper, String token, Field field, Class<?>[] entities) {
    Class<?> clazz;
    List<Class<?>> matchedClasses = new ArrayList<Class<?>>();
    for (Class<?> entity : entities) {
        Field peekAheadField = null;
        try {/*  w ww.  ja v a  2  s .  c o  m*/
            peekAheadField = entity.getDeclaredField(token);
        } catch (NoSuchFieldException nsf) {
            //do nothing
        }
        if (peekAheadField != null) {
            matchedClasses.add(entity);
        }
    }
    if (matchedClasses.size() > 1) {
        LOG.warn("Found the property (" + token + ") in more than one class of an inheritance hierarchy. "
                + "This may lead to unwanted behavior, as the system does not know which class was intended. Do not "
                + "use the same property name in different levels of the inheritance hierarchy. Defaulting to the "
                + "first class found (" + matchedClasses.get(0).getName() + ")");
    }
    if (matchedClasses.isEmpty()) {
        //probably an artificial field (i.e. passwordConfirm on AdminUserImpl)
        return null;
    }
    Class<?> myClass = field != null ? field.getType() : entities[0];
    if (getSingleField(matchedClasses.get(0), token) != null) {
        clazz = matchedClasses.get(0);
        Class<?>[] entities2 = helper.getUpDownInheritance(clazz, sessionFactory,
                includeUnqualifiedPolymorphicEntities, useCache, ejb3ConfigurationDao);
        if (!ArrayUtils.isEmpty(entities2) && matchedClasses.size() == 1 && clazz.isInterface()) {
            try {
                clazz = entityConfiguration.lookupEntityClass(myClass.getName());
            } catch (Exception e) {
                // Do nothing - we'll use the matchedClass
            }
        }
    } else {
        clazz = myClass;
    }
    return clazz;
}

From source file:com.zyf.framework.plugin.SqlSessionFactoryBean.java

/**
 * Build a {@code SqlSessionFactory} instance.
 *
 * The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
 * {@code SqlSessionFactory} instance based on an Reader.
 * Since 1.3.0, it can be specified a {@link Configuration} instance directly(without config file).
 *
 * @return SqlSessionFactory// w w  w.  j a v  a2s.  co  m
 * @throws IOException if loading the config file failed
 */
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {

    Configuration configuration;

    XMLConfigBuilder xmlConfigBuilder = null;
    if (this.configuration != null) {
        configuration = this.configuration;
        if (configuration.getVariables() == null) {
            configuration.setVariables(this.configurationProperties);
        } else if (this.configurationProperties != null) {
            configuration.getVariables().putAll(this.configurationProperties);
        }
    } else if (this.configLocation != null) {
        xmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null,
                this.configurationProperties);
        configuration = xmlConfigBuilder.getConfiguration();
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(
                    "Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");
        }
        configuration = new Configuration();
        if (this.configurationProperties != null) {
            configuration.setVariables(this.configurationProperties);
        }
    }

    if (this.objectFactory != null) {
        configuration.setObjectFactory(this.objectFactory);
    }

    if (this.objectWrapperFactory != null) {
        configuration.setObjectWrapperFactory(this.objectWrapperFactory);
    }

    if (this.vfs != null) {
        configuration.setVfsImpl(this.vfs);
    }

    if (hasLength(this.typeAliasesPackage)) {
        String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeAliasPackageArray) {
            configuration.getTypeAliasRegistry().registerAliases(packageToScan,
                    typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Scanned package: '" + packageToScan + "' for aliases");
            }
        }
    }

    if (!isEmpty(this.typeAliases)) {
        for (Class<?> typeAlias : this.typeAliases) {
            configuration.getTypeAliasRegistry().registerAlias(typeAlias);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered type alias: '" + typeAlias + "'");
            }
        }
    }

    if (!isEmpty(this.plugins)) {
        for (Interceptor plugin : this.plugins) {
            configuration.addInterceptor(plugin);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered plugin: '" + plugin + "'");
            }
        }
    }

    if (hasLength(this.typeHandlersPackage)) {
        String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeHandlersPackageArray) {
            configuration.getTypeHandlerRegistry().register(packageToScan);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Scanned package: '" + packageToScan + "' for type handlers");
            }
        }
    }

    if (!isEmpty(this.typeHandlers)) {
        for (TypeHandler<?> typeHandler : this.typeHandlers) {

            //TODO:
            ClazzTypeScan cts = typeHandler.getClass().getAnnotation(ClazzTypeScan.class);
            if (cts == null) {
                configuration.getTypeHandlerRegistry().register(typeHandler);
            } else {
                TypeScan typescan = cts.value();
                if (typeScanMap.containsKey(typescan.name())) {
                    String scanpath = typeScanMap.get(typescan.name());

                    ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
                    resolverUtil.find(new ResolverUtil.IsA(DescriptionID.class), scanpath);
                    Set<Class<? extends Class<?>>> handlerSet = resolverUtil.getClasses();
                    for (Class<?> type : handlerSet) {
                        try {
                            Constructor<?> c = typeHandler.getClass().getConstructor(Class.class);
                            c.newInstance(type);
                        } catch (NoSuchMethodException | SecurityException e) {
                            e.printStackTrace();
                        } catch (InstantiationException e) {
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        }

                        if (!type.isAnonymousClass() && !type.isInterface()
                                && !Modifier.isAbstract(type.getModifiers())) {
                            configuration.getTypeHandlerRegistry().register(type, typeHandler.getClass());
                        }
                    }

                }
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered type handler: '" + typeHandler + "'");
            }
        }
    }

    if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
        try {
            configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
        } catch (SQLException e) {
            throw new NestedIOException("Failed getting a databaseId", e);
        }
    }

    if (this.cache != null) {
        configuration.addCache(this.cache);
    }

    if (xmlConfigBuilder != null) {
        try {
            xmlConfigBuilder.parse();

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Parsed configuration file: '" + this.configLocation + "'");
            }
        } catch (Exception ex) {
            throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
        } finally {
            ErrorContext.instance().reset();
        }
    }

    if (this.transactionFactory == null) {
        this.transactionFactory = new SpringManagedTransactionFactory();
    }

    configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));

    if (!isEmpty(this.mapperLocations)) {
        for (Resource mapperLocation : this.mapperLocations) {
            if (mapperLocation == null) {
                continue;
            }

            try {
                XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
                        configuration, mapperLocation.toString(), configuration.getSqlFragments());
                xmlMapperBuilder.parse();
            } catch (Exception e) {
                throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
            } finally {
                ErrorContext.instance().reset();
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Parsed mapper file: '" + mapperLocation + "'");
            }
        }

        // ThinkGem ?MapperXML?
        if (mapperRefresh.isEnabled()) {
            System.out.println("mapperRefresh loading.............");
            mapperRefresh.setConfiguration(configuration);
            mapperRefresh.setMapperLocations(mapperLocations);
            mapperRefresh.run();
        }

    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Property 'mapperLocations' was not specified or no matching resources found");
        }
    }

    return this.sqlSessionFactoryBuilder.build(configuration);
}

From source file:org.eclipse.wb.internal.core.model.creation.ThisCreationSupport.java

@Override
public Object create(EvaluationContext context, ExecutionFlowFrameVisitor visitor) throws Exception {
    Class<?> componentClass = getComponentClass();
    // prepare constructor
    String signature;/*from   www . j  av  a  2  s  .c o m*/
    Constructor<?> constructor;
    Object[] argumentValues;
    if (m_invocation != null) {
        IMethodBinding methodBinding = AstNodeUtils.getSuperBinding(m_invocation);
        signature = AstNodeUtils.getMethodSignature(methodBinding);
        constructor = AstReflectionUtils.getConstructor(componentClass, m_invocation);
        List<Expression> arguments = DomGenerics.arguments(m_invocation);
        argumentValues = evaluateExpressions(context, arguments);
        argumentValues = AstReflectionUtils.updateForVarArgs(context.getClassLoader(), methodBinding,
                argumentValues);
    } else {
        signature = "<init>()";
        constructor = ReflectionUtils.getConstructorBySignature(componentClass, "<init>()");
        argumentValues = ArrayUtils.EMPTY_OBJECT_ARRAY;
    }
    if (constructor == null && !componentClass.isInterface()) {
        throw new DesignerException(ICoreExceptionConstants.EVAL_NO_CONSTRUCTOR, signature,
                componentClass.getName());
    }
    // create Object
    try {
        Object object = create0(visitor, constructor, componentClass, argumentValues);
        m_javaInfo.setObject(object);
        duringParsing_createExposedChildren();
        return object;
    } catch (DesignerException e) {
        throw e;
    } catch (Throwable e) {
        throw new DesignerException(ICoreExceptionConstants.EVAL_CGLIB, e,
                ReflectionUtils.getShortConstructorString(constructor),
                InvocationEvaluator.getArguments_toString(argumentValues),
                AstEvaluationEngine.getUserStackTrace(e));
    }
}

From source file:com.xwtec.xwserver.util.json.JSONObject.java

/**
 * Creates a bean from a JSONObject, with the specific configuration.
 *///from   ww  w .  j a  va2 s .  com
public static Object toBean(JSONObject jsonObject, Object root, JsonConfig jsonConfig) {
    if (jsonObject == null || jsonObject.isNullObject() || root == null) {
        return root;
    }

    Class rootClass = root.getClass();
    if (rootClass.isInterface()) {
        throw new JSONException("Root bean is an interface. " + rootClass);
    }

    Map classMap = jsonConfig.getClassMap();
    if (classMap == null) {
        classMap = Collections.EMPTY_MAP;
    }

    Map props = JSONUtils.getProperties(jsonObject);
    PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter();
    for (Iterator entries = jsonObject.names(jsonConfig).iterator(); entries.hasNext();) {
        String name = (String) entries.next();
        Class type = (Class) props.get(name);
        Object value = jsonObject.get(name);
        if (javaPropertyFilter != null && javaPropertyFilter.apply(root, name, value)) {
            continue;
        }
        String key = JSONUtils.convertToJavaIdentifier(name, jsonConfig);
        try {
            PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(root, key);
            if (pd != null && pd.getWriteMethod() == null) {
                log.info("Property '" + key + "' of " + root.getClass() + " has no write method. SKIPPED.");
                continue;
            }

            if (!JSONUtils.isNull(value)) {
                if (value instanceof JSONArray) {
                    if (pd == null || List.class.isAssignableFrom(pd.getPropertyType())) {
                        Class targetClass = findTargetClass(key, classMap);
                        targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass;
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null);
                        List list = JSONArray.toList((JSONArray) value, newRoot, jsonConfig);
                        setProperty(root, key, list, jsonConfig);
                    } else {
                        Class innerType = JSONUtils.getInnerComponentType(pd.getPropertyType());
                        Class targetInnerType = findTargetClass(key, classMap);
                        if (innerType.equals(Object.class) && targetInnerType != null
                                && !targetInnerType.equals(Object.class)) {
                            innerType = targetInnerType;
                        }
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(innerType, null);
                        Object array = JSONArray.toArray((JSONArray) value, newRoot, jsonConfig);
                        if (innerType.isPrimitive() || JSONUtils.isNumber(innerType)
                                || Boolean.class.isAssignableFrom(innerType) || JSONUtils.isString(innerType)) {
                            array = JSONUtils.getMorpherRegistry()
                                    .morph(Array.newInstance(innerType, 0).getClass(), array);
                        } else if (!array.getClass().equals(pd.getPropertyType())) {
                            if (!pd.getPropertyType().equals(Object.class)) {
                                Morpher morpher = JSONUtils.getMorpherRegistry()
                                        .getMorpherFor(Array.newInstance(innerType, 0).getClass());
                                if (IdentityObjectMorpher.getInstance().equals(morpher)) {
                                    ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher(
                                            new BeanMorpher(innerType, JSONUtils.getMorpherRegistry()));
                                    JSONUtils.getMorpherRegistry().registerMorpher(beanMorpher);
                                }
                                array = JSONUtils.getMorpherRegistry()
                                        .morph(Array.newInstance(innerType, 0).getClass(), array);
                            }
                        }
                        setProperty(root, key, array, jsonConfig);
                    }
                } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                        || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                        || JSONFunction.class.isAssignableFrom(type)) {
                    if (pd != null) {
                        if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                            setProperty(root, key, null, jsonConfig);
                        } else if (!pd.getPropertyType().isInstance(value)) {
                            Morpher morpher = JSONUtils.getMorpherRegistry()
                                    .getMorpherFor(pd.getPropertyType());
                            if (IdentityObjectMorpher.getInstance().equals(morpher)) {
                                log.warn("Can't transform property '" + key + "' from " + type.getName()
                                        + " into " + pd.getPropertyType().getName()
                                        + ". Will register a default BeanMorpher");
                                JSONUtils.getMorpherRegistry().registerMorpher(
                                        new BeanMorpher(pd.getPropertyType(), JSONUtils.getMorpherRegistry()));
                            }
                            setProperty(root, key,
                                    JSONUtils.getMorpherRegistry().morph(pd.getPropertyType(), value),
                                    jsonConfig);
                        } else {
                            setProperty(root, key, value, jsonConfig);
                        }
                    } else if (root instanceof Map) {
                        setProperty(root, key, value, jsonConfig);
                    } else {
                        log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class "
                                + root.getClass().getName());
                    }
                } else {
                    if (pd != null) {
                        Class targetClass = pd.getPropertyType();
                        if (jsonConfig.isHandleJettisonSingleElementArray()) {
                            JSONArray array = new JSONArray().element(value, jsonConfig);
                            Class newTargetClass = findTargetClass(key, classMap);
                            newTargetClass = newTargetClass == null ? findTargetClass(name, classMap)
                                    : newTargetClass;
                            Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(newTargetClass,
                                    null);
                            if (targetClass.isArray()) {
                                setProperty(root, key, JSONArray.toArray(array, newRoot, jsonConfig),
                                        jsonConfig);
                            } else if (Collection.class.isAssignableFrom(targetClass)) {
                                setProperty(root, key, JSONArray.toList(array, newRoot, jsonConfig),
                                        jsonConfig);
                            } else if (JSONArray.class.isAssignableFrom(targetClass)) {
                                setProperty(root, key, array, jsonConfig);
                            } else {
                                setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig),
                                        jsonConfig);
                            }
                        } else {
                            if (targetClass == Object.class) {
                                targetClass = findTargetClass(key, classMap);
                                targetClass = targetClass == null ? findTargetClass(name, classMap)
                                        : targetClass;
                            }
                            Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass,
                                    null);
                            setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig);
                        }
                    } else if (root instanceof Map) {
                        Class targetClass = findTargetClass(key, classMap);
                        targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass;
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null);
                        setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig);
                    } else {
                        log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class "
                                + rootClass.getName());
                    }
                }
            } else {
                if (type.isPrimitive()) {
                    // assume assigned default value
                    log.warn("Tried to assign null value to " + key + ":" + type.getName());
                    setProperty(root, key, JSONUtils.getMorpherRegistry().morph(type, null), jsonConfig);
                } else {
                    setProperty(root, key, null, jsonConfig);
                }
            }
        } catch (JSONException jsone) {
            throw jsone;
        } catch (Exception e) {
            throw new JSONException("Error while setting property=" + name + " type " + type, e);
        }
    }

    return root;
}

From source file:com.glaf.core.util.ReflectUtils.java

private static Object getEmptyObject(Class<?> returnType, Map<Class<?>, Object> emptyInstances, int level) {
    if (level > 2)
        return null;
    if (returnType == null) {
        return null;
    } else if (returnType == boolean.class || returnType == Boolean.class) {
        return false;
    } else if (returnType == char.class || returnType == Character.class) {
        return '\0';
    } else if (returnType == byte.class || returnType == Byte.class) {
        return (byte) 0;
    } else if (returnType == short.class || returnType == Short.class) {
        return (short) 0;
    } else if (returnType == int.class || returnType == Integer.class) {
        return 0;
    } else if (returnType == long.class || returnType == Long.class) {
        return 0L;
    } else if (returnType == float.class || returnType == Float.class) {
        return 0F;
    } else if (returnType == double.class || returnType == Double.class) {
        return 0D;
    } else if (returnType.isArray()) {
        return Array.newInstance(returnType.getComponentType(), 0);
    } else if (returnType.isAssignableFrom(ArrayList.class)) {
        return new java.util.ArrayList<Object>(0);
    } else if (returnType.isAssignableFrom(HashSet.class)) {
        return new HashSet<Object>(0);
    } else if (returnType.isAssignableFrom(HashMap.class)) {
        return new java.util.concurrent.ConcurrentHashMap<Object, Object>(0);
    } else if (String.class.equals(returnType)) {
        return "";
    } else if (!returnType.isInterface()) {
        try {/*from  w ww .j a va  2 s.c  o  m*/
            Object value = emptyInstances.get(returnType);
            if (value == null) {
                value = returnType.newInstance();
                emptyInstances.put(returnType, value);
            }
            Class<?> cls = value.getClass();
            while (cls != null && cls != Object.class) {
                Field[] fields = cls.getDeclaredFields();
                for (Field field : fields) {
                    Object property = getEmptyObject(field.getType(), emptyInstances, level + 1);
                    if (property != null) {
                        try {
                            if (!field.isAccessible()) {
                                field.setAccessible(true);
                            }
                            field.set(value, property);
                        } catch (Throwable e) {
                        }
                    }
                }
                cls = cls.getSuperclass();
            }
            return value;
        } catch (Throwable e) {
            return null;
        }
    } else {
        return null;
    }
}

From source file:gov.nih.nci.system.webservice.WSQuery.java

private Object copyValue(Object newObject, Object obj, Class objKlass) {
    try {//from   w w w .j  a va2s.c  o  m
        Field[] newObjFields = objKlass.getDeclaredFields();
        for (int i = 0; i < newObjFields.length; i++) {
            Field field = newObjFields[i];
            field.setAccessible(true);
            String fieldName = field.getName();
            if (fieldName.equals("serialVersionUID"))
                continue;

            //            if (field.getType().getName().indexOf("gov.nih.nci") > -1) continue;
            if (field.getType().isPrimitive() || field.getType().getName().startsWith("java.")) {
                String getterMethodName = "get" + fieldName.substring(0, 1).toUpperCase()
                        + fieldName.substring(1);
                String setterMethodName = "set" + fieldName.substring(0, 1).toUpperCase()
                        + fieldName.substring(1);
                log.debug("WSQuery.copyValue:  methodName = " + getterMethodName);
                Method getterMethod = objKlass.getMethod(getterMethodName);
                Object value = getterMethod.invoke(obj);
                Method setterMethod = newObject.getClass().getMethod(setterMethodName,
                        new Class[] { getterMethod.getReturnType() });
                setterMethod.invoke(newObject, new Object[] { value });
            }
        }
        // the superclass
        objKlass = objKlass.getSuperclass();
        while (objKlass != null && !objKlass.equals(Object.class) && !objKlass.isInterface()) {
            copyValue(newObject, obj, objKlass);
            objKlass = objKlass.getSuperclass();
        }

    } catch (Exception e) {
        e.printStackTrace();
        log.error("WSQuery.copyValue: WS Error" + e.getMessage());
        //System.out.println("WSQuery.copyValue: WS Error"+ e);
        return null;
    }
    return newObject;
}

From source file:net.sf.json.JSONObject.java

/**
 * Creates a bean from a JSONObject, with the specific configuration.
 *//*  www  .ja v a 2 s  .co  m*/
public static Object toBean(JSONObject jsonObject, Object root, JsonConfig jsonConfig) {
    if (jsonObject == null || jsonObject.isNullObject() || root == null) {
        return root;
    }

    Class rootClass = root.getClass();
    if (rootClass.isInterface()) {
        throw new JSONException("Root bean is an interface. " + rootClass);
    }

    Map classMap = jsonConfig.getClassMap();
    if (classMap == null) {
        classMap = Collections.EMPTY_MAP;
    }

    Map props = JSONUtils.getProperties(jsonObject);
    PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter();
    for (Iterator entries = jsonObject.names(jsonConfig).iterator(); entries.hasNext();) {
        String name = (String) entries.next();
        Class type = (Class) props.get(name);
        Object value = jsonObject.get(name);
        if (javaPropertyFilter != null && javaPropertyFilter.apply(root, name, value)) {
            continue;
        }
        String key = JSONUtils.convertToJavaIdentifier(name, jsonConfig);
        try {
            PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(root, key);
            if (pd != null && pd.getWriteMethod() == null) {
                log.info("Property '" + key + "' of " + root.getClass() + " has no write method. SKIPPED.");
                continue;
            }

            if (!JSONUtils.isNull(value)) {
                if (value instanceof JSONArray) {
                    if (pd == null || List.class.isAssignableFrom(pd.getPropertyType())) {
                        Class targetClass = resolveClass(classMap, key, name, type);
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null);
                        List list = JSONArray.toList((JSONArray) value, newRoot, jsonConfig);
                        setProperty(root, key, list, jsonConfig);
                    } else {
                        Class innerType = JSONUtils.getInnerComponentType(pd.getPropertyType());
                        Class targetInnerType = findTargetClass(key, classMap);
                        if (innerType.equals(Object.class) && targetInnerType != null
                                && !targetInnerType.equals(Object.class)) {
                            innerType = targetInnerType;
                        }
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(innerType, null);
                        Object array = JSONArray.toArray((JSONArray) value, newRoot, jsonConfig);
                        if (innerType.isPrimitive() || JSONUtils.isNumber(innerType)
                                || Boolean.class.isAssignableFrom(innerType) || JSONUtils.isString(innerType)) {
                            array = JSONUtils.getMorpherRegistry()
                                    .morph(Array.newInstance(innerType, 0).getClass(), array);
                        } else if (!array.getClass().equals(pd.getPropertyType())) {
                            if (!pd.getPropertyType().equals(Object.class)) {
                                Morpher morpher = JSONUtils.getMorpherRegistry()
                                        .getMorpherFor(Array.newInstance(innerType, 0).getClass());
                                if (IdentityObjectMorpher.getInstance().equals(morpher)) {
                                    ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher(
                                            new BeanMorpher(innerType, JSONUtils.getMorpherRegistry()));
                                    JSONUtils.getMorpherRegistry().registerMorpher(beanMorpher);
                                }
                                array = JSONUtils.getMorpherRegistry()
                                        .morph(Array.newInstance(innerType, 0).getClass(), array);
                            }
                        }
                        setProperty(root, key, array, jsonConfig);
                    }
                } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                        || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                        || JSONFunction.class.isAssignableFrom(type)) {
                    if (pd != null) {
                        if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                            setProperty(root, key, null, jsonConfig);
                        } else if (!pd.getPropertyType().isInstance(value)) {
                            Morpher morpher = JSONUtils.getMorpherRegistry()
                                    .getMorpherFor(pd.getPropertyType());
                            if (IdentityObjectMorpher.getInstance().equals(morpher)) {
                                log.warn("Can't transform property '" + key + "' from " + type.getName()
                                        + " into " + pd.getPropertyType().getName()
                                        + ". Will register a default BeanMorpher");
                                JSONUtils.getMorpherRegistry().registerMorpher(
                                        new BeanMorpher(pd.getPropertyType(), JSONUtils.getMorpherRegistry()));
                            }
                            setProperty(root, key,
                                    JSONUtils.getMorpherRegistry().morph(pd.getPropertyType(), value),
                                    jsonConfig);
                        } else {
                            setProperty(root, key, value, jsonConfig);
                        }
                    } else if (root instanceof Map) {
                        setProperty(root, key, value, jsonConfig);
                    } else {
                        log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class "
                                + root.getClass().getName());
                    }
                } else {
                    if (pd != null) {
                        Class targetClass = pd.getPropertyType();
                        if (jsonConfig.isHandleJettisonSingleElementArray()) {
                            JSONArray array = new JSONArray().element(value, jsonConfig);
                            Class newTargetClass = resolveClass(classMap, key, name, type);
                            Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(newTargetClass,
                                    (JSONObject) value);
                            if (targetClass.isArray()) {
                                setProperty(root, key, JSONArray.toArray(array, newRoot, jsonConfig),
                                        jsonConfig);
                            } else if (Collection.class.isAssignableFrom(targetClass)) {
                                setProperty(root, key, JSONArray.toList(array, newRoot, jsonConfig),
                                        jsonConfig);
                            } else if (JSONArray.class.isAssignableFrom(targetClass)) {
                                setProperty(root, key, array, jsonConfig);
                            } else {
                                setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig),
                                        jsonConfig);
                            }
                        } else {
                            if (targetClass == Object.class) {
                                targetClass = resolveClass(classMap, key, name, type);
                                if (targetClass == null) {
                                    targetClass = Object.class;
                                }
                            }
                            Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass,
                                    (JSONObject) value);
                            setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig);
                        }
                    } else if (root instanceof Map) {
                        Class targetClass = findTargetClass(key, classMap);
                        targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass;
                        Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null);
                        setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig);
                    } else {
                        log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class "
                                + rootClass.getName());
                    }
                }
            } else {
                if (type.isPrimitive()) {
                    // assume assigned default value
                    log.warn("Tried to assign null value to " + key + ":" + type.getName());
                    setProperty(root, key, JSONUtils.getMorpherRegistry().morph(type, null), jsonConfig);
                } else {
                    setProperty(root, key, null, jsonConfig);
                }
            }
        } catch (JSONException jsone) {
            throw jsone;
        } catch (Exception e) {
            throw new JSONException("Error while setting property=" + name + " type " + type, e);
        }
    }

    return root;
}

From source file:org.apache.axis.description.JavaServiceDesc.java

/**
 * Recursive helper class for loadServiceDescByIntrospection
 *//*from  w w  w.j  av a  2  s . c  o  m*/
private void loadServiceDescByIntrospectionRecursive(Class implClass) {
    if (Skeleton.class.equals(implClass)) {
        return;
    }

    Method[] methods = getMethods(implClass);

    for (int i = 0; i < methods.length; i++) {
        if (Modifier.isPublic(methods[i].getModifiers()) && !isServiceLifeCycleMethod(implClass, methods[i])) {
            getSyncedOperationsForName(implClass, methods[i].getName());
        }
    }

    if (implClass.isInterface()) {
        Class[] superClasses = implClass.getInterfaces();
        for (int i = 0; i < superClasses.length; i++) {
            Class superClass = superClasses[i];
            if (!superClass.getName().startsWith("java.") && !superClass.getName().startsWith("javax.")
                    && (stopClasses == null || !stopClasses.contains(superClass.getName()))) {
                loadServiceDescByIntrospectionRecursive(superClass);
            }
        }
    } else {
        Class superClass = implClass.getSuperclass();
        if (superClass != null && !superClass.getName().startsWith("java.")
                && !superClass.getName().startsWith("javax.")
                && (stopClasses == null || !stopClasses.contains(superClass.getName()))) {
            loadServiceDescByIntrospectionRecursive(superClass);
        }
    }
}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.FieldManager.java

protected Class<?> getClassForField(PersistenceManager persistenceManager, String token, Field field,
        Class<?>[] entities) {
    Class<?> clazz;
    List<Class<?>> matchedClasses = new ArrayList<Class<?>>();
    for (Class<?> entity : entities) {
        Field peekAheadField = null;
        try {//from w w  w.j  a v a2s  .  c  o m
            peekAheadField = entity.getDeclaredField(token);
        } catch (NoSuchFieldException nsf) {
            //do nothing
        }
        if (peekAheadField != null) {
            matchedClasses.add(entity);
        }
    }
    if (matchedClasses.size() > 1) {
        LOG.warn("Found the property (" + token + ") in more than one class of an inheritance hierarchy. "
                + "This may lead to unwanted behavior, as the system does not know which class was intended. Do not "
                + "use the same property name in different levels of the inheritance hierarchy. Defaulting to the "
                + "first class found (" + matchedClasses.get(0).getName() + ")");
    }
    if (matchedClasses.isEmpty()) {
        //probably an artificial field (i.e. passwordConfirm on AdminUserImpl)
        return null;
    }
    Class<?> myClass = field != null ? field.getType() : entities[0];
    if (getSingleField(matchedClasses.get(0), token) != null) {
        clazz = matchedClasses.get(0);
        Class<?>[] entities2 = persistenceManager.getUpDownInheritance(clazz);
        if (!ArrayUtils.isEmpty(entities2) && matchedClasses.size() == 1 && clazz.isInterface()) {
            try {
                clazz = entityConfiguration.lookupEntityClass(myClass.getName());
            } catch (Exception e) {
                // Do nothing - we'll use the matchedClass
            }
        }
    } else {
        clazz = myClass;
    }
    return clazz;
}

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

@SuppressWarnings("rawtypes")
private Object getObject(Type claz, List<Type> heirarchies) throws Exception {

    ParameterizedType type = null;
    Class clas = null;
    if (claz instanceof ParameterizedType) {
        type = (ParameterizedType) claz;
        clas = (Class) type.getRawType();
    } else {/*from  w w  w  . j a v  a  2s . c o m*/
        clas = (Class) claz;
    }
    if (isPrimitive(clas)) {
        return getPrimitiveValue(clas);
    } else if (isMap(clas)) {
        return getMapValue(clas, type.getActualTypeArguments(), heirarchies);
    } else if (isCollection(clas)) {
        return getListSetValue(clas, type.getActualTypeArguments(), heirarchies);
    } else if (!clas.isInterface()) {
        return getObject(clas, heirarchies);
    }
    return null;
}