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.eclipse.emf.teneo.hibernate.mapping.eav.EAVObjectTuplizer.java

@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
    if (persistentClass.getClassName() == null) { // an entity, no proxy
        return null;
    }/*from  w  w w.  ja  v  a2s . com*/

    final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass);
    final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName());
    if (eclass == null) {
        throw new HbMapperException("No eclass found for entityname: " + persistentClass.getEntityName());
    }

    // get all the interfaces from the main class, add the real interface
    // first
    final Set<Class<?>> proxyInterfaces = new LinkedHashSet<Class<?>>();
    final Class<?> pInterface = persistentClass.getProxyInterface();
    if (pInterface != null) {
        proxyInterfaces.add(pInterface);
    }
    final Class<?> mappedClass = persistentClass.getMappedClass();
    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }
    proxyInterfaces.add(HibernateProxy.class);
    proxyInterfaces.add(TeneoInternalEObject.class);

    for (Class<?> interfaces : mappedClass.getInterfaces()) {
        proxyInterfaces.add(interfaces);
    }

    // iterate over all subclasses and add them also
    final Iterator<?> iter = persistentClass.getSubclassIterator();
    while (iter.hasNext()) {
        final Subclass subclass = (Subclass) iter.next();
        final Class<?> subclassProxy = subclass.getProxyInterface();
        final Class<?> subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
            proxyInterfaces.add(subclassProxy);
        }
    }

    // get the idgettters/setters
    final Method theIdGetterMethod = idGetter == null ? null : idGetter.getMethod();
    final Method theIdSetterMethod = idSetter == null ? null : idSetter.getMethod();

    final Method proxyGetIdentifierMethod = theIdGetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdGetterMethod);
    final Method proxySetIdentifierMethod = theIdSetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdSetterMethod);

    ProxyFactory pf = Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod,
                proxySetIdentifierMethod,
                persistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HbStoreException e) {
        log.warn("could not create proxy factory for:" + getEntityName(), e);
        pf = null;
    }
    return pf;
}

From source file:org.apache.hadoop.yarn.webapp.hamlet.HamletGen.java

void genImpl(Class<?> spec, String implClassName, int indent) {
    String specName = spec.getSimpleName();
    for (Class<?> cls : spec.getClasses()) {
        String className = cls.getSimpleName();
        if (cls.isInterface()) {
            genFactoryMethods(cls, indent);
        }//from   ww  w. ja va  2 s  .  c  om
        if (isElement(className)) {
            LOG.info("Generating class {}<T>", className);
            puts(indent, "\n", "public class ", className, "<T extends _>", " extends EImp<T> implements ",
                    specName, ".", className, " {\n", "  public ", className, "(String name, T parent,",
                    " EnumSet<EOpt> opts) {\n", "    super(name, parent, opts);\n", "  }");
            genMethods(className, cls, indent + 1);
            puts(indent, "}");
        } else if (className.equals("_Html")) {
            top = cls;
        }
    }
}

From source file:com.mockey.plugin.PluginStore.java

/**
 * /*from w  ww  .  j a  v a  2 s .com*/
 * @param className
 * @return Instance of a Class with 'className, if implements
 *         <code>IRequestInspector</code>, otherwise returns null.
 */
private IRequestInspector createInspectorInstance(Class<?> clazz) {

    IRequestInspector instance = null;
    // HACK:
    if (!clazz.getName().equalsIgnoreCase(RequestInspectorDefinedByJson.class.getName())) {

        try {
            if (!clazz.isInterface() && IRequestInspector.class.isAssignableFrom(clazz)) {
                instance = (IRequestInspector) clazz.newInstance();
            }
        } catch (Exception e) {

            logger.error("Unable to create an instance of a class w/ name " + clazz.getName(), e);
        }
    }
    return instance;
}

From source file:net.sf.jrf.domain.PersistentObjectDynaClass.java

/** Overrides base class version to allow no-args constructors.
* @param dynaBeanClass <code>Class</code> instance to examine.
*///w  w  w.ja  va 2s  .com
protected void setDynaBeanClass(Class dynaBeanClass) {
    // Validate the argument type specified
    if (dynaBeanClass.isInterface())
        throw new IllegalArgumentException(
                "Class " + dynaBeanClass.getName() + " is an interface, not a class");
    if (!DynaBean.class.isAssignableFrom(dynaBeanClass))
        throw new IllegalArgumentException("Class " + dynaBeanClass.getName() + " does not implement DynaBean");
    if (!PersistentObjectDynaBean.class.isAssignableFrom(dynaBeanClass))
        throw new IllegalArgumentException(
                "Class " + dynaBeanClass.getName() + " does not implement PersistentObjectDynaBean");

    // Try DynaClass arg first, followed by no-arg constructor.
    for (int i = 0; super.constructor == null && i < 2; i++) {
        Class[] constructorParams = (i == 0 ? new Class[] { this.getClass() } : new Class[] {});
        try {
            super.constructor = dynaBeanClass.getConstructor(constructorParams);
            super.constructorValues = (i == 0 ? new Object[] { this } : new Object[] {});

        } catch (NoSuchMethodException e) {
        }
    }
    if (super.constructor == null)
        throw new IllegalArgumentException(
                "Class " + dynaBeanClass.getName() + " does not have an appropriate constructor");
    super.dynaBeanClass = dynaBeanClass;
}

From source file:com.agimatec.validation.jsr303.ClassValidator.java

/**
 * Return an object of the specified type to allow access to the
 * provider-specific API.  If the Bean Validation provider
 * implementation does not support the specified class, the
 * ValidationException is thrown.//from  www .j a  v  a 2  s.c  o m
 *
 * @param type the class of the object to be returned.
 * @return an instance of the specified class
 * @throws ValidationException if the provider does not
 *                             support the call.
 */
public <T> T unwrap(Class<T> type) {
    if (type.isAssignableFrom(getClass())) {
        return (T) this;
    } else if (!type.isInterface()) {
        return SecureActions.newInstance(type, new Class[] { AgimatecFactoryContext.class },
                new Object[] { factoryContext });
    } else {
        try {
            Class<T> cls = ClassUtils.getClass(type.getName() + "Impl");
            return SecureActions.newInstance(cls, new Class[] { AgimatecFactoryContext.class },
                    new Object[] { factoryContext });
        } catch (ClassNotFoundException e) {
            throw new ValidationException("Type " + type + " not supported");
        }
    }
}

From source file:org.firstopen.singularity.admin.view.DeviceProfileBean.java

public Set<String> getInterrogators() {

    String packageName = "org.firstopen.singularity.devicemgr.interrogator";
    Set<String> classFileNames = ReflectionUtil.getClassFilenames(packageName);

    HashSet<String> classes = new HashSet<String>();
    for (String filename : classFileNames) {

        /*//from   www  .j  a v  a  2 s  .co  m
         * removes the .class extension
         */
        String classname = filename.substring(0, filename.length() - 6);

        /*
         * check for instance of Interrogator
         */

        String fullname = packageName + "." + classname;

        Class c;
        try {
            c = Class.forName(fullname);

            if (!c.isInterface() && classname.endsWith("IO")) {

                Object o = Class.forName(fullname).newInstance();

                if (o instanceof Interrogator) {
                    System.out.println(classname);
                }
            } // ends with
        } catch (ClassNotFoundException e) {

            log.error(e);
        } catch (InstantiationException e) {

            log.error(e);
        } catch (IllegalAccessException e) {

            log.error(e);
        }
    } // end for all classFileNames
    return classes;
}

From source file:de.alpharogroup.lang.ClassExtensions.java

/**
 * Gets the {@link ClassType} from the given class.
 *
 * @param clazz//from w  w w .jav  a  2s.c  o m
 *            The class.
 * @return the {@link ClassType} from the given class.
 */
public static ClassType getClassType(final Class<?> clazz) {
    if (clazz.isArray()) {
        return ClassType.ARRAY;
    }
    if (isCollection(clazz)) {
        return ClassType.COLLECTION;
    }
    if (isMap(clazz)) {
        return ClassType.MAP;
    }
    if (clazz.isLocalClass()) {
        return ClassType.LOCAL;
    }
    if (clazz.isMemberClass()) {
        return ClassType.MEMBER;
    }
    if (clazz.isPrimitive()) {
        return ClassType.PRIMITIVE;
    }
    if (clazz.isAnnotation()) {
        return ClassType.ANNOTATION;
    }
    if (clazz.isEnum()) {
        return ClassType.ENUM;
    }
    if (clazz.isInterface()) {
        return ClassType.INTERFACE;
    }
    if (clazz.isSynthetic()) {
        return ClassType.SYNTHETIC;
    }
    if (clazz.isAnonymousClass()) {
        return ClassType.ANONYMOUS;
    }
    return ClassType.DEFAULT;
}

From source file:com.bstek.dorado.data.entity.PropertyPathUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void setValueByPath(EntityDataType dataType, Object object, String propertyPath, Object value)
        throws Exception {
    String[] paths = StringUtils.split(propertyPath, '.');
    Object currentEntity = object;
    EntityDataType currentDataType = dataType;
    for (int i = 0; i < paths.length - 1; i++) {
        String path = paths[i];//from www .  j  a v  a  2  s .co  m
        Object tempEntity;
        boolean isMap = currentEntity instanceof Map;
        if (EntityUtils.isEntity(currentEntity)) {
            tempEntity = EntityUtils.getValue(currentEntity, path);
        } else if (currentEntity instanceof Map) {
            tempEntity = ((Map) currentEntity).get(path);
        } else {
            tempEntity = PropertyUtils.getSimpleProperty(currentEntity, path);
        }

        if (tempEntity == null) {
            Class<?> subEntityType = null;
            if (currentDataType != null) {
                PropertyDef propertyDef = currentDataType.getPropertyDef(path);
                if (propertyDef != null) {
                    DataType propertyDataType = propertyDef.getDataType();
                    if (propertyDataType instanceof EntityDataType) {
                        currentDataType = (EntityDataType) propertyDataType;
                        subEntityType = currentDataType.getCreationType();
                        if (subEntityType == null) {
                            subEntityType = currentDataType.getMatchType();
                        }
                    }
                }
            } else if (isMap) {
                tempEntity = new HashMap();
                currentDataType = null;
            }

            if (tempEntity == null) {
                if (subEntityType == null) {
                    subEntityType = PropertyUtils.getPropertyType(currentEntity, path);
                }
                if (subEntityType.isAssignableFrom(Map.class)) {
                    tempEntity = new HashMap();
                } else if (!subEntityType.isInterface()) {
                    tempEntity = subEntityType.newInstance();
                }
                currentDataType = null;
            }

            if (tempEntity != null) {
                if (isMap) {
                    ((Map) currentEntity).put(path, tempEntity);
                } else {
                    PropertyUtils.setSimpleProperty(currentEntity, path, tempEntity);
                }
            } else {
                throw new IllegalArgumentException("Can not write value to [" + StringUtils.join(paths, '.')
                        + "] on [" + ObjectUtils.identityToString(object) + "].");
            }
        }
        currentEntity = tempEntity;
    }

    String path = paths[paths.length - 1];
    if (EntityUtils.isEntity(currentEntity)) {
        EntityUtils.setValue(currentEntity, path, value);
    } else if (currentEntity instanceof Map) {
        ((Map) currentEntity).put(path, value);
    } else {
        PropertyUtils.setSimpleProperty(currentEntity, path, value);
    }
}

From source file:org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldBase.java

/**
 * try to find a field in class c, recurse through class hierarchy if necessary
 *
 * @throws NoSuchFieldException if no Field was found into the class hierarchy
 *//*from   w w  w  .j av  a2  s  .c  om*/
private Field getFieldRecursive(Class c, String name) throws NoSuchFieldException {
    try {
        return c.getDeclaredField(name);
    } catch (NoSuchFieldException e) {
        // if field  could not be found in the inheritance hierarchy, signal error
        if ((c == Object.class) || (c.getSuperclass() == null) || c.isInterface()) {
            throw e;
        }
        // if field could not be found in class c try in superclass
        else {
            return getFieldRecursive(c.getSuperclass(), name);
        }
    }
}

From source file:org.eclipse.emf.teneo.ERuntime.java

/** Get the eclass for a certain class */
@Override/*  w ww.j a  v  a2  s  . com*/
public synchronized EClass getEClass(Class<?> clazz) {
    if (clazz.isInterface()) {
        return interfaceToEClass.get(clazz);
    }
    return concreteToEClass.get(clazz);
}