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:se.crisp.codekvast.agent.daemon.codebase.CodeBaseScanner.java

void findTrackedConstructors(CodeBase codeBase, Class<?> clazz) {
    if (clazz.isInterface()) {
        log.debug("Ignoring interface {}", clazz);
        return;//from w w w . j av  a 2s  .co  m
    }

    log.debug("Analyzing {}", clazz);
    MethodAnalyzer methodAnalyzer = codeBase.getConfig().getMethodAnalyzer();
    try {
        Constructor[] declaredConstructors = clazz.getDeclaredConstructors();

        for (Constructor constructor : declaredConstructors) {
            SignatureStatus status = methodAnalyzer.apply(constructor);
            MethodSignature thisSignature = SignatureUtils.makeConstructorSignature(clazz, constructor);
            codeBase.addSignature(thisSignature, thisSignature, status);
        }

        for (Class<?> innerClass : clazz.getDeclaredClasses()) {
            findTrackedConstructors(codeBase, innerClass);
        }
    } catch (NoClassDefFoundError e) {
        log.warn("Cannot analyze {}: {}", clazz, e.toString());
    }
}

From source file:org.eclipse.gemini.blueprint.service.importer.support.StaticServiceProxyCreator.java

/**
 * Apply 'greedy' proxying by discovering the exposed classes.
 * //from   w w w.j a  v a2 s . c  o m
 * @param ref
 * @return
 */
Class<?>[] discoverProxyClasses(ServiceReference ref) {
    boolean trace = log.isTraceEnabled();

    if (trace)
        log.trace("Generating greedy proxy for service " + OsgiStringUtils.nullSafeToString(ref));

    String[] classNames = OsgiServiceReferenceUtils.getServiceObjectClasses(ref);

    if (trace)
        log.trace("Discovered raw classes " + ObjectUtils.nullSafeToString(classNames));

    // try to get as many classes as possible
    Class<?>[] classes = ClassUtils.loadClassesIfPossible(classNames, classLoader);

    if (trace)
        log.trace("Visible classes are " + ObjectUtils.nullSafeToString(classes));

    // exclude final classes
    classes = ClassUtils.excludeClassesWithModifier(classes, Modifier.FINAL);

    if (trace)
        log.trace("Filtering out final classes; left out with " + ObjectUtils.nullSafeToString(classes));

    // remove classes if needed
    if (interfacesOnlyProxying) {
        Set<Class<?>> clazzes = new LinkedHashSet<Class<?>>(classes.length);
        for (int classIndex = 0; classIndex < classes.length; classIndex++) {
            Class<?> clazz = classes[classIndex];
            if (clazz.isInterface())
                clazzes.add(clazz);
        }
        if (trace)
            log.trace("Filtering out concrete classes; left out with " + clazzes);

        classes = (Class[]) clazzes.toArray(new Class[clazzes.size()]);
    }

    // remove class duplicates/parents
    classes = ClassUtils.removeParents(classes);

    if (trace)
        log.trace("Filtering out parent classes; left out with " + classes);

    return classes;
}

From source file:cat.albirar.framework.proxy.ProxyFactory.java

/**
 * Create a proxy for the indicated type, tied to the indicated type.
 * @param handler The handler, required//from  w  ww .ja  v  a2  s.  c  o m
 * @param type
 * @return the new type
 */
public <T> T newProxy(IProxyHandler handler, Class<T> type) {
    Assert.notNull(handler, "Handler is required");
    Assert.notNull(type, "Type is required");
    if (type.isInterface()) {
        return newProxyForInterface(new ProxyInvocationHandlerWrapper(handler), type);
    }
    return newProxyForConcreteClass(new ProxyInvocationHandlerWrapper(handler), type);
}

From source file:org.cloudifysource.restDoclet.exampleGenerators.DocDefaultExampleGenerator.java

private String generateJSON(final Type type) throws Exception {
    Class<?> clazz = ClassUtils.getClass(type.qualifiedTypeName());
    if (MultipartFile.class.getName().equals(clazz.getName())) {
        return "\"file content\"";
    }/*from www  .  j av a2  s.  c om*/
    if (clazz.isInterface()) {
        throw new InstantiationException("the given class is an interface [" + clazz.getName() + "].");
    }
    Object newInstance = null;
    if (clazz.isPrimitive()) {
        newInstance = PrimitiveExampleValues.getValue(clazz);
    }
    Class<?> classToInstantiate = clazz;
    if (newInstance == null) {
        newInstance = classToInstantiate.newInstance();
    }
    return new ObjectMapper().writeValueAsString(newInstance);
}

From source file:com.orange.mmp.api.ws.jsonrpc.SimpleMapSerializer.java

@SuppressWarnings("unchecked")
@Override/*from  ww w . j  a v a2s .  com*/
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    Map map = null;
    try {
        try {
            try {
                if (clazz.isInterface()) {
                    map = new java.util.HashMap();
                } else
                    map = (Map) clazz.newInstance();
            } catch (ClassCastException cce) {
                throw new UnmarshallException("invalid unmarshalling Class " + cce.getMessage());
            }
        } catch (IllegalAccessException iae) {
            throw new UnmarshallException("no access unmarshalling object " + iae.getMessage());
        }
    } catch (InstantiationException ie) {
        throw new UnmarshallException("unable to instantiate unmarshalling object " + ie.getMessage());
    }
    JSONObject jso = (JSONObject) o;
    Iterator keys = jso.keys();
    state.setSerialized(o, map);
    try {
        while (keys.hasNext()) {
            String key = (String) keys.next();
            map.put(key, ser.unmarshall(state, null, jso.get(key)));
        }
    } catch (JSONException je) {
        throw new UnmarshallException("Could not read map: " + je.getMessage());
    }

    return map;
}

From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java

private Class<?> findConcreteType(Element e, Class<?> type) {
    if (type.isInterface() && isAnnotationPresent(type, ConfigInterface.class)) {
        for (Class<?> implementation : registry.implementersOf(type)) {
            if (compare(e, implementation, configCache)) {
                return implementation;
            }//  ww  w . j a va 2  s . c  o m
        }
    } else if (compare(e, type, configCache)) {
        return type;
    }
    return null;
}

From source file:io.smartspaces.workbench.project.test.JunitTestClassDetector.java

/**
 * Is the class a JUnit test class?//w  w  w . jav a 2  s . c  o  m
 *
 * @param potentialTestClass
 *          the class to test
 * @param log
 *          the logger to use
 *
 * @return {@code true} if the class is testable and can be instantiated
 */
private boolean isTestClass(Class<?> potentialTestClass, Log log) {
    if (potentialTestClass.isInterface() || !classHasPublicConstructor(potentialTestClass, log)) {
        return false;
    }

    // Do not attempt to run tests on abstract test classes.
    if (Modifier.isAbstract(potentialTestClass.getModifiers())) {
        return false;
    }

    for (Method method : potentialTestClass.getMethods()) {
        if (method.isAnnotationPresent(Test.class)) {

            // No need to check any more if we have 1
            return true;
        }
    }

    return false;
}

From source file:org.gradle.platform.base.internal.registry.TypeModelRuleExtractor.java

protected ModelType<? extends U> determineImplementationType(ModelType<? extends T> type,
        TypeBuilderInternal<T> builder) {
    for (Class<?> internalView : builder.getInternalViews()) {
        if (!internalView.isInterface()) {
            throw new InvalidModelException(
                    String.format("Internal view '%s' must be an interface.", internalView.getName()));
        }//w w w . ja  v  a2 s .  c  o m
    }

    Class<? extends T> implementation = builder.getDefaultImplementation();
    if (implementation == null) {
        return null;
    }

    ModelType<? extends T> implementationType = ModelType.of(implementation);

    if (!baseImplementation.isAssignableFrom(implementationType)) {
        throw new InvalidModelException(String.format("%s implementation '%s' must extend '%s'.",
                StringUtils.capitalize(modelName), implementationType, baseImplementation));
    }

    ModelType<? extends U> asSubclass = implementationType.asSubtype(baseImplementation);
    if (!type.isAssignableFrom(asSubclass)) {
        throw new InvalidModelException(String.format("%s implementation '%s' must implement '%s'.",
                StringUtils.capitalize(modelName), asSubclass, type));
    }

    for (Class<?> internalView : builder.getInternalViews()) {
        if (!internalView.isAssignableFrom(implementation)) {
            throw new InvalidModelException(
                    String.format("%s implementation '%s' must implement internal view '%s'.",
                            StringUtils.capitalize(modelName), asSubclass, internalView.getName()));
        }
    }

    try {
        asSubclass.getRawClass().getConstructor();
    } catch (NoSuchMethodException nsmException) {
        throw new InvalidModelException(
                String.format("%s implementation '%s' must have public default constructor.",
                        StringUtils.capitalize(modelName), asSubclass));
    }

    return asSubclass;
}

From source file:de.vandermeer.execs.Skb_Exec.java

/**
 * Adds a set of service at runtime, as in all found SKB services that can be executed
 * @param set a set of services/*  w  w  w . ja va2  s  .c  o  m*/
 */
protected void addAllServices(Set<Class<?>> set) {
    for (Class<?> cls : set) {
        if (!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers())) {
            if (!this.byClass.containsValue(cls)) {
                this.byName.add(cls.getName());
            }
        }
    }
}

From source file:net.sf.jasperreports.export.CompositeExporterConfigurationFactory.java

/**
 * //  ww  w  .j a v a2s.c o m
 */
private final C getProxy(Class<?> clazz, InvocationHandler handler) {
    List<Class<?>> allInterfaces = new ArrayList<Class<?>>();

    if (clazz.isInterface()) {
        allInterfaces.add(clazz);
    } else {
        @SuppressWarnings("unchecked")
        List<Class<?>> lcInterfaces = ClassUtils.getAllInterfaces(clazz);
        allInterfaces.addAll(lcInterfaces);
    }

    @SuppressWarnings("unchecked")
    C composite = (C) Proxy.newProxyInstance(ExporterConfiguration.class.getClassLoader(),
            allInterfaces.toArray(new Class<?>[allInterfaces.size()]), handler);

    return composite;
}