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.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

protected void initClientEvent(RuleTemplate ruleTemplate, TypeInfo typeInfo,
        InitializerContext initializerContext) throws Exception {
    Class<?> type = typeInfo.getType();
    if (type != null && ClientEventSupported.class.isAssignableFrom(type)) {
        Map<String, ClientEventRegisterInfo> allClientEvents = new HashMap<String, ClientEventRegisterInfo>();
        Map<String, ClientEventRegisterInfo> clientEvents;

        for (Class<?> i : type.getInterfaces()) {
            clientEvents = ClientEventRegistry.getOwnClientEventRegisterInfos(i);
            if (clientEvents != null) {
                allClientEvents.putAll(clientEvents);
            }/*from  w ww.  j a v  a2 s  .  com*/
        }

        clientEvents = ClientEventRegistry.getOwnClientEventRegisterInfos(type);
        if (clientEvents != null) {
            allClientEvents.putAll(clientEvents);
        }

        for (ClientEventRegisterInfo clientEventRegisterInfo : allClientEvents.values()) {
            String name = clientEventRegisterInfo.getName();

            ClientEvent clientEvent = new AutoClientEvent(clientEventRegisterInfo);
            clientEvent.setName(name);
            String[] signature = clientEventRegisterInfo.getSignature();
            clientEvent.setParameters(signature);
            clientEvent.setDeprecated(clientEventRegisterInfo.isDeprecated());
            clientEvent.setClientTypes(clientEventRegisterInfo.getClientTypes());
            ruleTemplate.addClientEvent(clientEvent);
        }
    }
}

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

private boolean isDefaultRemoteAction(Class clazz, Method action) {
    if (!DefaultAction.class.isAssignableFrom(clazz)) {
        // this action class does not have default action
        return false;
    }//from   w  ww. j a v  a2s .  com
    Method defaultMethod = DefaultAction.class.getMethods()[0];
    if (!defaultMethod.getName().equals(action.getName())) {
        return false;
    }
    Class[] defaultParameterTypes = defaultMethod.getParameterTypes();
    if (defaultParameterTypes.length != action.getParameterTypes().length) {
        return false;
    }
    int parametersLength = defaultParameterTypes.length;
    for (int i = 0; i < parametersLength - 1; i++) {
        Class defaultParameterType = defaultParameterTypes[i];
        if (!defaultParameterType.isAssignableFrom(action.getParameterTypes()[i])) {
            return false;
        }
    }
    Type requiredLastParameterType = action.getGenericParameterTypes()[parametersLength - 1];
    Type actualLastParameterType = null;
    for (int i = 0; i < clazz.getInterfaces().length; i++) {
        Class interfaceOfClass = clazz.getInterfaces()[i];
        if (DefaultAction.class.equals(interfaceOfClass)) {
            Type genericInterface = clazz.getGenericInterfaces()[i];
            if (genericInterface instanceof ParameterizedType) {
                actualLastParameterType = ((ParameterizedType) (genericInterface)).getActualTypeArguments()[1];
            } else {
                actualLastParameterType = Object.class;
            }
        }
    }

    return requiredLastParameterType.equals(actualLastParameterType);
}

From source file:org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter.java

/**
 * The only method we will expose to users of this class. It will trigger the creation of the
 * <code>DescriptionBuilderComposite</code> based on our service class. It will also handle the
 * case of an impl class that references an SEI.
 *
 * @return - <code>DescriptionBuilderComposite</code>
 *//*from  w ww .jav a 2 s . c o  m*/
public HashMap<String, DescriptionBuilderComposite> produceDBC() {
    if (log.isDebugEnabled()) {
        log.debug("Creating DescriptionBuilderComposite map from Java Class.");
    }

    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    for (int i = 0; i < classes.size(); i++) {
        buildDBC(dbcMap, classes.get(i));
        if (seiClassName != null && !seiClassName.equals("")) {
            try {
                final ClassLoader contextClassLoader = (ClassLoader) AccessController
                        .doPrivileged(new PrivilegedAction() {
                            public Object run() {
                                return Thread.currentThread().getContextClassLoader();
                            }
                        });
                Class seiClass = null;
                try {
                    seiClass = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                        public Object run() throws ClassNotFoundException {
                            return contextClassLoader.loadClass(seiClassName);
                        }
                    });
                } catch (PrivilegedActionException e) {
                    throw (ClassNotFoundException) e.getException();
                }
                buildDBC(dbcMap, seiClass);

                // Also try to see if the SEI has any super interfaces  
                Class[] interfaces = seiClass.getInterfaces();
                for (int j = 0; j < interfaces.length; j++) {
                    buildDBC(dbcMap, interfaces[j]);
                }
            } catch (ClassNotFoundException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Class not found exception caught for class: " + seiClassName, e);
                }
            }
        }
    }
    return dbcMap;
}

From source file:org.gwtspringhibernate.reference.rlogman.spring.GwtServiceExporter.java

/**
 * Only called from isImplementedInterface().
 *//*from  w w  w .  j  a va 2  s  . com*/
private boolean isImplementedRemoteServiceInterfaceRecursive(String intfName, Class intfToCheck) {
    assert (intfToCheck.isInterface());

    if (intfToCheck.getName().equals(intfName)) {
        // The name is right, but we also verify that it is assignable to
        // RemoteService.
        // 
        if (RemoteService.class.isAssignableFrom(intfToCheck)) {
            return true;
        } else {
            return false;
        }
    }

    Class[] intfs = intfToCheck.getInterfaces();
    for (int i = 0; i < intfs.length; i++) {
        Class intf = intfs[i];
        if (isImplementedRemoteServiceInterfaceRecursive(intfName, intf)) {
            return true;
        }
    }

    return false;
}

From source file:com.link_intersystems.lang.reflect.Class2.java

private Type findBoundTypeInInterfaces(Class<?> typeClass, TypeVariable<?> typeVariable) {
    Type boundType = null;/*  w w  w .  ja  v a  2 s  .com*/

    Class<?>[] interfaces = typeClass.getInterfaces();
    boundType = doGetBoundType(typeVariable, interfaces);

    return boundType;
}

From source file:org.glowroot.agent.weaving.ClassAnalyzer.java

private static MatchedMixinTypes getMatchedMixinTypes(List<MixinType> mixinTypes, String className,
        @Nullable Class<?> classBeingRedefined, List<AnalyzedClass> superAnalyzedHierarchy,
        List<AnalyzedClass> interfaceAnalyzedHierarchy) {
    Set<MixinType> matchedMixinTypes = Sets.newHashSet();
    for (MixinType mixinType : mixinTypes) {
        // currently only exact matching is supported
        if (mixinType.targets().contains(className)) {
            matchedMixinTypes.add(mixinType);
        }// w w w  . j a  v a2 s. c o m
    }
    for (AnalyzedClass interfaceAnalyzedClass : interfaceAnalyzedHierarchy) {
        matchedMixinTypes.addAll(interfaceAnalyzedClass.mixinTypes());
    }
    for (AnalyzedClass superAnalyzedClass : superAnalyzedHierarchy) {
        matchedMixinTypes.addAll(superAnalyzedClass.nonReweavableMixinTypes());
    }
    // remove mixins that were already implemented in a super class
    for (AnalyzedClass superAnalyzedClass : superAnalyzedHierarchy) {
        if (!superAnalyzedClass.isInterface()) {
            matchedMixinTypes.removeAll(superAnalyzedClass.mixinTypes());
        }
    }
    List<MixinType> nonReweavableMatchedMixinTypes = Lists.newArrayList();
    if (classBeingRedefined != null) {
        Set<String> interfaceNames = Sets.newHashSet();
        for (Class<?> iface : classBeingRedefined.getInterfaces()) {
            interfaceNames.add(iface.getName());
        }
        for (Iterator<MixinType> i = matchedMixinTypes.iterator(); i.hasNext();) {
            MixinType matchedMixinType = i.next();
            for (Type mixinInterface : matchedMixinType.interfaces()) {
                if (!interfaceNames.contains(mixinInterface.getClassName())) {
                    // re-weaving would fail with "attempted to change superclass or interfaces"
                    logger.debug("not reweaving {} because cannot add mixin type: {}",
                            ClassNames.fromInternalName(className), mixinInterface.getClassName());
                    nonReweavableMatchedMixinTypes.add(matchedMixinType);
                    i.remove();
                    break;
                }
            }
        }
    }
    return ImmutableMatchedMixinTypes.builder().addAllReweavable(matchedMixinTypes)
            .addAllNonReweavable(nonReweavableMatchedMixinTypes).build();
}

From source file:com.sun.faces.application.ApplicationImpl.java

protected Converter createConverterBasedOnClass(Class targetClass) {

    Converter returnVal = (Converter) newThing(targetClass, converterTypeMap);
    if (returnVal != null) {
        if (log.isTraceEnabled()) {
            log.trace("Created converter of type " + returnVal.getClass().getName());
        }/*  ww w  .  j  ava2 s  . c  om*/
        return returnVal;
    }

    //Search for converters registered to interfaces implemented by
    //targetClass
    Class[] interfaces = targetClass.getInterfaces();
    if (interfaces != null) {
        for (int i = 0; i < interfaces.length; i++) {
            returnVal = createConverterBasedOnClass(interfaces[i]);
            if (returnVal != null) {
                if (log.isTraceEnabled()) {
                    log.trace("Created converter of type " + returnVal.getClass().getName());
                }
                return returnVal;
            }
        }
    }

    //Search for converters registered to superclasses of targetClass
    Class superclass = targetClass.getSuperclass();
    if (superclass != null) {
        returnVal = createConverterBasedOnClass(superclass);
        if (returnVal != null) {
            if (log.isTraceEnabled()) {
                log.trace("Created converter of type " + returnVal.getClass().getName());
            }
            return returnVal;
        }
    }
    return returnVal;
}

From source file:org.nuunframework.spring.SpringModule.java

@SuppressWarnings("unchecked")
private void bindFromApplicationContext() {
    boolean debugEnabled = logger.isDebugEnabled();

    ConfigurableListableBeanFactory currentBeanFactory = this.beanFactory;
    do {//from   w  w w. j  a  va  2 s.  com
        for (String beanName : currentBeanFactory.getBeanDefinitionNames()) {
            BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName);
            if (!beanDefinition.isAbstract()) {
                Class<?> beanClass = classFromString(beanDefinition.getBeanClassName());
                if (beanClass == null) {
                    logger.warn("Cannot bind spring bean " + beanName + " because its class "
                            + beanDefinition.getBeanClassName() + " failed to load");
                    return;
                }

                SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName,
                        currentBeanFactory);

                // Adding bean with its base type
                addBeanDefinition(beanClass, springBeanDefinition);

                // Adding bean with its parent type if enabled
                Class<?> parentClass = beanClass.getSuperclass();
                if (parentClass != null && parentClass != Object.class)
                    addBeanDefinition(parentClass, springBeanDefinition);

                // Adding bean with its immediate interfaces if enabled
                for (Class<?> i : beanClass.getInterfaces())
                    addBeanDefinition(i, springBeanDefinition);
            }
        }
        BeanFactory factory = currentBeanFactory.getParentBeanFactory();
        if (factory != null) {
            if (factory instanceof ConfigurableListableBeanFactory)
                currentBeanFactory = (ConfigurableListableBeanFactory) factory;
            else {
                logger.info(
                        "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory");
                currentBeanFactory = null;
            }
        } else
            currentBeanFactory = null;
    } while (currentBeanFactory != null);

    for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : this.beanDefinitions.entrySet()) {
        Class<?> type = entry.getKey();
        Map<String, SpringBeanDefinition> definitions = entry.getValue();

        // Bind by name for each bean of this type and by type if there is no ambiguity
        for (SpringBeanDefinition candidate : definitions.values()) {
            if (debugEnabled)
                logger.info("Binding spring bean " + candidate.getName() + " by name and type "
                        + type.getCanonicalName());

            bind(type).annotatedWith(Names.named(candidate.getName())).toProvider(
                    new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory()));
        }
    }
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java

private static void addXmlSeeAlsoPackages(Class clz, MarshalServiceRuntimeDescription msrd,
        TreeSet<String> set) {
    if (log.isDebugEnabled()) {
        log.debug("start addXmlSeeAlsoPackages for " + clz);
    }//from   w  w w  .ja  va  2s. c  o  m
    if (clz != null) {
        AnnotationDesc aDesc = msrd.getAnnotationDesc(clz);
        if (aDesc != null) {
            Class[] seeAlso = aDesc.getXmlSeeAlsoClasses();
            if (seeAlso != null) {
                for (int i = 0; i < seeAlso.length; i++) {
                    String pkg = (seeAlso[i] == null) ? null
                            : (seeAlso[i].getPackage() == null) ? "" : seeAlso[i].getPackage().getName();
                    if (pkg != null) {
                        if (log.isDebugEnabled()) {
                            log.debug(" adding package = " + pkg);
                        }
                        set.add(pkg);
                        set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace)
                        set.add("[" + seeAlso[i].getCanonicalName() + "]"); // Indicates a actual class reference
                    }
                }
            }
        }

        Class[] interfaces = clz.getInterfaces();
        if (interfaces != null) {
            for (int i = 0; i < interfaces.length; i++) {
                addXmlSeeAlsoPackages(interfaces[i], msrd, set);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("end addXmlSeeAlsoPackages for " + clz);
    }
}

From source file:io.nuun.plugin.spring.SpringModule.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void bindFromApplicationContext() {
    boolean debugEnabled = logger.isDebugEnabled();

    ConfigurableListableBeanFactory currentBeanFactory = beanFactory;
    do {//from w  ww.  j  a v a  2s .co  m
        for (String beanName : currentBeanFactory.getBeanDefinitionNames()) {
            BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName);
            if (!beanDefinition.isAbstract()) {
                Class<?> beanClass = classFromString(beanDefinition.getBeanClassName());
                if (beanClass == null) {
                    logger.warn("Cannot bind spring bean " + beanName + " because its class "
                            + beanDefinition.getBeanClassName() + " failed to load");
                    return;
                }

                SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName,
                        currentBeanFactory);

                // Adding bean with its base type
                addBeanDefinition(beanClass, springBeanDefinition);

                // Adding bean with its parent type if enabled
                Class<?> parentClass = beanClass.getSuperclass();
                if (parentClass != null && parentClass != Object.class) {
                    addBeanDefinition(parentClass, springBeanDefinition);
                }

                // Adding bean with its immediate interfaces if enabled
                for (Class<?> i : beanClass.getInterfaces()) {
                    addBeanDefinition(i, springBeanDefinition);
                }
            }
        }
        BeanFactory factory = currentBeanFactory.getParentBeanFactory();
        if (factory != null) {
            if (factory instanceof ConfigurableListableBeanFactory) {
                currentBeanFactory = (ConfigurableListableBeanFactory) factory;
            } else {
                logger.info(
                        "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory");
                currentBeanFactory = null;
            }
        } else {
            currentBeanFactory = null;
        }
    } while (currentBeanFactory != null);

    for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : beanDefinitions.entrySet()) {
        Class<?> type = entry.getKey();
        Map<String, SpringBeanDefinition> definitions = entry.getValue();

        // Bind by name for each bean of this type and by type if there is no ambiguity
        for (SpringBeanDefinition candidate : definitions.values()) {
            if (debugEnabled) {
                logger.info("Binding spring bean " + candidate.getName() + " by name and type "
                        + type.getCanonicalName());
            }

            bind(type).annotatedWith(Names.named(candidate.getName())).toProvider(
                    new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory()));
        }
    }
}