List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:com.payu.ratel.client.ContextAnnotationAutowireCandidateResolver.java
protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); TargetSource ts = new TargetSource() { @Override/*from w ww . j ava 2 s.c om*/ public Class<?> getTargetClass() { return descriptor.getDependencyType(); } @Override public boolean isStatic() { return false; } @Override public Object getTarget() { return beanFactory.doResolveDependency(descriptor, beanName, null, null); } @Override public void releaseTarget(Object target) { } }; ProxyFactory pf = new ProxyFactory(); pf.setTargetSource(ts); Class<?> dependencyType = descriptor.getDependencyType(); if (dependencyType.isInterface()) { pf.addInterface(dependencyType); } return pf.getProxy(beanFactory.getBeanClassLoader()); }
From source file:com.freiheit.fuava.ctprofiler.spring.ProfilingPostProcessor.java
private boolean isCandidateIface(final Class<?> cls) { if (cls == null || !cls.isInterface()) { return false; }/* ww w . ja va 2 s . c o m*/ for (final Pattern p : getPatterns()) { if (p.matcher(cls.getCanonicalName()).matches()) { return true; } } return false; }
From source file:org.openmhealth.schema.service.SchemaClassServiceImpl.java
@PostConstruct public void initializeSchemaIds() throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { Reflections reflections = new Reflections(SCHEMA_CLASS_PACKAGE); for (Class<? extends SchemaSupport> schemaClass : reflections.getSubTypesOf(SchemaSupport.class)) { if (schemaClass.isInterface() || Modifier.isAbstract(schemaClass.getModifiers())) { continue; }/* w w w . j a v a 2 s .c o m*/ SchemaId schemaId; if (schemaClass.isEnum()) { schemaId = schemaClass.getEnumConstants()[0].getSchemaId(); } else { Constructor<? extends SchemaSupport> constructor = schemaClass.getDeclaredConstructor(); constructor.setAccessible(true); schemaId = constructor.newInstance().getSchemaId(); } schemaIds.add(schemaId); } }
From source file:com.intelligentsia.dowsers.entity.serializer.EntityMapper.java
/** * Method that can be used to parse JSON to specified Java value, using * reader provided./*from w ww. j a v a 2 s .com*/ * * @param reader * @param valueType * @return * @throws DowsersException */ @SuppressWarnings("unchecked") public <T> T readValue(final Reader reader, final Class<T> valueType) throws DowsersException { if (valueType.isInterface() || Modifier.isAbstract(valueType.getModifiers())) { try { final EntityProxy entityProxy = mapper.readValue(reader, EntityProxy.class); return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { valueType, EntityProxyHandler.class }, entityProxy); } catch (final Throwable e) { throw new DowsersException(e); } } try { return mapper.readValue(reader, valueType); } catch (final Throwable e) { throw new DowsersException(e); } }
From source file:com.github.dozermapper.core.classmap.ClassMappings.java
private boolean isInterfaceImplementation(Class<?> type, Class<?> mappingType) { return mappingType.isInterface() && mappingType.isAssignableFrom(type); }
From source file:evyframework.common.ClassUtils.java
/** * Return all interfaces that the given class implements as Set, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be <code>null</code> when accepting all declared interfaces) * @return all interfaces that the given object implements as Set *//*from ww w. j av a2 s. c o m*/ @SuppressWarnings("rawtypes") public static Set<Class> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface() && isVisible(clazz, classLoader)) { return Collections.singleton(clazz); } Set<Class> interfaces = new LinkedHashSet<Class>(); while (clazz != null) { Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader)); } clazz = clazz.getSuperclass(); } return interfaces; }
From source file:org.ecloudmanager.tmrk.cloudapi.CloudapiEndpointFactory.java
/** * Create a new jax-rs client proxy. This method returns a new proxy instance * each time it is invoked./*from www . j a v a2s . com*/ * * @return endpoint service proxy instance * @throws CloudapiException if argument is not an interface */ public <T> T createEndpoint(Class<T> clazz) { if (clazz.isInterface()) { if (isOpen()) { return new EndpointProxyFactory<>(clazz).getInstance(); } else { throw new CloudapiException("Endpoint factory not open or closed."); } } else { throw new CloudapiException(clazz.getName() + " in not an interface, so cannot be proxied by JDK."); } }
From source file:com.liferay.portal.spring.extender.internal.bean.ServiceReferenceAnnotationBeanPostProcessor.java
protected void autoInject(Object targetBean, Class<?> beanClass) { if ((beanClass == null) || beanClass.isInterface()) { return;//from www . ja v a 2 s .com } Field[] fields = beanClass.getDeclaredFields(); for (Field field : fields) { ServiceReference serviceReference = field.getAnnotation(ServiceReference.class); if (serviceReference == null) { continue; } org.osgi.framework.ServiceReference<?> osgiServiceReference = null; try { String filterString = serviceReference.filterString(); if (filterString.isEmpty()) { Class<?> typeClass = serviceReference.type(); osgiServiceReference = _bundleContext.getServiceReference(typeClass.getName()); } else { Class<?> typeClass = serviceReference.type(); org.osgi.framework.ServiceReference<?>[] serviceReferences = _bundleContext .getServiceReferences(typeClass.getName(), filterString); if (serviceReferences != null) { osgiServiceReference = serviceReferences[0]; } } ReflectionUtils.makeAccessible(field); field.set(targetBean, _bundleContext.getService(osgiServiceReference)); } catch (Throwable t) { throw new BeanCreationException(beanClass.getName(), "Unable to inject bean reference fields", t); } _serviceReferences.add(osgiServiceReference); } autoInject(targetBean, beanClass.getSuperclass()); }
From source file:br.ufpr.gres.core.classpath.ClassDetails.java
/** * Verify if a class is testable// ww w.ja v a 2 s . c om * * @return Return true if a class is testable; otherwise false * @throws java.lang.ClassNotFoundException * @throws java.io.IOException */ public boolean isTestable() throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException { Class c = getClassInstance(); if (c.isInterface()) { logger.error("Can't apply mutation because " + className + " is 'interface'"); return false; } if (Modifier.isAbstract(c.getModifiers())) { logger.error("Can't apply mutation because " + className + " is 'abstract' class"); return false; } if (isGUI(c)) { logger.error("Can't apply mutation because " + className + " is 'GUI' class"); return false; } if (isApplet(c)) { logger.error("Can't apply mutation because " + className + " is 'applet' class"); return false; } return true; }
From source file:blue.lapis.pore.converter.wrapper.WrapperConverterTest.java
private Object create() { Class<?> base = interfaces.get(0); if (!base.isInterface() && Modifier.isFinal(base.getModifiers())) { if (base == Location.class) { return new Location(mock(Extent.class), 0, 0, 0); }/*from ww w . j av a2 s . c om*/ } Object mock; if (interfaces.size() == 1) { mock = mock(base); } else { mock = mock(base, withSettings().extraInterfaces( interfaces.subList(1, interfaces.size()).toArray(new Class<?>[interfaces.size() - 1]))); } // o.b.BlockState's subclasses break this test because of incongruencies between SpongeAPI and Bukkit // this code basically assures that a NullPointerException won't be thrown while converting if (base.getPackage().getName().startsWith("org.spongepowered.api.block.tileentity")) { Location loc = new Location(mock(Extent.class), 0, 0, 0); BlockState state = mock(BlockState.class); when(loc.getBlock()).thenReturn(state); when(((TileEntity) mock).getLocation()).thenReturn(loc); when(((TileEntity) mock).getBlock()).thenReturn(state); } return mock; }