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:org.broadinstitute.gatk.tools.walkers.help.WalkerDocumentationHandler.java

/**
 * Utility function that determines the annotation type for an instance of class c.
 *
 * @param myClass the class to query for the interfaces
 * @param annotInfo an empty HashSet in which to collect the info
 * @return a hash set of the annotation types, otherwise an empty set
 *//*ww w.  j av a  2 s.  co  m*/
private HashSet<String> getAnnotInfo(Class myClass, HashSet<String> annotInfo) {
    //
    // Retrieve interfaces
    Class[] implementedInterfaces = myClass.getInterfaces();
    for (Class intfClass : implementedInterfaces) {
        if (intfClass.getName().contains("Annotation")) {
            annotInfo.add(intfClass.getSimpleName());
        }
    }
    // Look up superclasses recursively
    final Class mySuperClass = myClass.getSuperclass();
    if (mySuperClass.getSimpleName().equals("Object")) {
        return annotInfo;
    }
    return getAnnotInfo(mySuperClass, annotInfo);
}

From source file:io.gravitee.management.repository.plugins.RepositoryPluginHandler.java

private void registerRepositoryDefinitions(Repository repository, ApplicationContext repoApplicationContext) {
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ((ConfigurableApplicationContext) applicationContext)
            .getBeanFactory();//from   w  w w .jav a2 s  .  co  m

    String[] beanNames = repoApplicationContext.getBeanDefinitionNames();
    for (String beanName : beanNames) {
        Object repositoryClassInstance = repoApplicationContext.getBean(beanName);
        Class<?> repositoryObjectClass = repositoryClassInstance.getClass();
        if ((beanName.endsWith("Repository")
                || (beanName.endsWith("Manager") && !beanName.endsWith("TransactionManager")))
                && !repository.getClass().equals(repositoryClassInstance.getClass())) {
            if (repositoryObjectClass.getInterfaces().length > 0) {
                Class<?> repositoryItfClass = repositoryObjectClass.getInterfaces()[0];
                LOGGER.debug("Set proxy target for {} [{}]", beanName, repositoryItfClass);
                try {
                    Object proxyRepository = beanFactory.getBean(repositoryItfClass);
                    if (proxyRepository instanceof AbstractProxy) {
                        AbstractProxy proxy = (AbstractProxy) proxyRepository;
                        proxy.setTarget(repositoryClassInstance);
                    }
                } catch (NoSuchBeanDefinitionException nsbde) {
                    LOGGER.debug("Unable to proxify {} [{}]", beanName, repositoryItfClass);
                }
            }
        } else if (beanName.endsWith("TransactionManager")) {
            beanFactory.registerSingleton(beanName, repositoryClassInstance);
        }
    }
}

From source file:org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel.java

protected Method extractMethodInheritanceChain(Class type, Method m) {
    if (m == null || Modifier.isPublic(type.getModifiers())) {
        return m;
    }/*from  w w  w. java 2s.  co  m*/
    Class[] iFaces = type.getInterfaces();
    Method mp;
    for (Class<?> iFace : iFaces) {
        mp = getClassMethod(iFace, m);
        if (mp != null) {
            return mp;
        }
    }
    return getClassMethod(type.getSuperclass(), m);
}

From source file:plugins.ApiHelpInventory.java

private boolean hasAnnotation(Class<?> type, Class<? extends Annotation> annotation) {

    // null cannot have annotations
    if (type == null) {
        return false;
    }/*  w  w  w .j  a  va2 s  . c  o  m*/

    // class annotation
    if (type.isAnnotationPresent(annotation)) {
        return true;
    }

    // annotation on interface
    for (Class<?> interfaceType : type.getInterfaces()) {
        if (hasAnnotation(interfaceType, annotation))
            return true;
    }

    // annotation on superclass
    return hasAnnotation(type.getSuperclass(), annotation);

}

From source file:com.eviware.soapui.plugins.LoaderBase.java

protected void unregisterListeners(List<Class<? extends SoapUIListener>> listeners) {
    for (Class<? extends SoapUIListener> listenerClass : listeners) {
        for (Class<?> implementedInterface : listenerClass.getInterfaces()) {
            if (SoapUIListener.class.isAssignableFrom(implementedInterface)) {
                listenerRegistry.removeListener(implementedInterface, listenerClass);
                listenerRegistry.removeSingletonListener(implementedInterface, listenerClass);
            }//from   w  w w  .j a  v  a 2 s .  c om
        }
    }
}

From source file:com.hubspot.utils.circuitbreaker.CircuitBreakerWrapper.java

/**
 * Wraps the supplied object toWrap in a CircuitBreaker conforming to the supplied CircuitBreakerPolicy.
 *///  ww w .j a  va2  s  . com
public <T, W extends T> T wrap(W toWrap, Class<T> interfaceToProxy, CircuitBreakerPolicy policy)
        throws CircuitBreakerWrappingException {
    sanityCheck(toWrap, interfaceToProxy, policy);

    // walk the chain of interfaces implemented by T and check for their blacklisted methods
    Stack<Class<?>> implementedInterfaces = new Stack<Class<?>>();
    implementedInterfaces.addAll(Arrays.asList(interfaceToProxy.getInterfaces()));
    implementedInterfaces.add(interfaceToProxy);

    Map<Method, Class[]> blacklist = new HashMap();
    while (!implementedInterfaces.isEmpty()) {
        Class<?> implementedInterface = implementedInterfaces.pop();

        for (Method m : implementedInterface.getDeclaredMethods()) {
            // check that the blacklisted method throws CircuitBreakerException
            if (m.isAnnotationPresent(CircuitBreakerExceptionBlacklist.class)) {
                if (!ArrayUtils.contains(m.getExceptionTypes(), CircuitBreakerException.class)) {
                    throw new CircuitBreakerWrappingException(
                            "Wrapped methods must throw CircuitBreakerException");
                }

                CircuitBreakerExceptionBlacklist a = (CircuitBreakerExceptionBlacklist) m
                        .getAnnotation(CircuitBreakerExceptionBlacklist.class);
                blacklist.put(m, a.blacklist());
            }
        }

        implementedInterfaces.addAll(Arrays.asList(implementedInterface.getInterfaces()));
    }

    Class<?>[] interfaces = new Class<?>[] { interfaceToProxy };
    InvocationHandler handler = new CircuitBreakerInvocationHandler(toWrap, blacklist, policy);
    T newProxyInstance = (T) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, handler);
    return newProxyInstance;
}

From source file:fedora.server.utilities.rebuild.Rebuild.java

public Rebuild(Rebuilder rebuilder, Map<String, String> options, ServerConfiguration serverConfig)
        throws Exception {
    // set these here so DOTranslationUtility doesn't try to get a Server
    // instance/*from  www.j  a v a2s  .  c  o m*/
    System.setProperty("fedoraServerHost", serverConfig.getParameter("fedoraServerHost").getValue());
    System.setProperty("fedoraServerPort", serverConfig.getParameter("fedoraServerPort").getValue());
    System.setProperty("fedoraAppServerContext",
            serverConfig.getParameter("fedoraAppServerContext").getValue());
    boolean serverIsRunning = ServerUtility.pingServer("http", null, null);
    if (serverIsRunning && rebuilder.shouldStopServer()) {
        throw new Exception("The Fedora server appears to be running."
                + "  It must be stopped before the rebuilder can run.");
    }
    if (options != null) {
        System.err.println();
        System.err.println("Rebuilding...");
        try {
            // ensure rebuilds are possible before trying anything,
            // as rebuilder.start() may be destructive!
            final String llPackage = "fedora.server.storage.lowlevel";
            String llstoreInterface = llPackage + ".ILowlevelStorage";
            String listableInterface = llPackage + ".IListable";
            ModuleConfiguration mcfg = serverConfig.getModuleConfiguration(llstoreInterface);
            Class<?> clazz = Class.forName(mcfg.getClassName());
            boolean isListable = false;
            for (Class<?> iface : clazz.getInterfaces()) {
                if (iface.getName().equals(listableInterface)) {
                    isListable = true;
                }
            }
            if (!isListable) {
                throw new Exception("ERROR: Rebuilds are not supported" + " by " + clazz.getName()
                        + " because it does not implement the" + " fedora.server.storage.lowlevel.IListable"
                        + " interface.");
            }

            // looks good, so init the rebuilder
            rebuilder.start(options);

            // add each object in llstore
            ILowlevelStorage llstore = (ILowlevelStorage) getServer().getModule(llstoreInterface);
            Iterator<String> pids = ((IListable) llstore).listObjects();
            int total = 0;
            int errors = 0;
            while (pids.hasNext()) {
                total++;
                String pid = pids.next();
                System.out.println("Adding object #" + total + ": " + pid);
                if (!addObject(rebuilder, llstore, pid)) {
                    errors++;
                }
            }
            if (errors == 0) {
                System.out.println("SUCCESS: " + total + " objects rebuilt.");
            } else {
                System.out.println(
                        "WARNING: " + errors + " of " + total + " objects failed to rebuild due to errors.");
            }
        } finally {
            rebuilder.finish();
            if (server != null) {
                server.shutdown(null);
                server = null;
            }
        }
        System.err.print("Finished.");
        System.err.println();
    }
}

From source file:org.glassfish.tyrus.tests.qa.tools.GlassFishToolkit.java

private boolean isBlackListed(File clazz) throws ClassNotFoundException, MalformedURLException {
    //logger.log(Level.FINE, "File? {0}", clazzCanonicalName);

    Class tryMe = getClazzForFile(clazz);

    logger.log(Level.FINE, "File? {0}", tryMe.getCanonicalName());

    logger.log(Level.FINE, "Interfaces:{0}", tryMe.getInterfaces());
    if (Arrays.asList(tryMe.getInterfaces()).contains((ServerApplicationConfig.class))) {
        logger.log(Level.FINE, "ServerApplicationConfig : {0}", tryMe.getCanonicalName());
        return true;
    }/*from  www.ja v a2 s . co  m*/
    if (tryMe.isAnnotationPresent(ServerEndpoint.class)) {
        logger.log(Level.FINE, "Annotated ServerEndpoint: {0}", tryMe.getCanonicalName());
        return true;
    }

    if (tryMe.isAnnotationPresent(ClientEndpoint.class)) {
        logger.log(Level.FINE, "Annotated ClientEndpoint: {0}", tryMe.getCanonicalName());
        return true;
    }
    //Endpoint itself is not blacklisted
    // TYRUS-150
    //if (Endpoint.class.isAssignableFrom(tryMe)) {
    //    logger.log(Level.INFO, "Programmatic Endpoint: {0}", tryMe.getCanonicalName());
    //    return true;
    //}

    return false;
}

From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java

/**
 * Perform the given callback operation on all matching methods of the given
 * class and superclasses (or given interface and super-interfaces).
 * <p>The same named method occurring on subclass and superclass will appear
 * twice, unless excluded by the specified {@link MethodFilter}.
 * @param clazz class to start looking at
 * @param mc the callback to invoke for each method
 * @param mf the filter that determines the methods to apply the callback to
 *///w ww  .  j  av  a2 s  .c  o m
public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf)
        throws IllegalArgumentException {

    // Keep backing up the inheritance hierarchy.
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
        if (mf != null && !mf.matches(method)) {
            continue;
        }
        try {
            mc.doWith(method);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException(
                    "Shouldn't be illegal to access method '" + method.getName() + "': " + ex);
        }
    }
    if (clazz.getSuperclass() != null) {
        doWithMethods(clazz.getSuperclass(), mc, mf);
    } else if (clazz.isInterface()) {
        for (Class<?> superIfc : clazz.getInterfaces()) {
            doWithMethods(superIfc, mc, mf);
        }
    }
}

From source file:org.cloudata.core.common.testhelper.FaultManager.java

private HashMap<String, Fault> findFaultMap(Class<?> c) {
    HashMap<String, Fault> ret = classFaultMap.get(c);

    if (ret == null) {
        Class<?>[] interfaces = c.getInterfaces();
        for (Class<?> ci : interfaces) {
            if ((ret = findFaultMap(ci)) != null) {
                return ret;
            }/*w w  w  .ja  v a2 s.c  o m*/
        }

        return null;
    }

    return ret;
}