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:com.web.server.EJBDeployer.java

@Override
public void run() {
    EJBJarFileListener jarFileListener = new EJBJarFileListener(registry, this.servicesRegistryPort, jarEJBMap,
            jarMDBMap, jms, connectionFactory);
    DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener);
    FileObject listendir = null;//from ww w. ja  v  a2 s.c om
    StandardFileSystemManager fsManager = new StandardFileSystemManager();
    String[] dirsToScan = scanDirectory.split(";");
    EJBContext ejbContext;
    try {
        File scanDirFile = new File(dirsToScan[0]);
        File[] scanJarFiles = scanDirFile.listFiles();
        System.out.println("SCANDIRECTORY=" + scanDirectory);
        if (scanJarFiles != null) {
            for (File scanJarFile : scanJarFiles) {
                if (scanJarFile.isFile() && scanJarFile.getAbsolutePath().endsWith(".jar")) {
                    URLClassLoader classLoader = new URLClassLoader(
                            new URL[] { new URL("file:///" + scanJarFile.getAbsolutePath()) },
                            Thread.currentThread().getContextClassLoader());
                    ConfigurationBuilder config = new ConfigurationBuilder();
                    config.addUrls(ClasspathHelper.forClassLoader(classLoader));
                    config.addClassLoader(classLoader);
                    org.reflections.Reflections reflections = new org.reflections.Reflections(config);
                    EJBContainer container = EJBContainer
                            .getInstance("file:///" + scanJarFile.getAbsolutePath(), config);
                    container.inject();
                    Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class);
                    Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class);
                    Object obj;
                    System.gc();
                    if (cls.size() > 0) {
                        ejbContext = new EJBContext();
                        ejbContext.setJarPath(scanJarFile.getAbsolutePath());
                        ejbContext.setJarDeployed(scanJarFile.getName());
                        for (Class<?> ejbInterface : cls) {
                            //BeanPool.getInstance().create(ejbInterface);
                            obj = BeanPool.getInstance().get(ejbInterface);
                            System.out.println(obj);
                            ProxyFactory factory = new ProxyFactory();
                            obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj),
                                    servicesRegistryPort);
                            String remoteBinding = container.getRemoteBinding(ejbInterface);
                            System.out.println(remoteBinding + " for EJB" + obj);
                            if (remoteBinding != null) {
                                //registry.unbind(remoteBinding);
                                registry.rebind(remoteBinding, (Remote) obj);
                                ejbContext.put(remoteBinding, obj.getClass());
                            }
                            //registry.rebind("name", (Remote) obj);
                        }
                        jarEJBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"),
                                ejbContext);
                    }
                    System.out.println("Class Message Driven" + clsMessageDriven);
                    if (clsMessageDriven.size() > 0) {
                        System.out.println("Class Message Driven");
                        MDBContext mdbContext;
                        ConcurrentHashMap<String, MDBContext> mdbContexts;
                        if (jarMDBMap.get(scanJarFile.getAbsolutePath()) != null) {
                            mdbContexts = jarMDBMap.get(scanJarFile.getAbsolutePath());
                        } else {
                            mdbContexts = new ConcurrentHashMap<String, MDBContext>();
                        }
                        jarMDBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"),
                                mdbContexts);
                        MDBContext mdbContextOld;
                        for (Class<?> mdbBean : clsMessageDriven) {
                            String classwithpackage = mdbBean.getName();
                            System.out.println("class package" + classwithpackage);
                            classwithpackage = classwithpackage.replace("/", ".");
                            System.out.println("classList:" + classwithpackage.replace("/", "."));
                            try {
                                if (!classwithpackage.contains("$")) {
                                    //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                                    //System.out.println();
                                    if (!mdbBean.isInterface()) {
                                        Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations();
                                        if (classServicesAnnot != null) {
                                            for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                                if (classServicesAnnot[annotcount] instanceof MessageDriven) {
                                                    MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount];
                                                    ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot
                                                            .activationConfig();
                                                    mdbContext = new MDBContext();
                                                    mdbContext.setMdbName(messageDrivenAnnot.name());
                                                    for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) {
                                                        if (activationConfigProperty.propertyName()
                                                                .equals(MDBContext.DESTINATIONTYPE)) {
                                                            mdbContext.setDestinationType(
                                                                    activationConfigProperty.propertyValue());
                                                        } else if (activationConfigProperty.propertyName()
                                                                .equals(MDBContext.DESTINATION)) {
                                                            mdbContext.setDestination(
                                                                    activationConfigProperty.propertyValue());
                                                        } else if (activationConfigProperty.propertyName()
                                                                .equals(MDBContext.ACKNOWLEDGEMODE)) {
                                                            mdbContext.setAcknowledgeMode(
                                                                    activationConfigProperty.propertyValue());
                                                        }
                                                    }
                                                    if (mdbContext.getDestinationType()
                                                            .equals(Queue.class.getName())) {
                                                        mdbContextOld = null;
                                                        if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                            mdbContextOld = mdbContexts
                                                                    .get(mdbContext.getMdbName());
                                                            if (mdbContextOld != null
                                                                    && mdbContext.getDestination().equals(
                                                                            mdbContextOld.getDestination())) {
                                                                throw new Exception(
                                                                        "Only one MDB can listen to destination:"
                                                                                + mdbContextOld
                                                                                        .getDestination());
                                                            }
                                                        }
                                                        mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                        Queue queue = (Queue) jms
                                                                .lookup(mdbContext.getDestination());
                                                        Connection connection = connectionFactory
                                                                .createConnection("guest", "guest");
                                                        connection.start();
                                                        Session session;
                                                        if (mdbContext.getAcknowledgeMode() != null
                                                                && mdbContext.getAcknowledgeMode()
                                                                        .equals("Auto-Acknowledge")) {
                                                            session = connection.createSession(false,
                                                                    Session.AUTO_ACKNOWLEDGE);
                                                        } else {
                                                            session = connection.createSession(false,
                                                                    Session.AUTO_ACKNOWLEDGE);
                                                        }
                                                        MessageConsumer consumer = session
                                                                .createConsumer(queue);
                                                        consumer.setMessageListener(
                                                                (MessageListener) mdbBean.newInstance());
                                                        mdbContext.setConnection(connection);
                                                        mdbContext.setSession(session);
                                                        mdbContext.setConsumer(consumer);
                                                        System.out.println("Queue=" + queue);
                                                    } else if (mdbContext.getDestinationType()
                                                            .equals(Topic.class.getName())) {
                                                        if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                            mdbContextOld = mdbContexts
                                                                    .get(mdbContext.getMdbName());
                                                            if (mdbContextOld.getConsumer() != null)
                                                                mdbContextOld.getConsumer()
                                                                        .setMessageListener(null);
                                                            if (mdbContextOld.getSession() != null)
                                                                mdbContextOld.getSession().close();
                                                            if (mdbContextOld.getConnection() != null)
                                                                mdbContextOld.getConnection().close();
                                                        }
                                                        mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                        Topic topic = (Topic) jms
                                                                .lookup(mdbContext.getDestination());
                                                        Connection connection = connectionFactory
                                                                .createConnection("guest", "guest");
                                                        connection.start();
                                                        Session session;
                                                        if (mdbContext.getAcknowledgeMode() != null
                                                                && mdbContext.getAcknowledgeMode()
                                                                        .equals("Auto-Acknowledge")) {
                                                            session = connection.createSession(false,
                                                                    Session.AUTO_ACKNOWLEDGE);
                                                        } else {
                                                            session = connection.createSession(false,
                                                                    Session.AUTO_ACKNOWLEDGE);
                                                        }
                                                        MessageConsumer consumer = session
                                                                .createConsumer(topic);
                                                        consumer.setMessageListener(
                                                                (MessageListener) mdbBean.newInstance());
                                                        mdbContext.setConnection(connection);
                                                        mdbContext.setSession(session);
                                                        mdbContext.setConsumer(consumer);
                                                        System.out.println("Topic=" + topic);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                    classLoader.close();
                    System.out.println(scanJarFile.getAbsolutePath() + " Deployed");
                }
            }
        }
        FileSystemOptions opts = new FileSystemOptions();
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
        fsManager.init();
        for (String dir : dirsToScan) {
            if (dir.startsWith("ftp://")) {
                listendir = fsManager.resolveFile(dir, opts);
            } else {
                listendir = fsManager.resolveFile(dir);
            }
            fm.addFile(listendir);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    fm.setRecursive(true);
    fm.setDelay(1000);
    fm.start();
}

From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.java

public GraphQLFieldDefinition getMethodDefinition(DfsContext dfsContext, Class<?> objectClass, Method method) {

    GraphQLFieldDefinition graphQLFieldDefinition = null;
    ResolvableTypeAccessor resolvableTypeAccessor = ResolvableTypeAccessor.forMethodReturnType(method,
            objectClass);/*from   w  w w  .j  a  va2 s . c  o  m*/
    if (resolvableTypeAccessor.isGraphQLIdOrGraphQLField()) {

        GraphQLOutputType graphQLOutputType = (GraphQLOutputType) createGraphQLFieldType(dfsContext,
                resolvableTypeAccessor, true);
        List<GraphQLArgument> graphQLArguments = buildGraphQLArgumentsFromMethodParams(dfsContext, method,
                objectClass);

        GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition()
                .name(resolvableTypeAccessor.getName())
                .deprecate(resolvableTypeAccessor.getGraphQLDeprecationReason()).argument(graphQLArguments)
                .type(graphQLOutputType).description(resolvableTypeAccessor.getDescription());

        if (!objectClass.isInterface()) {
            String beanName = objectClass.getName() + resolvableTypeAccessor.getName();
            Object object = getGraphQLSchemaBeanFactory().getBeanByType(objectClass);
            builder.dataFetcher(new ReflectionGraphQLDataFetcher(getGraphQLSchemaConfig(), object, method));
        }
        graphQLFieldDefinition = builder.build();

        addToFieldDefinitionResolverMap(dfsContext, graphQLFieldDefinition,
                resolvableTypeAccessor.getGraphQLComplexitySpelExpression());
    }

    return graphQLFieldDefinition;
}

From source file:org.debux.webmotion.server.handler.ExecutorParametersConvertorHandler.java

protected Object convert(ParameterTree parameterTree, Class<?> type, Type genericType) throws Exception {
    Object result = null;/* w  w  w  .  j a v  a2s.  c om*/

    if (parameterTree == null) {
        return null;
    }

    if (genericType == null) {
        genericType = type.getGenericSuperclass();
    }

    Map<String, List<ParameterTree>> parameterArray = parameterTree.getArray();
    Map<String, ParameterTree> parameterObject = parameterTree.getObject();
    Object value = parameterTree.getValue();

    Converter lookup = converter.lookup(type);
    if (lookup != null) {

        // converter found, use it
        result = lookup.convert(type, value);
        return result;
    }

    // Manage enums
    if (type.isEnum()) {
        Object name = value == null ? null : ((Object[]) value)[0];
        if (name != null) {
            result = Enum.valueOf((Class<? extends Enum>) type, name.toString());
        }

        // Manage collection
    } else if (Collection.class.isAssignableFrom(type)) {

        Collection instance;
        if (type.isInterface()) {
            if (List.class.isAssignableFrom(type)) {
                instance = new ArrayList();

            } else if (Set.class.isAssignableFrom(type)) {
                instance = new HashSet();

            } else if (SortedSet.class.isAssignableFrom(type)) {
                instance = new TreeSet();

            } else {
                instance = new ArrayList();
            }
        } else {
            instance = (Collection) type.newInstance();
        }

        Class convertType = String.class;
        if (genericType != null && genericType instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) genericType;
            convertType = (Class) parameterizedType.getActualTypeArguments()[0];
        }

        if (parameterObject != null) {
            for (Map.Entry<String, ParameterTree> entry : parameterObject.entrySet()) {
                ParameterTree object = entry.getValue();
                Object converted = convert(object, convertType, null);
                instance.add(converted);
            }
        } else {
            Object[] tab = (Object[]) value;
            for (Object object : tab) {
                Object converted = converter.convert(object, convertType);
                instance.add(converted);
            }
        }

        result = instance;

        // Manage map
    } else if (Map.class.isAssignableFrom(type)) {
        Map instance;
        if (type.isInterface()) {
            if (SortedMap.class.isAssignableFrom(type)) {
                instance = new TreeMap();

            } else {
                instance = new HashMap();
            }
        } else {
            instance = (Map) type.newInstance();
        }

        Class convertKeyType = String.class;
        Class convertValueType = String.class;
        if (genericType != null && genericType instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) genericType;
            convertKeyType = (Class) parameterizedType.getActualTypeArguments()[0];
            convertValueType = (Class) parameterizedType.getActualTypeArguments()[1];
        }

        for (Map.Entry<String, ParameterTree> entry : parameterObject.entrySet()) {
            String mapKey = entry.getKey();
            ParameterTree mapValue = entry.getValue();

            Object convertedKey = converter.convert(mapKey, convertKeyType);
            Object convertedValue = convert(mapValue, convertValueType, null);

            instance.put(convertedKey, convertedValue);
        }

        result = instance;

        // Manage simple object
    } else if (type.isArray()) {
        Class<?> componentType = type.getComponentType();

        if (parameterObject != null) {
            Object[] tabConverted = (Object[]) Array.newInstance(componentType, parameterObject.size());
            result = tabConverted;

            int index = 0;
            for (Map.Entry<String, ParameterTree> entry : parameterObject.entrySet()) {
                ParameterTree object = entry.getValue();
                Object objectConverted = convert(object, componentType, null);
                tabConverted[index] = objectConverted;
                index++;
            }

        } else {
            Object[] tab = (Object[]) value;
            Object[] tabConverted = (Object[]) Array.newInstance(componentType, tab.length);
            result = tabConverted;

            for (int index = 0; index < tab.length; index++) {
                Object object = tab[index];
                Object objectConverted = converter.convert(object, componentType);
                tabConverted[index] = objectConverted;
            }
        }

    } else if (value instanceof UploadFile) {
        if (File.class.isAssignableFrom(type)) {
            UploadFile uploadFile = (UploadFile) value;
            result = uploadFile.getFile();
        } else {
            result = value;
        }

        // Manage simple object
    } else {
        Object instance = type.newInstance();
        boolean one = false;

        if (parameterObject != null) {
            for (Map.Entry<String, ParameterTree> attribut : parameterObject.entrySet()) {
                String attributeName = attribut.getKey();
                ParameterTree attributeValue = attribut.getValue();

                boolean writeable = propertyUtils.isWriteable(instance, attributeName);
                if (writeable) {
                    one = true;

                    Field field = FieldUtils.getField(type, attributeName, true);
                    Class<?> attributeType = field.getType();

                    genericType = field.getGenericType();
                    Object attributeConverted = convert(attributeValue, attributeType, genericType);
                    beanUtil.setProperty(instance, attributeName, attributeConverted);
                }
            }
        }

        if (parameterArray != null) {
            for (Map.Entry<String, List<ParameterTree>> entry : parameterArray.entrySet()) {
                String attributeName = entry.getKey();
                List<ParameterTree> attributeValues = entry.getValue();

                boolean writeable = propertyUtils.isWriteable(instance, attributeName);
                if (writeable) {
                    one = true;

                    Field field = FieldUtils.getField(type, attributeName, true);
                    Class<?> attributeType = field.getType();

                    genericType = field.getGenericType();
                    Object attributeConverted = convert(attributeValues, attributeType, genericType);
                    beanUtil.setProperty(instance, attributeName, attributeConverted);
                }
            }
        }

        if (one) {
            result = instance;

        } else {
            result = null;
        }
    }

    return result;
}

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

/**
 * Returns a List or a Set taking generics into account.<br/>
 * Contributed by [Matt Small @ WaveMaker].
 *///from  w  w  w  .  j a  va2s  .c  o  m
public static Collection toCollection(JSONArray jsonArray, JsonConfig jsonConfig) {
    Collection collection = null;
    Class collectionType = jsonConfig.getCollectionType();

    if (collectionType.isInterface()) {
        if (collectionType.equals(List.class)) {
            collection = new ArrayList();
        } else if (collectionType.equals(Set.class)) {
            collection = new HashSet();
        } else {
            throw new JSONException("unknown interface: " + collectionType);
        }
    } else {
        try {
            collection = (Collection) collectionType.newInstance();
        } catch (InstantiationException e) {
            throw new JSONException(e);
        } catch (IllegalAccessException e) {
            throw new JSONException(e);
        }
    }

    Class objectClass = jsonConfig.getRootClass();
    Map classMap = jsonConfig.getClassMap();

    int size = jsonArray.size();
    for (int i = 0; i < size; i++) {
        Object value = jsonArray.get(i);

        if (JSONUtils.isNull(value)) {
            collection.add(null);
        } else {
            Class type = value.getClass();
            if (JSONArray.class.isAssignableFrom(value.getClass())) {
                collection.add(toCollection((JSONArray) value, jsonConfig));
            } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type)
                    || JSONUtils.isNumber(type) || Character.class.isAssignableFrom(type)
                    || JSONFunction.class.isAssignableFrom(type)) {

                if (objectClass != null && !objectClass.isAssignableFrom(type)) {
                    value = JSONUtils.getMorpherRegistry().morph(objectClass, value);
                }
                collection.add(value);
            } else {
                if (objectClass != null) {
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass(objectClass);
                    jsc.setClassMap(classMap);
                    collection.add(JSONObject.toBean((JSONObject) value, jsc));
                } else {
                    collection.add(JSONObject.toBean((JSONObject) value));
                }
            }
        }
    }

    return collection;
}

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

/**
 * Returns a List or a Set taking generics into account.<br/>
 * Contributed by [Matt Small @ WaveMaker].
 *///from w w  w . ja  v a 2  s. c  om
public static Collection toCollection(JSONArray jsonArray, JsonConfig jsonConfig) {
    Collection collection = null;
    Class collectionType = jsonConfig.getCollectionType();

    if (collectionType.isInterface()) {
        if (collectionType.equals(List.class)) {
            collection = new ArrayList();
        } else if (collectionType.equals(Set.class)) {
            collection = new HashSet();
        } else {
            throw new JSONException("unknown interface: " + collectionType);
        }
    } else {
        try {
            collection = (Collection) collectionType.newInstance();
        } catch (InstantiationException e) {
            throw new JSONException(e);
        } catch (IllegalAccessException e) {
            throw new JSONException(e);
        }
    }

    Class objectClass = jsonConfig.getRootClass();
    Map classMap = jsonConfig.getClassMap();

    int size = jsonArray.size();
    for (int i = 0; i < size; i++) {
        Object value = jsonArray.get(i);

        if (JSONUtils.isNull(value)) {
            collection.add(null);
        } else {
            Class type = value.getClass();
            if (JSONArray.class.isAssignableFrom(value.getClass())) {
                collection.add(toCollection((JSONArray) value, jsonConfig));
            } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type)
                    || JSONUtils.isNumber(type) || Character.class.isAssignableFrom(type)
                    || JSONFunction.class.isAssignableFrom(type)) {

                if (!value.getClass().isAssignableFrom(type)) {
                    throw new JSONException("can't assign value " + value + " of type " + value.getClass()
                            + " to Collection of type " + type);
                }
                collection.add(value);
            } else {
                if (objectClass != null) {
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass(objectClass);
                    jsc.setClassMap(classMap);
                    collection.add(JSONObject.toBean((JSONObject) value, jsc));
                } else {
                    collection.add(JSONObject.toBean((JSONObject) value));
                }
            }
        }
    }

    return collection;
}

From source file:org.apache.openjpa.util.ProxyManagerImpl.java

/**
 * Return the concrete type for proxying.
 *//*ww w  . ja  va  2  s.c  om*/
protected Class toProxyableCollectionType(Class type) {
    if (type.getName().endsWith(PROXY_SUFFIX))
        type = type.getSuperclass();
    else if (type.isInterface()) {
        type = toConcreteType(type, _stdCollections);
        if (type == null)
            throw new UnsupportedException(_loc.get("no-proxy-intf", type));
    } else if (Modifier.isAbstract(type.getModifiers()))
        throw new UnsupportedException(_loc.get("no-proxy-abstract", type));
    return type;
}

From source file:org.apache.openjpa.util.ProxyManagerImpl.java

/**
 * Return the concrete type for proxying.
 *///from w w  w. j a va 2s. co  m
protected Class toProxyableMapType(Class type) {
    if (type.getName().endsWith(PROXY_SUFFIX))
        type = type.getSuperclass();
    else if (type.isInterface()) {
        type = toConcreteType(type, _stdMaps);
        if (type == null)
            throw new UnsupportedException(_loc.get("no-proxy-intf", type));
    } else if (Modifier.isAbstract(type.getModifiers()))
        throw new UnsupportedException(_loc.get("no-proxy-abstract", type));
    return type;
}

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

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

    if (claz.isEnum())
        return claz.getEnumConstants()[0];

    if (isMap(claz)) {
        return getMapValue(claz, claz.getTypeParameters(), heirarchies);
    } else if (isCollection(claz)) {
        return getListSetValue(claz, claz.getTypeParameters(), heirarchies);
    } else if (claz.isInterface() || Modifier.isAbstract(claz.getModifiers())) {
        return null;
    }//from  ww w  .j  av a 2 s .c  o  m

    if (heirarchies.contains(claz) || heirarchies.size() >= 2)
        return null;
    heirarchies.add(claz);

    Constructor cons = null;
    try {
        cons = claz.getConstructor(new Class[] {});
    } catch (Exception e) {
        getLog().error("No public no-args constructor found for class " + claz.getName());
        return null;
    }

    Object object = cons.newInstance(new Object[] {});
    List<Field> allFields = getAllFields(claz);

    for (Field field : allFields) {

        if (Modifier.isStatic(field.getModifiers()))
            continue;

        if (!field.isAccessible()) {
            field.setAccessible(true);
        }

        List<Type> fheirlst = new ArrayList<Type>(heirarchies);

        if (isDebugEnabled())
            getLog().info("Parsing Class " + getHeirarchyStr(fheirlst) + " field " + field.getName() + " type "
                    + field.getType().equals(boolean.class));

        if (isPrimitive(field.getType())) {
            field.set(object, getPrimitiveValue(field.getType()));
        } else if (isMap(field.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            field.set(object, getMapValue(field.getType(), type.getActualTypeArguments(), fheirlst));
        } else if (isCollection(field.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            field.set(object, getListSetValue(field.getType(), type.getActualTypeArguments(), fheirlst));
        } else if (!claz.equals(field.getType())) {
            Object fieldval = getObject(field.getType(), fheirlst);
            field.set(object, fieldval);
        } else if (claz.equals(field.getType())) {
            if (isDebugEnabled())
                getLog().info("Ignoring recursive fields...");
        }
    }
    return object;
}

From source file:org.apache.drill.jdbc.proxy.InvocationReporterImpl.java

/**
 * Renders a value with its corresponding <em>declared</em> type.
 *
 * @param  declaredType//from  w  w w  .  j  a  va  2 s . c  o  m
 *         the corresponding declared method parameter or return type
 * @value  value
 *         the value to render
 */
private String formatTypeAndValue(Class<?> declaredType, Object value) {
    final String declaredTypePart = "(" + formatType(declaredType) + ") ";

    final String actualTypePart;
    final String actualValuePart;
    if (null == value) {
        // Null--show no actual type or object ID.
        actualTypePart = "";
        actualValuePart = formatValue(value);
    } else {
        // Non-null value--show at least some representation of value.
        Class<?> rawActualType = value.getClass();
        Class<?> origActualType = declaredType.isPrimitive() ? declaredType : rawActualType;
        if (String.class == rawActualType) {
            // String--show no actual type or object ID.
            actualTypePart = "";
            actualValuePart = formatValue(value);
        } else if (origActualType.isPrimitive()) {
            // Primitive type--show no actual type or object ID.
            actualTypePart = "";
            // (Remember--primitive type is wrapped here.)
            actualValuePart = value.toString();
        } else {
            // Non-primitive, non-String value--include object ID.
            final String idPrefix = "<id=" + getObjectId(value) + "> ";
            if (declaredType.isInterface() && JDBC_PACKAGES.contains(declaredType.getPackage())) {
                // JDBC interface implementation class--show no actual type or value
                // (because object is proxied and therefore all uses will be traced).
                actualTypePart = "";
                actualValuePart = idPrefix + "...";
            } else if (origActualType == declaredType) {
                // Actual type is same as declared--don't show redundant actual type.
                actualTypePart = "";
                actualValuePart = idPrefix + formatValue(value);
            } else {
                // Other--show actual type and (try to) show value.
                actualTypePart = "(" + formatType(rawActualType) + ") ";
                actualValuePart = idPrefix + formatValue(value);
            }
        }
    }
    final String result = declaredTypePart + actualTypePart + actualValuePart;
    return result;
}

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

/**
 * {@inheritDoc} Return an instance of the specified type allowing access to provider-specific APIs. If the Bean
 * Validation provider implementation does not support the specified class, <code>ValidationException</code> is
 * thrown.// w w  w . j av  a  2  s.  co  m
 *
 * @param type the class of the object to be returned.
 * @return an instance of the specified class
 * @throws ValidationException if the provider does not support the call.
 */
// @Override - not allowed in 1.5 for Interface methods
public <T> T unwrap(Class<T> type) {
    // FIXME 2011-03-27 jw:
    // This code is unsecure.
    // It should allow only a fixed set of classes.
    // Can't fix this because don't know which classes this method should support.

    if (type.isAssignableFrom(getClass())) {
        @SuppressWarnings("unchecked")
        final T result = (T) this;
        return result;
    }
    if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
        return newInstance(type);
    }
    try {
        final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
        if (type.isAssignableFrom(cls)) {
            @SuppressWarnings("unchecked")
            final Class<? extends T> implClass = (Class<? extends T>) cls;
            return newInstance(implClass);
        }
    } catch (ClassNotFoundException e) {
    }
    throw new ValidationException("Type " + type + " not supported");
}