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:org.castor.jaxb.reflection.ClassInfoBuilder.java

/**
 * Checks if a field of a class is describeable or not e.g. static or
 * transient fields are not described./*from  w  w  w. jav  a 2 s  .  c  o m*/
 * 
 * @param type
 *            the Class holding the field
 * @param field
 *            the field to check
 * @return true if the field should be described
 */
private boolean isDescribeable(final Class<?> type, final Field field) {
    boolean isDescribeable = true;
    Class<?> declaringClass = field.getDeclaringClass();
    if ((declaringClass != null) && !type.equals(declaringClass) && (!declaringClass.isInterface())) {
        isDescribeable = false;
    }
    if (Modifier.isStatic(field.getModifiers())) {
        isDescribeable &= false;
    }
    if (Modifier.isTransient(field.getModifiers())) {
        isDescribeable &= false;
    }
    if (field.isSynthetic()) {
        isDescribeable &= false;
    }
    return isDescribeable;
}

From source file:org.hibernate.tuple.entity.PojoEntityTuplizer.java

/**
 * {@inheritDoc}//from w w  w. j a va  2  s  .  c o  m
 */
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
    // determine the id getter and setter methods from the proxy interface (if any)
    // determine all interfaces needed by the resulting proxy
    HashSet proxyInterfaces = new HashSet();
    proxyInterfaces.add(HibernateProxy.class);

    Class mappedClass = persistentClass.getMappedClass();
    Class proxyInterface = persistentClass.getProxyInterface();

    if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
        if (!proxyInterface.isInterface()) {
            throw new MappingException(
                    "proxy must be either an interface, or the class itself: " + getEntityName());
        }
        proxyInterfaces.add(proxyInterface);
    }

    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }

    Iterator iter = persistentClass.getSubclassIterator();
    while (iter.hasNext()) {
        Subclass subclass = (Subclass) iter.next();
        Class subclassProxy = subclass.getProxyInterface();
        Class subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
            if (!proxyInterface.isInterface()) {
                throw new MappingException(
                        "proxy must be either an interface, or the class itself: " + subclass.getEntityName());
            }
            proxyInterfaces.add(subclassProxy);
        }
    }

    Iterator properties = persistentClass.getPropertyIterator();
    Class clazz = persistentClass.getMappedClass();
    while (properties.hasNext()) {
        Property property = (Property) properties.next();
        Method method = property.getGetter(clazz).getMethod();
        if (method != null && Modifier.isFinal(method.getModifiers())) {
            log.error("Getters of lazy classes cannot be final: " + persistentClass.getEntityName() + "."
                    + property.getName());
        }
        method = property.getSetter(clazz).getMethod();
        if (method != null && Modifier.isFinal(method.getModifiers())) {
            log.error("Setters of lazy classes cannot be final: " + persistentClass.getEntityName() + "."
                    + property.getName());
        }
    }

    Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
    Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();

    Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null
            : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
    Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null
            : ReflectHelper.getMethod(proxyInterface, idSetterMethod);

    ProxyFactory pf = buildProxyFactoryInternal(persistentClass, idGetter, idSetter);
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod,
                proxySetIdentifierMethod,
                persistentClass.hasEmbeddedIdentifier()
                        ? (AbstractComponentType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HibernateException he) {
        log.warn("could not create proxy factory for:" + getEntityName(), he);
        pf = null;
    }
    return pf;
}

From source file:org.castor.jaxb.reflection.ClassInfoBuilder.java

/**
 * Checks if the Method is describeable.
 * //from  ww w . j a v  a  2  s .com
 * @param type
 *            the Class of the Method
 * @param method
 *            the Method to check
 * @return true if the method is describeable
 */
private boolean isDescribeable(final Class<?> type, final Method method) {
    boolean isDescribeable = true;
    Class<?> declaringClass = method.getDeclaringClass();
    if ((declaringClass != null) && !type.equals(declaringClass) && (!declaringClass.isInterface())) {
        isDescribeable = false;
    }
    if (method.isSynthetic()) {
        isDescribeable &= false;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        isDescribeable &= false;
    }
    if (Modifier.isTransient(method.getModifiers())) {
        isDescribeable &= false;
    }
    if (!(javaNaming.isAddMethod(method) || javaNaming.isCreateMethod(method) || javaNaming.isGetMethod(method)
            || javaNaming.isIsMethod(method) || javaNaming.isSetMethod(method))) {
        isDescribeable = false;
    }
    return isDescribeable;
}

From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java

/**
 * Sets the required type for the Java class.
 *
 * @param type//from  w w w. j ava2  s  .c o m
 *            the required type for the Java class.
 * @return this object
 */
public ClassValidator type(final ClassType type) {
    Validate.notNull(type, "The type must not be null");

    if (getSubject() != null) {
        Class<?> javaClass = getSubject();
        boolean isTypeValid = false;

        switch (type) {
        case CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray();
            break;

        case REGULAR_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && !javaClass.isMemberClass()
                    && !javaClass.isAnonymousClass() && !javaClass.isLocalClass();
            break;

        case MEMBER_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isMemberClass();
            break;

        case ANONYMOUS_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isAnonymousClass();
            break;

        case LOCAL_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isLocalClass();
            break;

        case INTERFACE:
            isTypeValid = javaClass.isInterface();
            break;

        case REGULAR_INTERFACE:
            isTypeValid = javaClass.isInterface() && !javaClass.isMemberClass();
            break;

        case MEMBER_INTERFACE:
            isTypeValid = javaClass.isInterface() && javaClass.isMemberClass();
            break;

        case ENUM:
            isTypeValid = javaClass.isEnum();
            break;

        case REGULAR_ENUM:
            isTypeValid = javaClass.isEnum() && !javaClass.isMemberClass();
            break;

        case MEMBER_ENUM:
            isTypeValid = javaClass.isEnum() && javaClass.isMemberClass();
            break;

        case ANNOTATION:
            isTypeValid = javaClass.isAnnotation();
            break;

        case REGULAR_ANNOTATION:
            isTypeValid = javaClass.isAnnotation() && !javaClass.isMemberClass();
            break;

        case MEMBER_ANNOTATION:
            isTypeValid = javaClass.isAnnotation() && javaClass.isMemberClass();
            break;

        case PRIMITIVE:
            isTypeValid = javaClass.isPrimitive();
            break;

        case ARRAY:
            isTypeValid = javaClass.isArray();
            break;

        default:
            throw new UnsupportedOperationException("Unknown class type: " + type);
        }

        if (!isTypeValid) {
            this.addException(
                    String.format("The Java class must have the specified type\n" + "(type: [%s])", type));
        }
    }

    return this;
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java

/**
 * @param list/*from w  w  w. j a v a2 s  .co  m*/
 * @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:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Learn whether this BasicTypeConverter can create a collection of the specified type.
 * @param type prospective destination class
 * @return boolean/*from   www . jav a2  s .c om*/
 */
protected boolean canCreateCollection(Class type) {
    if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) {
        try {
            type.getConstructor(new Class[0]);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    return type == List.class || type == Collection.class || type == Set.class;
}

From source file:com.liferay.arkadiko.bean.AKBeanPostProcessor.java

/**
 * Try to get an Arkadiko bean which is a proxy backed by an OSGi service
 * tracker which is either going to wrap an existing spring bean, or wait
 * for one to be registered. This only happens when the bean is declared to
 * be wrapped by name or by class/interface.
 *
 * @param rootBeanDefinition//w  w  w  . ja va 2s  . c o m
 * @param beanName
 * @return a bean or null
 */
protected Object getServiceBean(RootBeanDefinition rootBeanDefinition, String beanName) {

    BeanDefinition originatingBeanDefinition = rootBeanDefinition.getOriginatingBeanDefinition();

    if ((originatingBeanDefinition != null) && (originatingBeanDefinition instanceof AKBeanDefinition)) {

        AKBeanDefinition akBeanDefinition = (AKBeanDefinition) originatingBeanDefinition;

        return akBeanDefinition.getProxy();
    } else if (rootBeanDefinition.hasBeanClass()) {
        Class<?> clazz = rootBeanDefinition.getBeanClass();

        if (clazz.isInterface()) {
            AKBeanDefinition akBeanDefinition = new AKBeanDefinition(this, rootBeanDefinition, beanName,
                    getServiceRegistry());

            return akBeanDefinition.getProxy();
        }
    }

    return null;
}

From source file:com.orange.mmp.api.helpers.DefaultApiContainer.java

/**
 * Inner method used to add module API from their configuration file  
 * //from ww  w.j a va2s . com
 * @param module The module owning the API
 * @throws MMPApiException
 */
@SuppressWarnings("unchecked")
protected void addModuleApi(Module module) throws MMPApiException {
    try {
        MMPConfig moduleConfiguration = ModuleContainerFactory.getInstance().getModuleContainer()
                .getModuleConfiguration(module);
        if (moduleConfiguration != null && moduleConfiguration.getApi() != null) {
            for (MMPConfig.Api apiConfig : moduleConfiguration.getApi()) {
                String definitionClassname = null;
                String implementationClassname = null;
                if (apiConfig.getDefinition() != null
                        && apiConfig.getDefinition().getOtherAttributes() != null) {
                    definitionClassname = apiConfig.getDefinition().getOtherAttributes()
                            .get(CUAPI_CONFIG_ATTR_CLASSNAME);
                }
                if (apiConfig.getImplementation() != null
                        && apiConfig.getImplementation().getOtherAttributes() != null) {
                    implementationClassname = apiConfig.getImplementation().getOtherAttributes()
                            .get(CUAPI_CONFIG_ATTR_CLASSNAME);
                }

                if (definitionClassname != null && implementationClassname != null) {
                    Class definitionClass = ModuleContainerFactory.getInstance().getModuleContainer()
                            .loadModuleClass(module, definitionClassname);
                    if (!definitionClass.isInterface()) {
                        throw new MMPApiException("Failed to add Module '" + module.getName() + "' Service : '"
                                + definitionClass.getName() + "' is not an interface");
                    }
                    Object implementationInstance = ModuleContainerFactory.getInstance().getModuleContainer()
                            .loadModuleClass(module, implementationClassname).newInstance();
                    Api api = new Api();
                    api.setDefinitionClass(definitionClass);
                    api.setName(apiConfig.getName());
                    api.setPublished(apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PUBLISHED) == null
                            || apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PUBLISHED)
                                    .equalsIgnoreCase("true"));
                    api.setShared(apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_SHARED) != null
                            && apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_SHARED)
                                    .equalsIgnoreCase("true"));
                    api.setPublic(apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PUBLIC) != null
                            && apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PUBLIC)
                                    .equalsIgnoreCase("true"));
                    api.setPrivate(apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PRIVATE) != null
                            && apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_IS_PRIVATE)
                                    .equalsIgnoreCase("true"));

                    // Errortype
                    if (apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_ERROR_TYPE) != null)
                        api.setErrorType(
                                apiConfig.getOtherAttributes().get(CUAPI_CONFIG_ATTR_ERROR_TYPE).toLowerCase());
                    else
                        api.setErrorType("body");
                    //Add api to current ServiceContainer
                    this.addApi(api, implementationInstance);
                }
            }
        }
    } catch (InstantiationException ie) {
        throw new MMPApiException(ie);
    } catch (IllegalAccessException iae) {
        throw new MMPApiException(iae);
    } catch (MMPModuleException ce) {
        throw new MMPApiException(ce);
    }
}

From source file:org.beanfuse.struts2.action.EntityDrivenAction.java

protected Entity populateEntity(Class entityClass, String shortName) {
    EntityType type = null;/*from ww w.j  a  va 2 s.  c o  m*/
    if (entityClass.isInterface()) {
        type = Model.getEntityType(entityClass.getName());
    } else {
        type = Model.getEntityType(entityClass);
    }
    return populateEntity(type.getEntityName(), shortName);
}

From source file:org.beanfuse.struts2.action.EntityDrivenAction.java

protected Entity getEntity(Class entityClass, String shortName) {
    EntityType type = null;/*from   w w w  .j a v a 2 s  . c om*/
    if (entityClass.isInterface()) {
        type = Model.getEntityType(entityClass.getName());
    } else {
        type = Model.getEntityType(entityClass);
    }
    return getEntity(type.getEntityName(), shortName);
}