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.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadKnowledgeImporters() {

    String ipack = this.getClass().getPackage().getName() + ".importers";

    for (Class<?> cls : MiscUtilities.findSubclasses(IKnowledgeImporter.class, ipack, getClassLoader())) {

        /*//from  ww  w .jav  a2s . com
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) {

                String fmt = ((org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) annotation)
                        .format();
                KBoxManager.get().registerImporterClass(fmt, cls);

                break;
            }
        }
    }

}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadTransformations() throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + ".transformations";

    for (Class<?> cls : MiscUtilities.findSubclasses(ITransformation.class, ipack, getClassLoader())) {

        /*//from   www  .  j  ava  2s.  c o  m
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof DataTransformation) {

                String name = ((DataTransformation) annotation).id();
                try {
                    TransformationFactory.get().registerTransformation(name,
                            (ITransformation) cls.newInstance());
                } catch (Exception e) {
                    throw new ThinklabValidationException(e);
                }

                break;
            }
        }
    }

}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadListingProviders() throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + ".commands";

    for (Class<?> cls : MiscUtilities.findSubclasses(IListingProvider.class, ipack, getClassLoader())) {

        /*//from   ww  w.jav  a2 s  .  c  om
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof ListingProvider) {

                String name = ((ListingProvider) annotation).label();
                String sname = ((ListingProvider) annotation).itemlabel();
                try {
                    CommandManager.get().registerListingProvider(name, sname,
                            (IListingProvider) cls.newInstance());
                } catch (Exception e) {
                    throw new ThinklabValidationException(e);
                }

                break;
            }
        }
    }
}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadPersistentClasses() throws ThinklabPluginException {

    String ipack = this.getClass().getPackage().getName() + ".implementations";

    for (Class<?> cls : MiscUtilities.findSubclasses(IPersistentObject.class, ipack, getClassLoader())) {

        String ext = null;//from  w  w w  .  ja v a  2  s.  com

        /*
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * lookup implemented concept
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof PersistentObject) {
                ext = ((PersistentObject) annotation).extension();
                if (ext.equals("__NOEXT__"))
                    ext = null;
                break;
            }
        }

        PersistenceManager.get().registerSerializableClass(cls, ext);
    }
}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadCommandHandlers() throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + ".commands";

    for (Class<?> cls : MiscUtilities.findSubclasses(ICommandHandler.class, ipack, getClassLoader())) {

        /*/*from  w  ww.j  av  a 2  s .  co m*/
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * lookup implemented concept
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof ThinklabCommand) {

                String name = ((ThinklabCommand) annotation).name();
                String description = ((ThinklabCommand) annotation).description();

                CommandDeclaration declaration = new CommandDeclaration(name, description);

                String retType = ((ThinklabCommand) annotation).returnType();

                if (!retType.equals(""))
                    declaration.setReturnType(KnowledgeManager.get().requireConcept(retType));

                String[] aNames = ((ThinklabCommand) annotation).argumentNames().split(",");
                String[] aTypes = ((ThinklabCommand) annotation).argumentTypes().split(",");
                String[] aDesc = ((ThinklabCommand) annotation).argumentDescriptions().split(",");

                for (int i = 0; i < aNames.length; i++) {
                    if (!aNames[i].isEmpty())
                        declaration.addMandatoryArgument(aNames[i], aDesc[i], aTypes[i]);
                }

                String[] oaNames = ((ThinklabCommand) annotation).optionalArgumentNames().split(",");
                String[] oaTypes = ((ThinklabCommand) annotation).optionalArgumentTypes().split(",");
                String[] oaDesc = ((ThinklabCommand) annotation).optionalArgumentDescriptions().split(",");
                String[] oaDefs = ((ThinklabCommand) annotation).optionalArgumentDefaultValues().split(",");

                for (int i = 0; i < oaNames.length; i++) {
                    if (!oaNames[i].isEmpty())
                        declaration.addOptionalArgument(oaNames[i], oaDesc[i], oaTypes[i], oaDefs[i]);
                }

                String[] oNames = ((ThinklabCommand) annotation).optionNames().split(",");
                String[] olNames = ((ThinklabCommand) annotation).optionLongNames().split(",");
                String[] oaLabel = ((ThinklabCommand) annotation).optionArgumentLabels().split(",");
                String[] oTypes = ((ThinklabCommand) annotation).optionTypes().split(",");
                String[] oDesc = ((ThinklabCommand) annotation).optionDescriptions().split(",");

                for (int i = 0; i < oNames.length; i++) {
                    if (!oNames[i].isEmpty())
                        declaration.addOption(oNames[i], olNames[i],
                                (oaLabel[i].equals("") ? null : oaLabel[i]), oDesc[i], oTypes[i]);
                }

                try {
                    CommandManager.get().registerCommand(declaration, (ICommandHandler) cls.newInstance());
                } catch (Exception e) {
                    throw new ThinklabValidationException(e);
                }

                break;
            }
        }
    }

}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadInstanceImplementationConstructors() throws ThinklabPluginException {

    String ipack = this.getClass().getPackage().getName() + ".implementations";

    for (Class<?> cls : MiscUtilities.findSubclasses(IInstanceImplementation.class, ipack, getClassLoader())) {

        String concept = null;/* www .j  ava2  s.  c o  m*/

        /*
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * lookup implemented concept
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof InstanceImplementation) {
                concept = ((InstanceImplementation) annotation).concept();
            }
        }

        if (concept != null) {

            String[] cc = concept.split(",");

            for (String ccc : cc) {
                logger().info("registering class " + cls + " as implementation for instances of type " + ccc);
                KnowledgeManager.get().registerInstanceImplementationClass(ccc, cls);
            }
        }
    }
}

From source file:com.clarkparsia.empire.annotation.RdfGenerator.java

/**
 * Create an instance of the specified class and instantiate it's data from the given data source using the RDF
 * instance specified by the given URI//from   w w  w.  ja  v  a 2  s. c o m
 * @param theClass the class to create
 * @param theId the id of the RDF individual containing the data for the new instance
 * @param theSource the KB to get the RDF data from
 * @param <T> the type of the instance to create
 * @return a new instance
 * @throws InvalidRdfException thrown if the class does not support RDF JPA operations, or does not provide sufficient access to its fields/data.
 * @throws DataSourceException thrown if there is an error while retrieving data from the graph
 */
public static <T> T fromRdf(Class<T> theClass, SupportsRdfId.RdfKey theId, DataSource theSource)
        throws InvalidRdfException, DataSourceException {
    T aObj;
    long start = System.currentTimeMillis(), start1 = System.currentTimeMillis();
    try {
        aObj = Empire.get().instance(theClass);
    } catch (ConfigurationException ex) {
        aObj = null;
    } catch (ProvisionException ex) {
        aObj = null;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Tried to get instance of class in {} ms ", (System.currentTimeMillis() - start));
    }
    start = System.currentTimeMillis();

    if (aObj == null) {
        // this means Guice construction failed, which is not surprising since that's not going to be the default.
        // so we'll try our own reflect based creation or create bytecode for an interface.

        try {
            long istart = System.currentTimeMillis();
            if (theClass.isInterface() || Modifier.isAbstract(theClass.getModifiers())) {
                aObj = com.clarkparsia.empire.codegen.InstanceGenerator.generateInstanceClass(theClass)
                        .newInstance();

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("CodeGenerated instance in {} ms. ", (System.currentTimeMillis() - istart));
                }
            } else {
                aObj = theClass.newInstance();

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("CodeGenerated instance in {} ms. ", (System.currentTimeMillis() - istart));
                }
            }
        } catch (InstantiationException e) {
            throw new InvalidRdfException("Cannot create instance of bean, should have a default constructor.",
                    e);
        } catch (IllegalAccessException e) {
            throw new InvalidRdfException("Could not access default constructor for class: " + theClass, e);
        } catch (Exception e) {
            throw new InvalidRdfException("Cannot create an instance of bean", e);
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got reflect instance of class {} ms ", (System.currentTimeMillis() - start1));
        }

        start = System.currentTimeMillis();
    }

    asSupportsRdfId(aObj).setRdfId(theId);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Has rdfId {} ms", (System.currentTimeMillis() - start1));
    }

    start = System.currentTimeMillis();

    Class<T> aNewClass = determineClass(theClass, aObj, theSource);

    if (!aNewClass.equals(aObj.getClass())) {
        try {
            aObj = aNewClass.newInstance();
        } catch (InstantiationException e) {
            throw new InvalidRdfException("Cannot create instance of bean, should have a default constructor.",
                    e);
        } catch (IllegalAccessException e) {
            throw new InvalidRdfException("Could not access default constructor for class: " + theClass, e);
        } catch (Exception e) {
            throw new InvalidRdfException("Cannot create an instance of bean", e);
        }
        asSupportsRdfId(aObj).setRdfId(theId);
    }

    T fromRdf = fromRdf(aObj, theSource);
    return fromRdf;
}

From source file:adalid.core.Operation.java

void initialiseFields(Class<?> clazz) {
    Class<?> c;// w  ww .j  av  a 2s  . com
    int d, r;
    String name;
    Class<?> type;
    int modifiers;
    boolean restricted;
    Object o;
    int depth = depth();
    int round = round();
    Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class };
    Class<?> dac = getClass();
    Class<?> top = Operation.class;
    int i = ArrayUtils.indexOf(classes, clazz);
    if (i != ArrayUtils.INDEX_NOT_FOUND) {
        c = classes[i];
        for (Field field : XS1.getFields(dac, top)) {
            field.setAccessible(true);
            logger.trace(field);
            name = field.getName();
            type = field.getType();
            if (!c.isAssignableFrom(type)) {
                continue;
            }
            modifiers = type.getModifiers();
            if (type.isInterface() && Expression.class.isAssignableFrom(type)) {
                restricted = false;
            } else {
                restricted = Modifier.isAbstract(modifiers);
            }
            restricted = restricted || !Modifier.isPublic(modifiers);
            if (restricted) {
                continue;
            }
            modifiers = field.getModifiers();
            restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
            if (restricted) {
                continue;
            }
            String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this;
            try {
                o = field.get(this);
                if (o == null) {
                    logger.debug(message(type, name, o, depth, round));
                    o = XS1.initialiseField(this, field);
                    if (o == null) {
                        logger.debug(message(type, name, o, depth, round));
                        //                          throw new RuntimeException(message(type, name, o, depth, round));
                    } else {
                        logger.debug(message(type, name, o, depth, round));
                        field.set(this, o);
                    }
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                throw new InstantiationRuntimeException(errmsg, ex);
            }
        }
    }
}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadLiteralValidators() throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + ".literals";

    for (Class<?> cls : MiscUtilities.findSubclasses(ParsedLiteralValue.class, ipack, getClassLoader())) {

        String concept = null;/*from w w  w  .  j a v a  2  s  . c o m*/
        String xsd = null;

        /*
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * lookup implemented concept
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof LiteralImplementation) {
                concept = ((LiteralImplementation) annotation).concept();
                xsd = ((LiteralImplementation) annotation).xsd();
            }
        }

        if (concept != null) {

            logger().info("registering class " + cls + " as implementation for literals of type " + concept);

            KnowledgeManager.get().registerLiteralImplementationClass(concept, cls);
            if (!xsd.equals(""))

                logger().info("registering XSD type mapping: " + xsd + " -> " + concept);
            KnowledgeManager.get().registerXSDTypeMapping(xsd, concept);
        }

    }

}

From source file:com.hc.wx.server.common.bytecode.ReflectUtils.java

private static Object getEmptyObject(Class<?> returnType, Map<Class<?>, Object> emptyInstances, int level) {
    if (level > 2)
        return null;
    if (returnType == null) {
        return null;
    } else if (returnType == boolean.class || returnType == Boolean.class) {
        return false;
    } else if (returnType == char.class || returnType == Character.class) {
        return '\0';
    } else if (returnType == byte.class || returnType == Byte.class) {
        return (byte) 0;
    } else if (returnType == short.class || returnType == Short.class) {
        return (short) 0;
    } else if (returnType == int.class || returnType == Integer.class) {
        return 0;
    } else if (returnType == long.class || returnType == Long.class) {
        return 0L;
    } else if (returnType == float.class || returnType == Float.class) {
        return 0F;
    } else if (returnType == double.class || returnType == Double.class) {
        return 0D;
    } else if (returnType.isArray()) {
        return Array.newInstance(returnType.getComponentType(), 0);
    } else if (returnType.isAssignableFrom(ArrayList.class)) {
        return new ArrayList<Object>(0);
    } else if (returnType.isAssignableFrom(HashSet.class)) {
        return new HashSet<Object>(0);
    } else if (returnType.isAssignableFrom(HashMap.class)) {
        return new HashMap<Object, Object>(0);
    } else if (String.class.equals(returnType)) {
        return "";
    } else if (!returnType.isInterface()) {
        try {/*from  w  w w .  j  av a2 s  . c  o m*/
            Object value = emptyInstances.get(returnType);
            if (value == null) {
                value = returnType.newInstance();
                emptyInstances.put(returnType, value);
            }
            Class<?> cls = value.getClass();
            while (cls != null && cls != Object.class) {
                Field[] fields = cls.getDeclaredFields();
                for (Field field : fields) {
                    Object property = getEmptyObject(field.getType(), emptyInstances, level + 1);
                    if (property != null) {
                        try {
                            if (!field.isAccessible()) {
                                field.setAccessible(true);
                            }
                            field.set(value, property);
                        } catch (Throwable e) {
                        }
                    }
                }
                cls = cls.getSuperclass();
            }
            return value;
        } catch (Throwable e) {
            return null;
        }
    } else {
        return null;
    }
}