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:net.sf.juffrou.reflect.JuffrouTypeConverterDelegate.java

private boolean canCreateCopy(Class requiredType) {
    return (!requiredType.isInterface() && !Modifier.isAbstract(requiredType.getModifiers())
            && Modifier.isPublic(requiredType.getModifiers()) && ClassUtils.hasConstructor(requiredType));
}

From source file:com.netspective.axiom.sql.Query.java

public void setValueBean(Class valueBean) throws IOException, ClassNotFoundException {
    if (!valueBean.isInterface())
        throw new RuntimeException("Value bean " + valueBean + " is not an interface");

    this.valueBean = valueBean;
    this.valueBeanGenerator = ValueBeanGeneratorClassLoader.getInstance(valueBean.getName() + "Impl",
            new Class[] { valueBean });
}

From source file:com.alibaba.dubbo.config.spring.AnnotationBean.java

private Object refer(Reference reference, Class<?> referenceClass) { //method.getParameterTypes()[0]
    String interfaceName;/*from   w  w  w. ja v  a2s .co  m*/
    if (!"".equals(reference.interfaceName())) {
        interfaceName = reference.interfaceName();
    } else if (!void.class.equals(reference.interfaceClass())) {
        interfaceName = reference.interfaceClass().getName();
    } else if (referenceClass.isInterface()) {
        interfaceName = referenceClass.getName();
    } else {
        throw new IllegalStateException(
                "The @Reference undefined interfaceClass or interfaceName, and the property type "
                        + referenceClass.getName() + " is not a interface.");
    }
    String key = reference.group() + "/" + interfaceName + ":" + reference.version();
    ReferenceBean<?> referenceConfig = referenceConfigs.get(key);
    if (referenceConfig == null) {
        referenceConfig = new ReferenceBean<Object>(reference);
        if (void.class.equals(reference.interfaceClass()) && "".equals(reference.interfaceName())
                && referenceClass.isInterface()) {
            referenceConfig.setInterface(referenceClass);
        }
        if (applicationContext != null) {
            referenceConfig.setApplicationContext(applicationContext);
            if (reference.registry() != null && reference.registry().length > 0) {
                List<RegistryConfig> registryConfigs = new ArrayList<RegistryConfig>();
                for (String registryId : reference.registry()) {
                    if (registryId != null && registryId.length() > 0) {
                        registryConfigs.add(
                                (RegistryConfig) applicationContext.getBean(registryId, RegistryConfig.class));
                    }
                }
                referenceConfig.setRegistries(registryConfigs);
            }
            if (reference.consumer() != null && reference.consumer().length() > 0) {
                referenceConfig.setConsumer((ConsumerConfig) applicationContext.getBean(reference.consumer(),
                        ConsumerConfig.class));
            }
            if (reference.monitor() != null && reference.monitor().length() > 0) {
                referenceConfig.setMonitor(
                        (MonitorConfig) applicationContext.getBean(reference.monitor(), MonitorConfig.class));
            }
            if (reference.application() != null && reference.application().length() > 0) {
                referenceConfig.setApplication((ApplicationConfig) applicationContext
                        .getBean(reference.application(), ApplicationConfig.class));
            }
            if (reference.module() != null && reference.module().length() > 0) {
                referenceConfig.setModule(
                        (ModuleConfig) applicationContext.getBean(reference.module(), ModuleConfig.class));
            }
            if (reference.consumer() != null && reference.consumer().length() > 0) {
                referenceConfig.setConsumer((ConsumerConfig) applicationContext.getBean(reference.consumer(),
                        ConsumerConfig.class));
            }
            try {
                referenceConfig.afterPropertiesSet();
            } catch (RuntimeException e) {
                throw (RuntimeException) e;
            } catch (Exception e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
        referenceConfigs.putIfAbsent(key, referenceConfig);
        referenceConfig = referenceConfigs.get(key);
    }
    return referenceConfig.get();
}

From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java

/**
 * Interfaces, enums, annotations, and abstract classes cannot be
 * instantiated.// w w  w .j av a 2s  .  c o m
 * 
 * @param actionClass
 *            class to check
 * @return returns true if the class cannot be instantiated or should be
 *         ignored
 */
protected boolean cannotInstantiate(Class<?> actionClass) {
    return actionClass.isAnnotation() || actionClass.isInterface() || actionClass.isEnum()
            || (actionClass.getModifiers() & Modifier.ABSTRACT) != 0 || actionClass.isAnonymousClass();
}

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

@SuppressWarnings("unchecked")
protected <T> T populateEntity(Class<T> entityClass, String shortName) {
    EntityType type = null;//w ww  .  j  a v a2s  . co m
    if (entityClass.isInterface()) {
        type = Model.getEntityType(entityClass.getName());
    } else {
        type = Model.getEntityType(entityClass);
    }
    return (T) populateEntity(type.getEntityName(), shortName);
}

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

@SuppressWarnings("unchecked")
protected <T> T getEntity(Class<T> entityClass, String shortName) {
    EntityType type = null;//w  w  w  .  j  a v a 2  s. co m
    if (entityClass.isInterface()) {
        type = Model.getEntityType(entityClass.getName());
    } else {
        type = Model.getEntityType(entityClass);
    }
    return (T) getEntity(type.getEntityName(), shortName);
}

From source file:org.geoserver.jdbcconfig.internal.DbMappings.java

@SuppressWarnings("unchecked")
public Set<PropertyType> getPropertyTypes(final Class<?> queryType, String propertyName) {
    checkArgument(queryType.isInterface(), "queryType should be an interface");

    propertyName = removeIndexes(propertyName);

    Set<PropertyType> matches = Sets.newHashSet();

    ClassMappings classMappings;//  ww  w.ja v a  2  s. co  m
    classMappings = ClassMappings.fromInterface((Class<? extends Info>) queryType);
    checkState(classMappings != null, "ClassMappings not found for " + queryType);
    Class<? extends Info>[] concreteInterfaces = classMappings.concreteInterfaces();

    for (Class<? extends Info> concreteType : concreteInterfaces) {
        Map<String, PropertyType> propTypes = getPropertyTypes(concreteType);
        if (null == propTypes) {
            continue;
        }
        if (Predicates.ANY_TEXT.getPropertyName().equals(propertyName)) {
            for (PropertyType propertyType : propTypes.values()) {
                if (propertyType.isText()) {
                    matches.add(propertyType);
                }
            }
        } else {
            PropertyType propertyType = propTypes.get(propertyName);
            if (null != propertyType) {
                matches.add(propertyType);
            }
        }
    }
    return matches;
}

From source file:org.grycap.gpf4med.ext.GraphConnectorManager.java

public ImmutableList<GraphConnectorInformation> getConnectorsInformation() {
    final ImmutableList.Builder<GraphConnectorInformation> builder = new ImmutableList.Builder<GraphConnectorInformation>();
    // get connectors      
    for (final Map.Entry<String, GraphConnector> connector : connectors().entrySet()) {
        try {//  w w w  .  j  ava  2  s .com
            // resource classes
            final Class<?> resourceDefinition = connector.getValue().restResourceDefinition();
            final Class<?> resourceImplementation = connector.getValue().restResourceImplementation();
            checkArgument(resourceDefinition.isAnnotationPresent(Path.class),
                    "No @Path annotation found, resource definition must be a REST resource");
            checkArgument(resourceDefinition.isInterface(), "Resource definition is not an interface");
            checkArgument(resourceDefinition.isAssignableFrom(resourceImplementation),
                    "Resource does not implements the definition");
            // path
            final String path = connector.getKey();
            checkArgument(path.equals(resourceDefinition.getAnnotation(Path.class).value()),
                    "Path does not coincide with with @Path annotation");
            checkArgument(path.matches(".*/v\\d+$"), "Path does not contain API version (e.g. resource/v1)");
            // version
            String version = null;
            List<String> items = new ArrayList<String>(
                    pluginInformation.getInformation(Information.VERSION, connector.getValue()));
            if (items != null && items.size() == 1) {
                version = formatVersion(items.get(0));
            } else {
                throw new IllegalStateException("Cannot find version");
            }
            // author
            String author = null;
            items = new ArrayList<String>(
                    pluginInformation.getInformation(Information.AUTHORS, connector.getValue()));
            if (items != null && items.size() > 0) {
                String authors = "";
                int i = 0;
                for (; i < items.size() - 1; i++) {
                    authors += items.get(i) + "; ";
                }
                authors += items.get(i);
                author = authors;
            }
            // package name
            String packageName = getPluginPackagename(connector.getValue());
            if (StringUtils.isNotBlank(packageName)) {
                packageName = FilenameUtils.getName(new URI(packageName).getPath());
            }
            // description
            String description = null;
            if (StringUtils.isNotBlank(connector.getValue().getDescription())) {
                description = connector.getValue().getDescription();
            }
            builder.add(new GraphConnectorInformation(path, resourceDefinition, resourceImplementation, version,
                    author, packageName, description));
        } catch (Exception e) {
            LOGGER.warn(
                    "Incomplete information found in the connector: " + connector.getClass().getCanonicalName(),
                    e);
        }
    }
    return builder.build();
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        ModelSchemaStore store, final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (isTarget(type)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }//from  ww w . j a va 2  s  .com
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass);
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition.java

@SuppressWarnings("unchecked")
void populateScanAlso(Set<Class<? extends IBase>> theScanAlso) {
    for (ScannedField next : myScannedFields) {
        if (IBase.class.isAssignableFrom(next.getElementType())) {
            if (next.getElementType().isInterface() == false
                    && Modifier.isAbstract(next.getElementType().getModifiers()) == false) {
                theScanAlso.add((Class<? extends IBase>) next.getElementType());
            }/*from  w w w.j a  v a2s. c o m*/
        }
        for (Class<? extends IBase> nextChildType : next.getChoiceTypes()) {
            if (nextChildType.isInterface() == false
                    && Modifier.isAbstract(nextChildType.getModifiers()) == false) {
                theScanAlso.add(nextChildType);
            }
        }
    }
}