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.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java

private Object convertFromMessage(MethodParameter parameter, Message<?> message) {
    Object payload = message.getPayload();
    Class<?> targetClass = parameter.getParameterType();
    if (targetClass.isInterface() || Modifier.isAbstract(targetClass.getModifiers())) {
        return payload;
    }/*from w  w w  .j  av a2 s  .c om*/

    if (this.converter instanceof GenericMessageAdapterConverter) {
        payload = convertJavaTypeFromMessage(message, parameter);
        validate(message, parameter, payload);
        return payload;
    }

    payload = convertClassFromMessage(message, targetClass);
    validate(message, parameter, payload);
    return payload;
}

From source file:com.jivesoftware.os.routing.bird.deployable.config.extractor.ConfigExtractor.java

public void writeDefaultsToFile(File outputFile) throws IOException {
    List<String> lines = new ArrayList<>();
    for (Class c : configClasses) {
        if (!c.isInterface()) {
            System.out.println("WARNING: class " + c
                    + " somehow made it into the list of config classes. It is being skipped.");
            continue;
        } else {// w w  w.j  a va  2s .c o m
            System.out.println("Building defaults for class:" + c.getName());
        }
        String classPrefix = propertyPrefix.propertyPrefix(c);
        Map<String, String> expected = new HashMap<>();
        Config config = new BindInterfaceToConfiguration<>(new MapBackConfiguration(expected), c).bind();
        config.applyDefaults();
        for (Map.Entry<String, String> entry : expected.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            String property = classPrefix + key + "=" + value;
            lines.add(property);
            System.out.println("\t" + property);
        }
    }
    FileUtils.writeLines(outputFile, "utf-8", lines, "\n", false);
}

From source file:org.atteo.moonshine.websocket.jsonmessages.HandlerDispatcher.java

public <T> SenderProvider<T> addSender(Class<T> klass) {
    checkState(klass.isInterface(), "Provided Class object must represent an interface");

    for (Method method : klass.getMethods()) {
        registerSenderMethod(method);/*from w  w  w. j  a v  a  2s .c om*/
    }
    @SuppressWarnings("unchecked")
    final Class<T> proxyClass = (Class<T>) Proxy.getProxyClass(Thread.currentThread().getContextClassLoader(),
            klass);

    class SenderInvocationHandler implements InvocationHandler {
        private final Session session;

        public SenderInvocationHandler(Session session) {
            this.session = session;
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            String request = encoderObjectMapper.writeValueAsString(args[0]);
            session.getBasicRemote().sendText(request);
            return null;
        }
    }

    return new SenderProvider<T>() {
        @Override
        public T get(Session session) {
            try {
                return proxyClass.getConstructor(new Class<?>[] { InvocationHandler.class })
                        .newInstance(new SenderInvocationHandler(session));
            } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
                    | IllegalArgumentException | InvocationTargetException ex) {
                throw new RuntimeException(ex);
            }
        }
    };
}

From source file:com.google.code.guice.repository.configuration.ScanningJpaRepositoryModule.java

@Override
protected void bindRepositories(RepositoryBinder binder) {
    for (RepositoriesGroup group : repositoriesGroups) {
        String persistenceUnitName = group.getPersistenceUnitName();

        Set<URL> urls = new HashSet<URL>();
        Collection<String> packagesToScan = group.getRepositoriesPackages();
        getLogger().info(String.format("Scanning %s for [%s]", packagesToScan, persistenceUnitName));

        for (String packageName : packagesToScan) {
            urls.addAll(ClasspathHelper.forPackage(packageName));
        }//  ww  w . j ava 2s . c o m

        Collection<Class<?>> repositoryClasses = findRepositories(urls);

        // Extraction of real Repository implementations (Classes)
        Collection<Class<?>> implementations = filter(repositoryClasses, new Predicate<Class<?>>() {
            @Override
            public boolean apply(Class<?> input) {
                return !input.isInterface();
            }
        });

        for (final Class<?> repositoryClass : repositoryClasses) {
            // Autobind only for interfaces matched with group filters/patterns
            if (repositoryClass.isInterface() && group.matches(repositoryClass)) {
                // Custom implementations
                Collection<Class<?>> repoImplementations = filter(implementations, new Predicate<Class<?>>() {
                    @Override
                    public boolean apply(Class<?> input) {
                        return repositoryClass.isAssignableFrom(input);
                    }
                });

                Iterator<Class<?>> iterator = repoImplementations.iterator();
                Class<?> implementation = iterator.hasNext() ? iterator.next() : null;
                getLogger().info(String.format("Found repository: [%s]", repositoryClass.getName()));
                binder.bind(repositoryClass).withCustomImplementation(implementation).to(persistenceUnitName);
            }
        }
    }
}

From source file:org.springframework.data.rest.core.projection.ProxyProjectionFactory.java

@Override
@SuppressWarnings("unchecked")
public <T> T createProjection(Object source, Class<T> projectionType) {

    Assert.isTrue(projectionType.isInterface(), "Projection type must be an interface!");

    if (source == null) {
        return null;
    }//from w w w .  j  av  a2 s.co m

    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(source);
    factory.setOpaque(true);
    factory.setInterfaces(projectionType, TargetClassAware.class);

    factory.addAdvice(new TargetClassAwareMethodInterceptor(source.getClass()));
    factory.addAdvice(getMethodInterceptor(source, projectionType));

    return (T) factory.getProxy();
}

From source file:com.github.philippn.springremotingautoconfigure.client.annotation.HttpInvokerProxyFactoryBeanRegistrar.java

protected void setupProxy(Class<?> clazz, BeanDefinitionRegistry registry) {
    Assert.isTrue(clazz.isInterface(), "Annotation @RemoteExport may only be used on interfaces");

    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .genericBeanDefinition(HttpInvokerProxyFactoryBean.class)
            .addPropertyValue("serviceInterface", clazz)
            .addPropertyValue("serviceUrl", getBaseUrl() + getMappingPath(clazz));

    registry.registerBeanDefinition(clazz.getSimpleName() + "Proxy", builder.getBeanDefinition());

    logger.info("Created HttpInvokerProxyFactoryBean for " + clazz.getSimpleName());
}

From source file:com.mmnaseri.dragonfly.runtime.repo.impl.CrudRepositoryContext.java

public CrudRepositoryContext(ClassLoader classLoader, String... basePackages) {
    //noinspection unchecked
    this.repositories = with(new EntityRepositoryLookupSource(classLoader).getClasses(basePackages))
            .keep(new Filter<Class>() {
                @Override//  w w  w  . j  a  v a 2 s.  c o  m
                public boolean accepts(Class item) {
                    return !item.equals(EntityRepository.class) && !item.equals(CrudRepository.class)
                            && item.isInterface();
                }
            }).list();
}

From source file:ClassVersionInfo.java

public ClassVersionInfo(String name, ClassLoader loader) throws ClassNotFoundException {
    this.name = name;
    Class c = loader.loadClass(name);
    CodeSource cs = c.getProtectionDomain().getCodeSource();
    if (cs != null)
        location = cs.getLocation();//w w  w.  j a v  a 2 s  . com
    if (c.isInterface() == false) {
        ObjectStreamClass osc = ObjectStreamClass.lookup(c);
        if (osc != null) {
            serialVersion = osc.getSerialVersionUID();
            try {
                c.getDeclaredField("serialVersionUID");
                hasExplicitSerialVersionUID = true;
            } catch (NoSuchFieldException e) {
                hasExplicitSerialVersionUID = false;
            }
        }
    }
}

From source file:org.jabsorb.serializer.impl.ReferenceSerializer.java

public boolean canSerialize(Class clazz, Class jsonClazz) {
    return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface()
            && (bridge.isReference(clazz) || bridge.isCallableReference(clazz))
            && (jsonClazz == null || jsonClazz == JSONObject.class));
}

From source file:plugins.ApiHelpInventory.java

private boolean isRessource(Class<?> javaClass) {

    // ignore interfaces and abstract classes
    if (javaClass.isInterface() || Modifier.isAbstract(javaClass.getModifiers())) {
        return false;
    }/*w  ww  .j a  v  a  2 s. c o m*/

    // check for @Path or @Provider annotation
    if (hasAnnotation(javaClass, Path.class)) {
        return true;
    }

    return false;
}