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.gatf.executor.core.AcceptanceTestContext.java

@SuppressWarnings("rawtypes")
private List<Map<String, String>> getProviderData(GatfTestDataProvider provider, TestCase testCase) {

    TestDataSource dataSource = dataSourceMap.get(provider.getDataSourceName());

    TestDataProvider testDataProvider = null;
    List<Map<String, String>> testData = null;
    if (provider.getProviderClass() != null) {
        if (FileTestDataProvider.class.getCanonicalName().equals(provider.getProviderClass().trim())) {
            testDataProvider = new FileTestDataProvider();
        } else if (InlineValueTestDataProvider.class.getCanonicalName()
                .equals(provider.getProviderClass().trim())) {
            testDataProvider = new InlineValueTestDataProvider();
        } else if (RandomValueTestDataProvider.class.getCanonicalName()
                .equals(provider.getProviderClass().trim())) {
            testDataProvider = new RandomValueTestDataProvider();
        } else {//  ww  w  .  j  a  va  2 s .  c o  m
            try {
                Class claz = loadCustomClass(provider.getProviderClass());
                Class[] classes = claz.getInterfaces();
                boolean validProvider = false;
                if (classes != null) {
                    for (Class class1 : classes) {
                        if (class1.equals(TestDataProvider.class)) {
                            validProvider = true;
                            break;
                        }
                    }
                }
                Assert.assertTrue("Provider class should implement the TestDataProvider class", validProvider);
                Object providerInstance = claz.newInstance();
                testDataProvider = (TestDataProvider) providerInstance;
            } catch (Throwable e) {
                throw new AssertionError(e);
            }
        }
    } else {
        testDataProvider = dataSource;
    }

    //Live provider queries can have templatized parameter names
    if (provider.isLive() && provider.getQueryStr() != null) {
        String oQs = provider.getQueryStr();
        provider = new GatfTestDataProvider(provider);
        if (testCase != null) {
            provider.setQueryStr(
                    getWorkflowContextHandler().evaluateTemplate(testCase, provider.getQueryStr(), this));
            if (provider.getQueryStr() == null || provider.getQueryStr().isEmpty()) {
                provider.setQueryStr(oQs);
            }
        }
    }

    testData = testDataProvider.provide(provider, this);
    return testData;
}

From source file:com.gatf.executor.core.AcceptanceTestContext.java

@SuppressWarnings("rawtypes")
private void handleDataSources(List<GatfTestDataSource> dataSourceList, boolean forProfiling) {
    for (GatfTestDataSource dataSource : dataSourceList) {
        Assert.assertNotNull("DataSource name is not defined", dataSource.getDataSourceName());
        Assert.assertNotNull("DataSource class is not defined", dataSource.getDataSourceClass());
        Assert.assertNotNull("DataSource args not defined", dataSource.getArgs());
        Assert.assertTrue("DataSource args empty", dataSource.getArgs().length > 0);
        Assert.assertNull("Duplicate DataSource name found", dataSourceMap.get(dataSource.getDataSourceName()));

        TestDataSource testDataSource = null;
        if (SQLDatabaseTestDataSource.class.getCanonicalName().equals(dataSource.getDataSourceClass())) {
            testDataSource = new SQLDatabaseTestDataSource();
        } else if (MongoDBTestDataSource.class.getCanonicalName().equals(dataSource.getDataSourceClass())) {
            testDataSource = new MongoDBTestDataSource();
        } else {/*from ww  w.j a  va2s.c  o  m*/
            try {
                Class claz = loadCustomClass(dataSource.getDataSourceClass());
                Class[] classes = claz.getInterfaces();
                boolean validProvider = false;
                if (classes != null) {
                    for (Class class1 : classes) {
                        if (class1.equals(TestDataSource.class)) {
                            validProvider = true;
                            break;
                        }
                    }
                }
                Assert.assertTrue("DataSource class should extend the TestDataSource class", validProvider);
                Object providerInstance = claz.newInstance();
                testDataSource = (TestDataSource) providerInstance;
            } catch (Throwable e) {
                throw new AssertionError(e);
            }
        }

        testDataSource.setClassName(dataSource.getDataSourceClass());
        testDataSource.setArgs(dataSource.getArgs());
        testDataSource.setContext(this);
        testDataSource.setDataSourceName(dataSource.getDataSourceName());
        if (dataSource.getPoolSize() > 1) {
            testDataSource.setPoolSize(dataSource.getPoolSize());
        }

        if (forProfiling) {
            testDataSource.setPoolSize(1);
            testDataSource.init();
            dataSourceMapForProfiling.put(dataSource.getDataSourceName(), testDataSource);
        } else {
            testDataSource.init();
            dataSourceMap.put(dataSource.getDataSourceName(), testDataSource);
        }
    }
}

From source file:com.gatf.executor.core.AcceptanceTestContext.java

@SuppressWarnings("rawtypes")
private void handleHooks(List<GatfTestDataSourceHook> dataSourceHooks) {
    for (GatfTestDataSourceHook dataSourceHook : dataSourceHooks) {
        Assert.assertNotNull("DataSourceHook name is not defined", dataSourceHook.getHookName());
        Assert.assertNotNull("DataSourceHook query string is not defined", dataSourceHook.getQueryStrs());
        Assert.assertNull("Duplicate DataSourceHook name found",
                dataSourceHooksMap.get(dataSourceHook.getHookName()));

        TestDataSource dataSource = null;
        if (dataSourceHook.getDataSourceName() != null && dataSourceHook.getHookClass() == null) {
            dataSource = dataSourceMap.get(dataSourceHook.getDataSourceName());
            Assert.assertNotNull("No DataSource found", dataSource);
        } else if (dataSourceHook.getDataSourceName() != null && dataSourceHook.getHookClass() != null) {
            Assert.assertNotNull("Specify either hookClass or dataSourceName", null);
        } else if (dataSourceHook.getDataSourceName() == null && dataSourceHook.getHookClass() == null) {
            Assert.assertNotNull("Specify any one of hookClass or dataSourceName", null);
        }/* www .ja  va  2 s. c o m*/

        dataSourceHooksMap.put(dataSourceHook.getHookName(), dataSourceHook);

        TestDataHook testDataHook = null;
        if (dataSourceHook.getHookClass() != null) {
            try {
                Class claz = loadCustomClass(dataSourceHook.getHookClass());
                Class[] classes = claz.getInterfaces();
                boolean validProvider = false;
                if (classes != null) {
                    for (Class class1 : classes) {
                        if (class1.equals(TestDataProvider.class)) {
                            validProvider = true;
                            break;
                        }
                    }
                }
                Assert.assertTrue("Hook class should implement the TestDataHook class", validProvider);
                Object providerInstance = claz.newInstance();
                testDataHook = (TestDataHook) providerInstance;
            } catch (Throwable e) {
                throw new AssertionError(e);
            }
        } else {
            testDataHook = dataSource;
        }

        if (dataSourceHook.isExecuteOnStart()) {
            for (String query : dataSourceHook.getQueryStrs()) {
                boolean flag = false;
                try {
                    flag = testDataHook.execute(query);
                } catch (Throwable e) {
                }
                if (!flag) {
                    logger.severe("Startup DataSourceHook execution for " + dataSourceHook.getHookName()
                            + " failed, queryString = " + query);
                }
            }
        }
    }
}

From source file:cn.webwheel.DefaultMain.java

private void getActions(List<Action> list, Set<Class> set, Class cls, Method method) {
    if (cls == null || !set.add(cls))
        return;//  ww w  .  ja  v  a 2  s  .c  om
    for (Method m : cls.getDeclaredMethods()) {
        if (!m.getName().equals(method.getName()))
            continue;
        if (!Arrays.equals(m.getParameterTypes(), method.getParameterTypes()))
            continue;
        Action action = m.getAnnotation(Action.class);
        if (action != null) {
            list.add(action);
        }
        break;
    }
    for (Class i : cls.getInterfaces()) {
        getActions(list, set, i, method);
    }
    getActions(list, set, cls.getSuperclass(), method);
}

From source file:org.evosuite.setup.TestClusterGenerator.java

/**
 * Get the set of methods defined in this class and its superclasses
 * //ww w  .ja  va 2  s.c  o  m
 * @param clazz
 * @return
 */
public static Set<Method> getMethods(Class<?> clazz) {

    Map<String, Method> helper = new TreeMap<String, Method>();

    if (clazz.getSuperclass() != null) {
        for (Method m : getMethods(clazz.getSuperclass())) {
            helper.put(m.getName() + org.objectweb.asm.Type.getMethodDescriptor(m), m);
        }
    }
    for (Class<?> in : clazz.getInterfaces()) {
        for (Method m : getMethods(in)) {
            helper.put(m.getName() + org.objectweb.asm.Type.getMethodDescriptor(m), m);
        }
    }

    try {
        for (Method m : clazz.getDeclaredMethods()) {
            helper.put(m.getName() + org.objectweb.asm.Type.getMethodDescriptor(m), m);
        }
    } catch (NoClassDefFoundError e) {
        // TODO: What shall we do?
        logger.info("Error while trying to load methods of class {}: {}", clazz.getName(), e);
    }

    Set<Method> methods = new LinkedHashSet<Method>();
    methods.addAll(helper.values());
    return methods;
}

From source file:com.cuubez.visualizer.resource.ResourceMetaDataScanner.java

private boolean scanPath(Class<?> clazz, RootResource rootResource) {

    Path path = clazz.getAnnotation(Path.class);

    if (path != null) {
        rootResource.setPath(normalizePath(path.value()));
        return true;
    }//from  w w  w  . j a  va 2  s.c  om

    if (!clazz.equals(Object.class)) {

        Class<?> superClass = clazz.getSuperclass();
        Path superClassPath = superClass.getAnnotation(Path.class);

        if (superClassPath != null) {
            rootResource.setPath(normalizePath(superClassPath.value()));
            return true;
        }

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

        for (Class<?> intface : interfaces) {

            Path interfacePath = intface.getAnnotation(Path.class);

            if (interfacePath != null) {

                rootResource.setPath(normalizePath(interfacePath.value()));
                return true;

            }
        }

    }

    return false;
}

From source file:com.tmind.framework.pub.utils.MethodUtils.java

public static Method findMethod(Class start, String methodName, int argCount) {
    // For overridden methods we need to find the most derived version.
    // So we start with the given class and walk up the superclass chain.
    for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
        Method methods[] = getPublicDeclaredMethods(cl);
        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            if (method == null) {
                continue;
            }/*from www .j a  v a2s.co m*/
            // skip static methods.
            int mods = method.getModifiers();
            if (Modifier.isStatic(mods)) {
                continue;
            }
            if (method.getName().equals(methodName) && method.getParameterTypes().length == argCount) {
                return method;
            }
        }
    }

    // Now check any inherited interfaces.  This is necessary both when
    // the argument class is itself an interface, and when the argument
    // class is an abstract class.
    Class ifcs[] = start.getInterfaces();
    for (int i = 0; i < ifcs.length; i++) {
        Method m = findMethod(ifcs[i], methodName, argCount);
        if (m != null) {
            return m;
        }
    }

    return null;
}

From source file:org.jspresso.framework.util.bean.PropertyHelper.java

private static PropertyDescriptor getPropertyDescriptorNoException(Class<?> beanClass, String property) {
    PropertyDescriptor descriptorToReturn = null;
    int nestedDotIndex = property.indexOf(IAccessor.NESTED_DELIM);
    if (nestedDotIndex > 0) {
        PropertyDescriptor rootDescriptor = getPropertyDescriptorNoException(beanClass,
                property.substring(0, nestedDotIndex));
        if (rootDescriptor != null) {
            descriptorToReturn = getPropertyDescriptorNoException(rootDescriptor.getPropertyType(),
                    property.substring(nestedDotIndex + 1));
        }/*from w ww .  j av a  2  s.c  o  m*/
    } else {
        PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(beanClass);
        for (PropertyDescriptor descriptor : descriptors) {
            if (property.substring(0, 1).equalsIgnoreCase(descriptor.getName().substring(0, 1))
                    && property.substring(1).equals(descriptor.getName().substring(1))) {
                // 1st letter might be uppercase in descriptor and lowercase in
                // property when property name is like 'tEst'.
                descriptorToReturn = descriptor;
            }
        }
    }
    if (descriptorToReturn == null || descriptorToReturn.getWriteMethod() == null) {
        // If we reach this point, no property with the given name has been found.
        // or the found descriptor is read-only.
        // If beanClass is indeed an interface, we must also deal with all its
        // super-interfaces.
        List<Class<?>> superTypes = new ArrayList<>();
        if (beanClass.getSuperclass() != null && beanClass.getSuperclass() != Object.class) {
            superTypes.add(beanClass.getSuperclass());
        }
        Collections.addAll(superTypes, beanClass.getInterfaces());
        for (Class<?> superType : superTypes) {
            PropertyDescriptor descriptor;
            descriptor = getPropertyDescriptorNoException(superType, property);
            if (descriptor != null) {
                if (descriptorToReturn != null) {
                    try {
                        descriptorToReturn.setWriteMethod(descriptor.getWriteMethod());
                    } catch (IntrospectionException ex) {
                        throw new NestedRuntimeException(ex);
                    }
                } else {
                    descriptorToReturn = descriptor;
                }
            }
        }
    }
    return descriptorToReturn;
}

From source file:org.rhq.enterprise.server.util.CriteriaQueryGenerator.java

private boolean isAList(Field field) {
    Class<?> fieldType = field.getType();

    if (List.class.isAssignableFrom(fieldType)) {
        return true;
    }//  w w  w .j  av  a2s. c o m

    for (Class<?> declaredInterface : fieldType.getInterfaces()) {
        if (List.class.isAssignableFrom(declaredInterface)) {
            return true;
        }
    }
    return false;
}

From source file:org.ajax4jsf.builder.config.BuilderConfig.java

private Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> clazz) {

    if (clazz.equals(Object.class)) {
        return Collections.emptyMap();
    }/*from w  ww. j a v a2 s. c om*/

    Map<String, PropertyDescriptor> m = new TreeMap<String, PropertyDescriptor>();

    Class<?> superclass = clazz.getSuperclass();
    if (superclass != null) {
        m.putAll(getPropertyDescriptors(superclass));
    }

    Class<?>[] interfaces = clazz.getInterfaces();
    if (interfaces != null) {
        for (Class<?> intrfc : interfaces) {
            m.putAll(getPropertyDescriptors(intrfc));
        }
    }

    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);

    for (PropertyDescriptor propertyDescriptor : descriptors) {
        m.put(propertyDescriptor.getName(), propertyDescriptor);
    }

    return m;
}