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.liferay.arkadiko.bean.AKBeanDefinition.java

protected Class<?>[] getInterfaces(String className) throws ClassNotFoundException {

    Class<?> interfaceClass = Class.forName(className);

    if (!interfaceClass.isInterface()) {
        throw new IllegalArgumentException(className + " is not an interface");
    }//from w  w w.  jav  a2s. c  o  m

    return new Class<?>[] { interfaceClass };
}

From source file:com.ngandroid.lib.NgAndroid.java

public <T> T buildScope(Class<T> clss) {
    T instance;//from w  ww  .  j  a v a2  s. c o  m
    try {
        instance = clss.newInstance();
        Field[] fields = clss.getDeclaredFields();
        for (Field f : fields) {
            f.setAccessible(true);
            Class type = f.getType();
            if (type.isInterface() && !f.isAnnotationPresent(Ignore.class)) {
                f.set(instance, buildModel(type));
            }
        }
    } catch (InstantiationException | IllegalAccessException e) {
        // TODO
        throw new RuntimeException("Error instantiating scope.", e);
    }
    return instance;
}

From source file:com.cloudera.livy.client.common.TestHttpMessages.java

/**
 * Tests that all defined messages can be serialized and deserialized using Jackson.
 *//*  w  w w  .  j a v  a 2  s .co  m*/
@Test
public void testMessageSerialization() throws Exception {
    ObjectMapper mapper = new ObjectMapper();

    for (Class<?> msg : HttpMessages.class.getClasses()) {
        if (msg.isInterface()) {
            continue;
        }

        String name = msg.getSimpleName();

        Constructor c = msg.getConstructors()[0];
        Object[] params = new Object[c.getParameterTypes().length];
        Type[] genericTypes = c.getGenericParameterTypes();
        for (int i = 0; i < params.length; i++) {
            params[i] = dummyValue(c.getParameterTypes()[i], genericTypes[i]);
        }

        Object o1 = c.newInstance(params);
        byte[] serialized = mapper.writeValueAsBytes(o1);
        Object o2 = mapper.readValue(serialized, msg);

        assertNotNull("could not deserialize " + name, o2);
        for (Field f : msg.getFields()) {
            checkEquals(name, f, o1, o2);
        }
    }

}

From source file:org.javaan.bytecode.ReflectionClassContextBuilder.java

private Type createTypeFromClass(String className) {
    Type type = null;/*from ww w. j a  va  2s  .  c o m*/
    try {
        Class<?> clazz = Class.forName(className);
        if (clazz.isInterface()) {
            type = new Interface(className);
            Class<?>[] superInterfaces = clazz.getInterfaces();
            addInterface((Interface) type,
                    ClassUtils.convertClassesToClassNames(Arrays.asList(superInterfaces)));
            addMethods(type, clazz);
        } else {
            type = new Clazz(className);
            Class<?> superClass = clazz.getSuperclass();
            String superClassName = (superClass == null) ? null : superClass.getName();
            Class<?>[] implementedInterfaces = clazz.getInterfaces();
            addClass((Clazz) type, superClassName,
                    ClassUtils.convertClassesToClassNames(Arrays.asList(implementedInterfaces)));
            addMethods(type, clazz);
        }
    } catch (ClassNotFoundException e) {
        missingTypes.add(className);
        return null;
    }
    return type;
}

From source file:org.ff4j.aop.FeatureAutoProxy.java

/** {@inheritDoc} */
@Override/*from   w  w w. j  a  v  a2  s . c o  m*/
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName,
        TargetSource targetSource) {
    // Scan interface only once.
    if (!beanClass.isInterface() && beanClass.getInterfaces() != null) {
        // Get Interface
        for (Class<?> currentInterface : beanClass.getInterfaces()) {
            Object[] r = addAnnotedInterface(currentInterface);
            if (r != null) {
                return r;
            }
        }
    }
    return DO_NOT_PROXY;
}

From source file:com.payu.ratel.proxy.UnicastingInvocationHandler.java

public UnicastingInvocationHandler(FetchStrategy fetchStrategy, Class<?> serviceApi,
        ClientProxyGenerator clientProxyGenerator, TimeoutConfig timeout) {
    assert fetchStrategy != null;
    assert serviceApi.isInterface();
    assert clientProxyGenerator != null;
    this.fetchStrategy = fetchStrategy;
    this.serviceApi = serviceApi;
    this.clientProxyGenerator = clientProxyGenerator;
    this.timeout = timeout;
}

From source file:com.bstek.dorado.data.type.AbstractDataType.java

public void setMatchType(Class<?> matchType) {
    this.matchType = matchType;
    if (creationType == null && !matchType.isInterface() && !Modifier.isAbstract(matchType.getModifiers())) {
        creationType = matchType;/*w w w  .  ja  v  a 2s  . co  m*/
    }
}

From source file:com.payu.ratel.register.ServiceRegisterPostProcessor.java

private boolean isService(Object o, String beanName) {
    Class realBeanClazz = getRealBeanClass(o, beanName);

    return !realBeanClazz.isInterface() && realBeanClazz.isAnnotationPresent(Publish.class);
}

From source file:com.metaparadigm.jsonrpc.ReferenceSerializer.java

@Override
public boolean canSerialize(Class clazz, Class jsonClazz) {
    return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface()
            && (bridge.isReference(clazz) || bridge.isCallableReference(clazz))
            && (jsonClazz == null || jsonClazz == JSONObject.class));
}

From source file:com.joyveb.dbpimpl.cass.prepare.option.DefaultOption.java

protected void setType(Class<?> type) {
    if (type != null) {
        if (type.isInterface()
                && !(Map.class.isAssignableFrom(type) || Collection.class.isAssignableFrom(type))) {
            throw new IllegalArgumentException(
                    "given type [" + type.getName() + "] must be a class, Map or Collection");
        }/*w  w w.  jav a2 s .com*/
    }
    this.type = type;
}