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.googlecode.ddom.weaver.reactor.Reactor.java

public ClassInfo getClassInfo(ClassRef classRef) {
    String className = classRef.getClassName();
    ClassInfo classInfo = classInfos.get(className);
    if (classInfo != null) {
        return classInfo;
    } else {/*from  ww  w. j  a v  a 2  s. c o m*/
        WeavableClassInfoBuilder builder = weavableClassInfoBuilders.get(className);
        if (builder != null) {
            WeavableClassInfo weavableClassInfo = builder.build(this);
            weavableClassInfoBuilders.remove(className);
            weavableClasses.add(weavableClassInfo);
            classInfo = weavableClassInfo;
        } else {
            Class<?> clazz;
            try {
                clazz = classRef.load();
            } catch (ClassNotFoundException ex) {
                throw new ReactorException("Class not found: " + classRef.getClassName());
            }
            Class<?> superclass = clazz.getSuperclass();
            Class<?>[] interfaces = clazz.getInterfaces();
            ClassInfo[] interfaceInfos = new ClassInfo[interfaces.length];
            for (int i = 0; i < interfaces.length; i++) {
                interfaceInfos[i] = getClassInfo(new ClassRef(interfaces[i]));
            }
            Extensions extensions = new Extensions();
            NonWeavableClassInfo nonWeavableClassInfo = new NonWeavableClassInfo(className, clazz.isInterface(),
                    superclass == null ? null : getClassInfo(new ClassRef(clazz.getSuperclass())),
                    interfaceInfos, extensions);
            for (ReactorPlugin plugin : plugins) {
                plugin.processNonWeavableClassInfo(nonWeavableClassInfo, clazz, extensions, this);
            }
            classInfo = nonWeavableClassInfo;
        }
        classInfos.put(className, classInfo);
        return classInfo;
    }
}

From source file:org.itest.impl.ITestRandomObjectGeneratorImpl.java

protected Object fillCollection(Object o, Type type, Map<String, Type> map, ITestContext iTestContext) {
    ITestParamState iTestState = iTestContext.getCurrentParam();
    Collection<Object> col = (Collection<Object>) o;
    Class collectionClass;
    if (null != iTestContext.getCurrentParam()
            && null != iTestContext.getCurrentParam().getAttribute(ITestConstants.ATTRIBUTE_CLASS)) {
        collectionClass = iTestConfig.getITestValueConverter().convert(Class.class,
                iTestContext.getCurrentParam().getAttribute(ITestConstants.ATTRIBUTE_CLASS));
    } else {/*from w  ww.j  a  va2  s.com*/
        collectionClass = ITestTypeUtil.getRawClass(type);
    }
    if (!collectionClass.isInterface()) {
        col = (Collection<Object>) newInstance(collectionClass, iTestContext);
    } else {
        if (Set.class.isAssignableFrom(collectionClass)) {
            col = new HashSet<Object>();
        } else {
            col = new ArrayList<Object>();
        }
    }
    if (null == col) {
    } else {
        col.clear();
    }
    int size = random.nextInt(RANDOM_MAX - RANDOM_MIN) + RANDOM_MIN;
    if (null != iTestState && iTestState.getSizeParam() != null) {
        size = iTestState.getSizeParam();
    }

    Type elementType = ITestTypeUtil
            .getTypeProxy(ITestTypeUtil.getParameterType(type, Collection.class, 0, map), map);
    for (int i = 0; i < size; i++) {
        iTestContext.enter(col, String.valueOf(i));
        Object value;
        value = generateRandom(elementType, map, iTestContext);
        col.add(value);
        iTestContext.leave(value);
    }
    return col;
}

From source file:org.fastmongo.odm.dbobject.mapping.support.classname.ReflectionClassNameResolver.java

@Override
@SuppressWarnings("unchecked")
public String getClassName(Type type, DBObject dbObject, String classPrefix) {
    if (dbObject.containsField(CLASS_KEY)) {
        return restoreClassName((String) dbObject.get(CLASS_KEY), classPrefix);
    }/*from w  w w  . j  a  v a 2  s.c  o m*/

    Class clazz = (Class) type;

    String className = IMPLEMENTATION_BY_INTERFACE.get(clazz);
    if (className == null) {
        Set<Class<?>> subTypes = reflections.getSubTypesOf(clazz);
        if (subTypes.size() == 1) {
            className = subTypes.iterator().next().getName();
        } else {
            className = NO_IMPLEMENTATION;
        }
        IMPLEMENTATION_BY_INTERFACE.put(clazz, className);
    }

    if (!NO_IMPLEMENTATION.equals(className)) {
        return className;
    }

    ResolveStrategy resolveStrategy = findSuitableStrategy(clazz);
    if (resolveStrategy != null) {
        className = resolveStrategy.getClassName(clazz, dbObject);
        className = className.startsWith(classPrefix) ? className : restoreClassName(className, classPrefix);
    }

    if (StringUtils.isEmpty(className)) {
        if (!clazz.isInterface()) {
            return clazz.getName();
        }

        throw new IllegalArgumentException(String.format(
                "Can't find appropriate class name for '%s' and DBObject('%s') with classNamePrefix = %s", type,
                StringUtils.abbreviateMiddle(dbObject.toString(), "<...>", 100), classPrefix));
    }

    return className;
}

From source file:org.jgentleframework.core.factory.support.CoreProcessorImpl.java

@SuppressWarnings("unchecked")
@Override/*www.j a v  a 2 s  . c  o m*/
protected CachedConstructor createConstructionProxy(final CoreInstantiationSelector selector,
        Class<?> interfaze, net.sf.cglib.proxy.MethodInterceptor interceptor, final List<Method> methodList,
        MetaDefObject mdo) throws SecurityException, NoSuchMethodException {

    Assertor.notNull(interceptor, "The given interceptor must not be null !");
    Assertor.notNull(interceptor, "The given method list must not be null !");
    // Create
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(selector.getTargetClass());
    if (interfaze != null && interfaze.isAnnotation())
        enhancer.setInterfaces(new Class<?>[] { interfaze, Annotation.class, ReturnScopeName.class });
    else if (interfaze != null && interfaze.isInterface())
        enhancer.setInterfaces(new Class<?>[] { interfaze, ReturnScopeName.class });
    else {
        enhancer.setInterfaces(new Class<?>[] { ReturnScopeName.class });
    }
    final Method returnScopeNameMethod = ReturnScopeName.class.getDeclaredMethod("returnsScopeName");
    Callback[] callbacks = new Callback[] { NoOp.INSTANCE, interceptor,
            new ReturnScopeNameMethodInterceptor(selector.getScopeName()) };
    Class<? extends Callback>[] callbackTypes = new Class[] { NoOp.class,
            net.sf.cglib.proxy.MethodInterceptor.class, net.sf.cglib.proxy.MethodInterceptor.class };
    enhancer.setCallbackFilter(new CallbackFilter() {
        @Override
        public int accept(Method method) {

            if (methodList != null && methodList.contains(method) && !selector.getTargetClass().isAnnotation())
                return 1;
            else if (selector.getTargetClass().isAnnotation())
                return 1;
            else if (method.equals(returnScopeNameMethod))
                return 2;
            else
                return 0;
        }
    });
    enhancer.setCallbackTypes(callbackTypes);
    enhancer.setUseFactory(false);
    enhancer.setUseCache(true);
    enhancer.setNamingPolicy(new JGentleNamingPolicy());
    Class<?> proxied = enhancer.createClass();
    // Store callbacks.
    Enhancer.registerStaticCallbacks(proxied, callbacks);
    CachedConstructor cons = Utils.createConstructionProxy(selector.getDefinition(), proxied,
            selector.getArgTypes(), mdo);
    return cons;
}

From source file:org.apache.axis2.jaxws.framework.JAXWSDeployer.java

protected AxisServiceGroup deployClasses(String groupName, URL location, ClassLoader classLoader,
        List<String> classList)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxisFault {
    ArrayList<AxisService> axisServiceList = new ArrayList<AxisService>();
    // Get the hierarchical path of the service
    String serviceHierarchy = Utils.getServiceHierarchy(location.getPath(), this.directory);
    for (String className : classList) {
        Class<?> pojoClass;
        try {//from   www .j  ava 2  s.  c om
            pojoClass = Loader.loadClass(classLoader, className);
        } catch (Exception e) {
            continue;
        }
        WebService wsAnnotation = pojoClass.getAnnotation(WebService.class);
        WebServiceProvider wspAnnotation = null;
        if (wsAnnotation == null) {
            wspAnnotation = pojoClass.getAnnotation(WebServiceProvider.class);
        }

        // Create an Axis Service only if the class is not an interface and it has either 
        // @WebService annotation or @WebServiceProvider annotation.
        if ((wsAnnotation != null || wspAnnotation != null) && !pojoClass.isInterface()) {
            AxisService axisService;
            axisService = createAxisService(classLoader, className, location);
            if (axisService != null) {
                log.info("Deploying JAXWS annotated class " + className + " as a service - " + serviceHierarchy
                        + axisService.getName());
                axisServiceList.add(axisService);
            }
        }
    }
    int size = axisServiceList.size();
    if (size <= 0) {
        return null;
    }
    //creating service group by considering the hierarchical path also
    AxisServiceGroup serviceGroup = new AxisServiceGroup();
    serviceGroup.setServiceGroupName(serviceHierarchy + groupName);
    for (AxisService axisService : axisServiceList) {
        axisService.setName(serviceHierarchy + axisService.getName());
        serviceGroup.addService(axisService);
    }
    axisConfig.addServiceGroup(serviceGroup);
    configureAddressing(serviceGroup);
    return serviceGroup;
}

From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java

private void analyze(Collection<Class> classes, RegistryNodeModel model) throws IOException, JAXBException {
    Class service = null;//w  w  w .j  a va 2s  .  c om
    Class endpoint = null;
    for (Class clazz : classes) {
        if (clazz.isInterface() && clazz.isAnnotationPresent(WebService.class)) {
            service = clazz;
            if (!clazz.isAnnotationPresent(SOAPBinding.class))
                break;
        }
    }

    for (Class clazz : classes) {
        if (javax.xml.ws.Service.class.isAssignableFrom(clazz)) {
            endpoint = clazz;
            break;
        }
    }

    if (service == null)
        throw new BusinessFunctionException("Cannot find Service class");

    Wsdl wsdl = new Wsdl(endpoint, service);

    analyzeService(service.getDeclaredMethods(), model, wsdl);

    String name = SecurityHelper.generateRandomSequence(16);
    File temp = new File(FileUtils.getTempDirectory(), name);
    FileOutputStream stream = FileUtils.openOutputStream(temp);
    FileUtils.writeJAXB(wsdl, stream);
    IOUtils.closeQuietly(stream);

    saveResource(WSDL_SCHEME, model.getName() + ".sch", model, temp);
    FileUtils.forceDelete(temp);
}

From source file:org.apache.axis2.jaxws.framework.JAXWSDeployerSupport.java

/**
 * Deploy classes.//w w  w  .jav a  2  s .  c o  m
 * 
 * @param location
 *            the location
 * @param classLoader
 *            the class loader
 * @param classList
 *            the class list
 * @return the hash map
 * @throws ClassNotFoundException
 *             the class not found exception
 * @throws InstantiationException
 *             the instantiation exception
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws AxisFault
 *             the axis fault
 */
protected HashMap<String, AxisService> deployClasses(URL location, ClassLoader classLoader,
        List<String> classList)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxisFault {
    HashMap<String, AxisService> services = new HashMap<String, AxisService>();
    // Get the hierarchical path of the service

    String serviceHierarchy = Utils.getServiceHierarchy(location.getPath(), getDirectory());
    for (String className : classList) {
        Class<?> pojoClass;
        try {
            pojoClass = Loader.loadClass(classLoader, className);
        } catch (Exception e) {
            continue;
        }
        WebService wsAnnotation = pojoClass.getAnnotation(WebService.class);
        WebServiceProvider wspAnnotation = null;
        if (wsAnnotation == null) {
            wspAnnotation = pojoClass.getAnnotation(WebServiceProvider.class);
        }

        // Create an Axis Service only if the class is not an interface and
        // it has either
        // @WebService annotation or @WebServiceProvider annotation.
        if ((wsAnnotation != null || wspAnnotation != null) && !pojoClass.isInterface()) {
            AxisService axisService;
            axisService = createAxisService(classLoader, className, location);
            if (axisService != null) {
                log.info("Deploying JAXWS annotated class " + className + " as a service - " + serviceHierarchy
                        + axisService.getName());
                services.put(axisService.getName(), axisService);
            }
        }
    }
    return services;
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

public void setExtends(Class<?> cls) {
    if (cls.isInterface()) {
        throw new IllegalArgumentException("the class " + cls.getName() + " is a interface");
    }// ww w .  j a  va 2 s . co  m
    this.extendsClass = getJavaClassName(cls.getName());
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

public void addImplementsInterface(Class<?> s) {
    if (!s.isInterface()) {
        throw new IllegalArgumentException("class " + s.getName() + " is not a interface.");
    }//from   w  w w  .  j ava 2  s  .c  om
    if (implementsInterface == null) {
        implementsInterface = new String[] { s.getName() };
    } else {
        implementsInterface = (String[]) ArrayUtils.add(implementsInterface, s.getName());
    }
}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Create a new Instance of a 'Mapped' Property
 * @param name The name of the property/*from  w  ww  .  jav  a  2  s  .  co m*/
 * @param type The class of the property
 * @return The new value
 */
protected Object createMappedProperty(String name, Class type) {

    // Create the mapped object
    Object mappedProperty = null;

    if (type == null) {

        mappedProperty = defaultMappedProperty(name);

    } else if (type.isInterface()) {

        mappedProperty = defaultMappedProperty(name);

    } else if (Map.class.isAssignableFrom(type)) {
        try {
            mappedProperty = type.newInstance();
        } catch (Exception ex) {
            throw new IllegalArgumentException("Error instantiating mapped property of type '" + type.getName()
                    + "' for '" + name + "' " + ex);
        }
    } else {

        throw new IllegalArgumentException(
                "Non-mapped property of type '" + type.getName() + "' for '" + name + "'");
    }

    return mappedProperty;

}