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.hubspot.utils.circuitbreaker.CircuitBreakerWrapper.java

/**
 * Ensures that the object we're wrapping and it's base interface conform to our restrictions
 * @throws CircuitBreakerWrappingException
 *//*from   ww  w.  ja v a 2s.co  m*/
private <T, W extends T> void sanityCheck(W toWrap, Class<T> interfaceToProxy, CircuitBreakerPolicy policy)
        throws CircuitBreakerWrappingException {
    if (toWrap == null) {
        throw new CircuitBreakerWrappingException("Cannot wrap a null object");
    }
    if (interfaceToProxy == null) {
        throw new CircuitBreakerWrappingException("Cannot proxy a null interface");
    }
    if (!interfaceToProxy.isInterface()) {
        throw new CircuitBreakerWrappingException("interfaceToProxy must be an interface");
    }

    try {
        if (Proxy.isProxyClass(toWrap.getClass())
                && Proxy.getInvocationHandler(toWrap) instanceof CircuitBreakerInvocationHandler) {
            throw new CircuitBreakerWrappingException("Object is already wrapped in a circuit breaker.");
        }
    } catch (IllegalArgumentException ex) {
        // "this should never happen", but if it does, we'll log our own logic error
        // before throwing the bad wrap
        getLog().error("IllegalArgumentException when trying to check for previous wrap", ex);
        throw new CircuitBreakerWrappingException("Trouble detecting whether object was already proxied");
    }
}

From source file:com.datastax.hectorjpa.spring.ConsistencyLevelAspect.java

/**
 * Gets the number of steps required needed to turn the source class into
 * the destination class. This represents the number of steps in the object
 * hierarchy graph.//  ww w  .  j  a va2  s  . c o m
 * 
 * @param srcClass
 *            The source class
 * @param destClass
 *            The destination class
 * @return The cost of transforming an object
 */
private float getObjectTransformationCost(Class<?> srcClass, Class<?> destClass) {
    float cost = 0.0f;
    while (srcClass != null && !destClass.equals(srcClass)) {
        if (destClass.isInterface() && MethodUtils.isAssignmentCompatible(destClass, srcClass)) {
            // slight penalty for interface match.
            // we still want an exact match to override an interface match,
            // but
            // an interface match should override anything where we have to
            // get a
            // superclass.
            cost += 0.25f;
            break;
        }
        cost++;
        srcClass = srcClass.getSuperclass();
    }

    /*
     * If the destination class is null, we've travelled all the way up to
     * an Object match. We'll penalize this by adding 1.5 to the cost.
     */
    if (srcClass == null) {
        cost += 1.5f;
    }

    return cost;
}

From source file:org.resthub.rpc.AMQPHessianProxyFactory.java

/**
 * Set the interface implemented by the proxy.
 * @param serviceInterface the interface the proxy must implement
 * @throws IllegalArgumentException if serviceInterface is null or is not an interface type
 *///from   w w w. j  a v  a2  s .co  m
public void setServiceInterface(Class<?> serviceInterface) {
    if (null == serviceInterface || !serviceInterface.isInterface()) {
        throw new IllegalArgumentException("'serviceInterface' is null or is not an interface");
    }
    this.serviceInterface = serviceInterface;
}

From source file:net.ymate.platform.core.beans.impl.DefaultBeanFactory.java

public void init() throws Exception {
    if (this.__beanLoader == null) {
        if (this.__parentFactory != null) {
            this.__beanLoader = this.__parentFactory.getLoader();
        }/*from  ww  w. ja v  a  2  s  .  c o  m*/
        if (this.__beanLoader == null) {
            this.__beanLoader = new DefaultBeanLoader();
        }
    }
    if (!__packageNames.isEmpty())
        for (String _packageName : __packageNames) {
            List<Class<?>> _classes = this.__beanLoader.load(_packageName);
            for (Class<?> _class : _classes) {
                // ?????
                if (!_class.isAnnotation() && !_class.isEnum() && !_class.isInterface()) {
                    Annotation[] _annotations = _class.getAnnotations();
                    if (_annotations != null && _annotations.length > 0) {
                        for (Annotation _anno : _annotations) {
                            IBeanHandler _handler = __beanHandlerMap.get(_anno.annotationType());
                            if (_handler != null) {
                                Object _instance = _handler.handle(_class);
                                if (_instance != null) {
                                    if (_instance instanceof BeanMeta) {
                                        __addClass((BeanMeta) _instance);
                                    } else {
                                        __addClass(BeanMeta.create(_instance, _class));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
}

From source file:org.atemsource.atem.impl.pojo.ScannedPojoEntityTypeRepository.java

protected synchronized AbstractEntityType createEntityType(final Class clazz) {
    AbstractEntityType entityType;/*from   w w w . j av  a2s.  c o  m*/
    entityType = beanCreator.create(entityTypeClass);
    entityType.setEntityClass(clazz);
    entityType.setRepository(this);

    entityType.setAbstractType(clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()));
    entityType.setCode(clazz.getName());
    addEntityTypeToLookup(clazz, entityType);
    return entityType;
}

From source file:net.sf.json.util.DynaBeanToBeanMorpher.java

/**
 * DOCUMENT ME!//from  w  ww. j ava  2s . c  o m
 *
 * @param clazz DOCUMENT ME!
 */
private void validateClass(Class clazz) {
    if (clazz == null) {
        throw new IllegalArgumentException("target class is null");
    } else if (clazz.isPrimitive()) {
        throw new IllegalArgumentException("target class is a primitive");
    } else if (clazz.isArray()) {
        throw new IllegalArgumentException("target class is an array");
    } else if (clazz.isInterface()) {
        throw new IllegalArgumentException("target class is an interface");
    } else if (DynaBean.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("target class is a DynaBean");
    } else if (Number.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz)
            || Character.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("target class is a wrapper");
    } else if (String.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("target class is a String");
    } else if (Collection.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("target class is a Collection");
    } else if (Map.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("target class is a Map");
    }
}

From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeansGenerator.java

protected void createService(BeanDefinitionRegistry registry, ModelContext modelContext)
        throws NotFoundException, CannotCompileException {
    if (modelContext.getServiceDefinition() == null) {

        String newBeanClassName = modelContext.getGeneratedClassNamePrefix() + "Service";
        String newBeanRegistryName = StringUtils.uncapitalize(newBeanClassName);
        String newBeanPackage = this.serviceBasePackage + '.';
        // grab the generic types
        List<Class<?>> genericTypes = modelContext.getGenericTypes();

        // extend the base service interface
        Class<?> newServiceInterface = JavassistUtil.createInterface(newBeanPackage + newBeanClassName,
                ModelService.class, genericTypes);
        ArrayList<Class<?>> interfaces = new ArrayList<Class<?>>(1);
        interfaces.add(newServiceInterface);

        // create a service implementation bean
        CreateClassCommand createServiceCmd = new CreateClassCommand(
                newBeanPackage + "impl." + newBeanClassName + "Impl", AbstractModelServiceImpl.class);
        createServiceCmd.setInterfaces(interfaces);
        createServiceCmd.setGenericTypes(genericTypes);
        createServiceCmd.addGenericType(modelContext.getRepositoryType());
        HashMap<String, Object> named = new HashMap<String, Object>();
        named.put("value", newBeanRegistryName);
        createServiceCmd.addTypeAnnotation(Named.class, named);

        // create and register a service implementation bean
        Class<?> serviceClass = JavassistUtil.createClass(createServiceCmd);
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(serviceClass).getBeanDefinition();
        registry.registerBeanDefinition(newBeanRegistryName, def);

        // note in context as a dependency to a controller
        modelContext.setServiceDefinition(def);
        modelContext.setServiceInterfaceType(newServiceInterface);
        modelContext.setServiceImplType(serviceClass);

    } else {//from  w  ww. ja  va2 s .  c om
        Class<?> serviceType = ClassUtils.getClass(modelContext.getServiceDefinition().getBeanClassName());
        // grab the service interface
        if (!serviceType.isInterface()) {
            Class<?>[] serviceInterfaces = serviceType.getInterfaces();
            if (ArrayUtils.isNotEmpty(serviceInterfaces)) {
                for (Class<?> interfaze : serviceInterfaces) {
                    if (ModelService.class.isAssignableFrom(interfaze)) {
                        modelContext.setServiceInterfaceType(interfaze);
                        break;
                    }
                }
            }
        }
        Assert.notNull(modelContext.getRepositoryType(),
                "Found a service bean definition for " + modelContext.getGeneratedClassNamePrefix()
                        + "  but failed to figure out the service interface type.");
    }
}

From source file:org.atricore.idbus.kernel.main.databinding.JAXBUtils.java

/**
 * @param list//from   ww  w . j  a  va 2 s  . com
 * @param pkg
 */
private static void checkClasses(List<Class> list, String pkg) {
    // The installed classfinder or directory search may inadvertently add too many
    // classes.  This rountine is a 'double check' to make sure that the classes
    // are acceptable.
    for (int i = 0; i < list.size();) {
        Class cls = list.get(i);
        if (!cls.isInterface()
                && (cls.isEnum() || getAnnotation(cls, XmlType.class) != null
                        || ClassUtils.getDefaultPublicConstructor(cls) != null)
                && !ClassUtils.isJAXWSClass(cls) && !isSkipClass(cls)
                && cls.getPackage().getName().equals(pkg)) {
            i++; // Acceptable class
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Removing class " + cls + " from consideration because it is not in package " + pkg
                        + " or is an interface or does not have a public constructor or is" + " a jaxws class");
            }
            list.remove(i);
        }
    }
}

From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java

private void _onJSONWebServiceClass(String className) throws Exception {
    Class<?> actionClass = _classLoader.loadClass(className);

    if (!_isJSONWebServiceClass(actionClass)) {
        return;/*  w  w  w  .  j  a  v  a  2  s.c o m*/
    }

    if (actionClass.isInterface() && _hasAnnotatedServiceImpl(className)) {
        return;
    }

    JSONWebService classAnnotation = actionClass.getAnnotation(JSONWebService.class);

    JSONWebServiceMode classAnnotationMode = JSONWebServiceMode.MANUAL;

    if (classAnnotation != null) {
        classAnnotationMode = classAnnotation.mode();
    }

    Method[] methods = actionClass.getMethods();

    for (Method method : methods) {
        Class<?> methodDeclaringClass = method.getDeclaringClass();

        if (!methodDeclaringClass.equals(actionClass)) {
            continue;
        }

        boolean registerMethod = false;

        JSONWebService methodAnnotation = method.getAnnotation(JSONWebService.class);

        if (classAnnotationMode.equals(JSONWebServiceMode.AUTO)) {
            registerMethod = true;

            if (methodAnnotation != null) {
                JSONWebServiceMode methodAnnotationMode = methodAnnotation.mode();

                if (methodAnnotationMode.equals(JSONWebServiceMode.IGNORE)) {

                    registerMethod = false;
                }
            }
        } else {
            if (methodAnnotation != null) {
                JSONWebServiceMode methodAnnotationMode = methodAnnotation.mode();

                if (!methodAnnotationMode.equals(JSONWebServiceMode.IGNORE)) {

                    registerMethod = true;
                }
            }
        }

        if (registerMethod) {
            _registerJSONWebServiceAction(actionClass, method);
        }
    }
}