List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:net.bioclipse.structuredb.persistency.dao.FetchIntroductionInterceptor.java
@SuppressWarnings("unchecked") public boolean implementsInterface(Class intf) { return intf.isInterface() && FetchExecutor.class.isAssignableFrom(intf); }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return all interfaces that the given class implements as array, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyse 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 array *//*from w w w .j a v a2 s. c o m*/ public static Class[] getAllInterfacesForClass(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface()) { return new Class[] { clazz }; } List interfaces = new ArrayList(); while (clazz != null) { for (int i = 0; i < clazz.getInterfaces().length; i++) { Class ifc = clazz.getInterfaces()[i]; if (!interfaces.contains(ifc) && (classLoader == null || isVisible(ifc, classLoader))) { interfaces.add(ifc); } } clazz = clazz.getSuperclass(); } return (Class[]) interfaces.toArray(new Class[interfaces.size()]); }
From source file:com.jeeframework.util.classes.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 analyse 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 *///w ww. j a v a 2 s . c om public static Set getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface()) { return Collections.singleton(clazz); } Set interfaces = new LinkedHashSet(); while (clazz != null) { for (int i = 0; i < clazz.getInterfaces().length; i++) { Class ifc = clazz.getInterfaces()[i]; if (classLoader == null || isVisible(ifc, classLoader)) { interfaces.add(ifc); } } clazz = clazz.getSuperclass(); } return interfaces; }
From source file:net.kamhon.ieagle.vo.ManagerList.java
public ManagerList() { try {/* www . j a v a 2 s. c o m*/ Set<String> clazzStr = ReflectionUtil.findFileNames("com", true, "net.kamhon.+?\\.manager\\..+?"); for (String str : clazzStr) { Class<?> clazz = Class.forName(str); if (clazz.isInterface()) { add((str.substring(str.lastIndexOf(".") + 1).charAt(0) + "").toLowerCase() + str.substring(str.lastIndexOf(".") + 2)); log.info(str.substring(str.lastIndexOf(".") + 1)); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.oltpbenchmark.util.ClassUtil.java
/** * Get a set of all of the interfaces that the element_class implements * @param element_class//from w w w . j av a2 s . c om * @return */ @SuppressWarnings("unchecked") public static Collection<Class<?>> getInterfaces(Class<?> element_class) { Set<Class<?>> ret = ClassUtil.CACHE_getInterfaceClasses.get(element_class); if (ret == null) { // ret = new HashSet<Class<?>>(); // Queue<Class<?>> queue = new LinkedList<Class<?>>(); // queue.add(element_class); // while (!queue.isEmpty()) { // Class<?> current = queue.poll(); // for (Class<?> i : current.getInterfaces()) { // ret.add(i); // queue.add(i); // } // FOR // } // WHILE ret = new HashSet<Class<?>>(ClassUtils.getAllInterfaces(element_class)); if (element_class.isInterface()) ret.add(element_class); ret = Collections.unmodifiableSet(ret); ClassUtil.CACHE_getInterfaceClasses.put(element_class, ret); } return (ret); }
From source file:gr.interamerican.bo2.utils.JavaBeanUtils.java
/** * Finds the properties of a bean.// w w w .ja va2 s . com * * <li>If the bean is a concrete class the properties of the bean, for which * there exists a setter method, a getter method or both. Properties of * super-types are returned as well.</li> * * <li>If the bean is an abstract class, an empty array is returned</li> * * <li>If the bean is an interface, the properties of the bean are returned. * The method also queries all super-interfaces and fetches their properties * as well.</li> * * @param type * the bean * @return Returns the property descriptors of a java bean. * * TODO: Support properties of abstract classes. */ public static PropertyDescriptor[] getBeansProperties(Class<?> type) { ArrayList<PropertyDescriptor> propertyDescriptor = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor p : PropertyUtils.getPropertyDescriptors(type)) { if (!propertyDescriptor.contains(p) && !p.getName().equals("class")) { //$NON-NLS-1$ propertyDescriptor.add(p); } } if (type.isInterface()) { Class<?>[] classArray = type.getInterfaces(); PropertyDescriptor[] pdArray; for (Class<?> next : classArray) { pdArray = getBeansProperties(next); for (PropertyDescriptor pd : pdArray) { if (!propertyDescriptor.contains(pd)) { propertyDescriptor.add(pd); } } } } return propertyDescriptor.toArray(new PropertyDescriptor[0]); }
From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebJavaTypeMetadata.java
public SpringWebJavaTypeMetadata(Class<?> javaType) { isTrue(javaType.isInterface(), "Your type must be a Java interface."); isTrue(javaType.getInterfaces().length <= 1, "Only single inheritance is supported."); RequestMapping mapping = AnnotatedElementUtils.getMergedAnnotation(javaType, RequestMapping.class); if (mapping != null) { isTrue(mapping.value().length <= 1, "Only single path is allowed."); isTrue(mapping.method().length == 0, "You must not set the HTTP method at the class level, only at the method level."); }/* w ww .ja va 2s . c o m*/ this.mapping = Optional.ofNullable(mapping).map(m -> new SpringWebRequestMappingMetadata(m)); this.javaType = javaType; this.parent = javaType.getInterfaces().length == 1 ? new SpringWebJavaTypeMetadata(javaType.getInterfaces()[0]) : null; }
From source file:com.abbhsoft.jpadaoframework.dao.advisor.FinderIntroductionInterceptor.java
public boolean implementsInterface(Class intf) { return intf.isInterface() && FinderExecutor.class.isAssignableFrom(intf); }
From source file:org.apache.crunch.impl.mr.run.TaskAttemptContextFactory.java
private TaskAttemptContextFactory() { Class implClass = TaskAttemptContext.class; if (implClass.isInterface()) { try {//from w w w .ja va2s .c o m implClass = Class.forName("org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl"); } catch (ClassNotFoundException e) { LOG.fatal("Could not find TaskAttemptContextImpl class, exiting", e); } } try { this.taskAttemptConstructor = implClass.getConstructor(Configuration.class, TaskAttemptID.class); } catch (Exception e) { LOG.fatal("Could not access TaskAttemptContext constructor, exiting", e); } }
From source file:org.blocks4j.reconf.client.factory.ConfigurationRepositoryElementFactory.java
private ConfigurationRepositoryElement createNewRepositoryFor(Class<?> arg) { if (!arg.isInterface()) { throw new ReConfInitializationError(msg.format("error.is.not.interface", arg.getCanonicalName())); }/*from w w w. jav a 2s . co m*/ if (!arg.isAnnotationPresent(ConfigurationRepository.class)) { return null; } ConfigurationRepository ann = arg.getAnnotation(ConfigurationRepository.class); ConfigurationRepositoryElement result = new ConfigurationRepositoryElement(); result.setProduct(ann.product()); result.setComponent(ann.component()); result.setConnectionSettings(configuration.getConnectionSettings()); result.setInterfaceClass(arg); result.setRate(ann.pollingRate()); result.setTimeUnit(ann.pollingTimeUnit()); result.setConfigurationItems(ConfigurationItemElement.from(result)); return result; }