Example usage for java.lang Class getInterfaces

List of usage examples for java.lang Class getInterfaces

Introduction

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

Prototype

public Class<?>[] getInterfaces() 

Source Link

Document

Returns the interfaces directly implemented by the class or interface represented by this object.

Usage

From source file:com.seer.datacruncher.utils.generic.CommonUtils.java

public static Object getClassInstance(String className, String implementedClassName, Class<?> implementedClass,
        String sourceCode) throws Exception {
    DynamicClassLoader dynacode = DynamicClassLoader.getInstance();
    Class<?> dynaClass = dynacode.getLoadedClass(className);
    File sourceDir = new File(System.getProperty("java.io.tmpdir"), "DataCruncher/src");
    boolean createFileInTemp = false;
    if (dynaClass == null) {
        createFileInTemp = true;//from w w w. j  a  v a2  s . c om
    } else {
        boolean isExist = false;
        @SuppressWarnings("rawtypes")
        Class[] interfaces = dynaClass.getInterfaces();
        if (ArrayUtils.isNotEmpty(interfaces)) {
            for (Class<?> clz : interfaces) {
                if ((clz.getName().equalsIgnoreCase(implementedClassName))) {
                    isExist = true;
                }
            }
        }
        if (!isExist) {
            createFileInTemp = true;
        }
    }
    if (createFileInTemp) {
        boolean isCreated = CommonUtils.createFileIfNotExist(className, sourceCode, sourceDir);
        if (isCreated || dynaClass == null) {
            dynacode.addSourceDir(sourceDir);
            return dynacode.newProxyInstance(implementedClass, className);
        }
    }
    return dynaClass.newInstance();

}

From source file:com.bstek.dorado.config.text.TextParserHelper.java

private void doGetTextSectionInfo(TextSectionInfo textSectionInfo, Class<?> type) {
    for (Class<?> i : type.getInterfaces()) {
        doGetTextSectionInfo(textSectionInfo, i);
    }// w  w  w . j a va 2 s  .  c  o m

    Class<?> superclass = type.getSuperclass();
    if (superclass != null && !superclass.equals(Object.class)) {
        doGetTextSectionInfo(textSectionInfo, superclass);
    }

    collectXmlNodeInfo(textSectionInfo, type);
}

From source file:com.exadel.flamingo.flex.messaging.amf.io.util.DefaultClassGetter.java

protected Class<?> extractFromProxy(Class<?> clazz) {
    if (Proxy.isProxyClass(clazz)) {
        clazz = extractFromProxy(clazz.getInterfaces()[0]);
    } else {/*from   w  w  w.  j  av a  2  s  .c o m*/
        try {
            if (Class.forName("javassist.util.proxy.ProxyObject").isAssignableFrom(clazz)) {
                clazz = extractFromProxy(clazz.getSuperclass());
            }
        } catch (ClassNotFoundException ex) {
            if (log.isDebugEnabled())
                log.debug("Class javassist.util.proxy.ProxyObject can not be located");
        }
    }
    return clazz;
}

From source file:it.openprj.jValidator.utils.generic.CommonUtils.java

public static Object getClassInstance(String className, String implementedClassName, Class<?> implementedClass,
        String sourceCode) throws Exception {
    DynamicClassLoader dynacode = DynamicClassLoader.getInstance();
    Class<?> dynaClass = dynacode.getLoadedClass(className);
    File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src");
    boolean createFileInTemp = false;
    if (dynaClass == null) {
        createFileInTemp = true;/*from  ww  w  .j a v a  2s. c  o m*/
    } else {
        boolean isExist = false;
        @SuppressWarnings("rawtypes")
        Class[] interfaces = dynaClass.getInterfaces();
        if (ArrayUtils.isNotEmpty(interfaces)) {
            for (Class<?> clz : interfaces) {
                if ((clz.getName().equalsIgnoreCase(implementedClassName))) {
                    isExist = true;
                }
            }
        }
        if (!isExist) {
            createFileInTemp = true;
        }
    }
    if (createFileInTemp) {
        boolean isCreated = CommonUtils.createFileIfNotExist(className, sourceCode, sourceDir);
        if (isCreated || dynaClass == null) {
            dynacode.addSourceDir(sourceDir);
            return dynacode.newProxyInstance(implementedClass, className);
        }
    }
    return dynaClass.newInstance();

}

From source file:gr.interamerican.bo2.utils.JavaBeanUtils.java

/**
 * Finds the properties of a bean./*from   ww  w .java2  s  . com*/
 * 
 * <li>If the bean is a concrete class the properties of the bean, for which
 * there exists a setter method, a getter method or both. Properties of
 * super-types are returned as well.</li>
 * 
 * <li>If the bean is an abstract class, an empty array is returned</li>
 * 
 * <li>If the bean is an interface, the properties of the bean are returned.
 * The method also queries all super-interfaces and fetches their properties
 * as well.</li>
 * 
 * @param type
 *            the bean
 * @return Returns the property descriptors of a java bean.
 * 
 * TODO: Support properties of abstract classes.
 */
public static PropertyDescriptor[] getBeansProperties(Class<?> type) {

    ArrayList<PropertyDescriptor> propertyDescriptor = new ArrayList<PropertyDescriptor>();

    for (PropertyDescriptor p : PropertyUtils.getPropertyDescriptors(type)) {
        if (!propertyDescriptor.contains(p) && !p.getName().equals("class")) { //$NON-NLS-1$
            propertyDescriptor.add(p);
        }
    }

    if (type.isInterface()) {
        Class<?>[] classArray = type.getInterfaces();
        PropertyDescriptor[] pdArray;
        for (Class<?> next : classArray) {
            pdArray = getBeansProperties(next);
            for (PropertyDescriptor pd : pdArray) {
                if (!propertyDescriptor.contains(pd)) {
                    propertyDescriptor.add(pd);
                }
            }
        }
    }
    return propertyDescriptor.toArray(new PropertyDescriptor[0]);
}

From source file:pl.bristleback.server.bristle.conf.resolver.action.ActionExtractorsResolver.java

private Class getParameterClass(Class extractorClass, Class parametrizedInterface) {
    for (int i = 0; i < extractorClass.getInterfaces().length; i++) {
        Class interfaceOfClass = extractorClass.getInterfaces()[i];
        if (parametrizedInterface.equals(interfaceOfClass)) {
            Type genericInterface = extractorClass.getGenericInterfaces()[i];
            if (genericInterface instanceof ParameterizedType) {
                return (Class) ((ParameterizedType) (genericInterface)).getActualTypeArguments()[0];
            }//from   w w w . j  av  a  2s. c o m
            return Object.class;
        }
    }
    throw new BristleRuntimeException("Cannot find " + parametrizedInterface.getSimpleName()
            + " interface, this exception should never happen.");
}

From source file:com.espertech.esper.event.bean.BeanEventType.java

private static EventType[] getSuperTypes(Class clazz, BeanEventTypeFactory beanEventTypeFactory) {
    List<Class> superclasses = new LinkedList<Class>();

    // add superclass
    Class superClass = clazz.getSuperclass();
    if (superClass != null) {
        superclasses.add(superClass);// w  ww . j  a  v a 2s. com
    }

    // add interfaces
    Class interfaces[] = clazz.getInterfaces();
    superclasses.addAll(Arrays.asList(interfaces));

    // Build event types, ignoring java language types
    List<EventType> superTypes = new LinkedList<EventType>();
    for (Class superclass : superclasses) {
        if (!superclass.getName().startsWith("java")) {
            EventType superType = beanEventTypeFactory.createBeanType(superclass.getName(), superclass, false,
                    false, false);
            superTypes.add(superType);
        }
    }

    return superTypes.toArray(new EventType[superTypes.size()]);
}

From source file:com.jeeframework.util.classes.ClassUtils.java

/**
 * Return a descriptive name for the given object's type: usually simply
 * the class name, but component type class name + "[]" for arrays,
 * and an appended list of implemented interfaces for JDK proxies.
 * @param value the value to introspect//  w w  w.j  a v a  2s . c o  m
 * @return the qualified name of the class
 */
public static String getDescriptiveType(Object value) {
    if (value == null) {
        return null;
    }
    Class clazz = value.getClass();
    if (Proxy.isProxyClass(clazz)) {
        StringBuffer buf = new StringBuffer(clazz.getName());
        buf.append(" implementing ");
        Class[] ifcs = clazz.getInterfaces();
        for (int i = 0; i < ifcs.length; i++) {
            buf.append(ifcs[i].getName());
            if (i < ifcs.length - 1) {
                buf.append(',');
            }
        }
        return buf.toString();
    } else if (clazz.isArray()) {
        return getQualifiedNameForArray(clazz);
    } else {
        return clazz.getName();
    }
}

From source file:org.bytesoft.bytejta.supports.spring.ManagedConnectionFactoryPostProcessor.java

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

    Class<?> clazz = bean.getClass();
    ClassLoader cl = clazz.getClassLoader();

    Class<?>[] interfaces = clazz.getInterfaces();

    if (XADataSource.class.isInstance(bean)) {
        ManagedConnectionFactoryHandler interceptor = new ManagedConnectionFactoryHandler(bean);
        interceptor.setIdentifier(beanName);
        return Proxy.newProxyInstance(cl, interfaces, interceptor);
    } else if (XAConnectionFactory.class.isInstance(bean)) {
        ManagedConnectionFactoryHandler interceptor = new ManagedConnectionFactoryHandler(bean);
        interceptor.setIdentifier(beanName);
        return Proxy.newProxyInstance(cl, interfaces, interceptor);
    } else if (ManagedConnectionFactory.class.isInstance(bean)) {
        ManagedConnectionFactoryHandler interceptor = new ManagedConnectionFactoryHandler(bean);
        interceptor.setIdentifier(beanName);
        return Proxy.newProxyInstance(cl, interfaces, interceptor);
    } else {/*ww w . jav  a2  s .  c  o  m*/
        return bean;
    }
}

From source file:com.nortal.petit.converter.ConverterContainer.java

private Converter<?, ?> getForInterface(Class<?> type, Map<Class<?>, Converter<?, ?>> fromTypeMapping) {
    Class<?>[] interfaces = type.getInterfaces();

    for (Class<?> interfaceType : interfaces) {
        @SuppressWarnings("unchecked")
        Converter<?, ?> converter = coalesce(fromTypeMapping.get(type),
                getForInterface(interfaceType, fromTypeMapping));

        if (converter != null) {
            return converter;
        }/*from w w w. j  a v  a  2  s .  c o  m*/
    }

    return null;
}