List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java
/** * Sets the required interface count for the Java class. * * @param interfaceCount// ww w . j ava 2 s. c om * the required interface count for the Java class. * @return this object */ public ClassValidator interfaceCount(final int interfaceCount) { Validate.isTrue(interfaceCount >= 0, "The required interface count must be " + "a non-negative number"); if (getSubject() != null) { Class<?> javaClass = getSubject(); if (javaClass.getInterfaces().length != interfaceCount) { if (interfaceCount == 0) { this.addException("The Java class must not implement " + "any interfaces"); } else if (interfaceCount == 1) { this.addException("The Java class must implement " + "exactly 1 interface"); } else { this.addException(String.format("The Java class must implement " + "exactly %d interfaces", interfaceCount)); } } } return this; }
From source file:fr.putnami.pwt.plugin.spring.rpc.server.service.CommandServiceImpl.java
private void scanBean(Object bean, String name) { Class<?> implClass = bean.getClass(); if (AopUtils.isAopProxy(bean)) { implClass = AopUtils.getTargetClass(bean); }/*from w w w . j a v a 2 s. c o m*/ Service serviceAnnotation = AnnotationUtils.findAnnotation(implClass, Service.class); if (serviceAnnotation != null) { for (Class<?> inter : implClass.getInterfaces()) { this.injectService(inter, bean); } } }
From source file:com.wcs.base.util.StringUtils.java
private static boolean isClassOrInterface(Class objClass, String className) { if (objClass.getClass().getName().equals(className)) return true; Class[] classes = objClass.getInterfaces(); for (int i = 0; i < classes.length; i++) { if (classes[i].getName().equals("java.util." + className)) return true; }/*from w ww . ja va 2 s. c o m*/ return false; }
From source file:com.laidians.utils.ClassUtils.java
/** * ?<br/>//from w ww . j a v a2 s . c o m * 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 */ 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:com.manydesigns.elements.annotations.AnnotationsManager.java
public void addAnnotationMapping(String annotationName, String annotationImplName) { logger.debug("Mapping annotation {} to implemetation {}", annotationName, annotationImplName); Class annotationClass = ReflectionUtil.loadClass(annotationName); if (annotationClass == null) { logger.warn("Failed to load annotation class: {}", annotationName); return;//ww w .j av a 2s.com } if (!annotationClass.isAnnotation()) { logger.warn("Not an annotation: {}", annotationName); return; } Class annotationImplClass = ReflectionUtil.loadClass(annotationImplName); if (annotationImplClass == null) { logger.warn("Failed to load annotation implementation class: {}", annotationImplName); return; } if (!Arrays.asList(annotationImplClass.getInterfaces()).contains(annotationClass)) { logger.warn("Class {} not an implementation of {}", annotationImplName, annotationName); return; } annotationClassMap.put(annotationClass, annotationImplClass); logger.debug("Mapped annotation {} to implementation {}", annotationName, annotationImplName); }
From source file:com.flozano.socialauth.AbstractProvider.java
@Override public final void registerPlugins() throws Exception { LOG.info("Loading plugins"); List<String> pluginsList = getPluginsList(); if (pluginsList != null && !pluginsList.isEmpty()) { for (String s : pluginsList) { LOG.info("Loading plugin :: " + s); Class<? extends Plugin> clazz = Class.forName(s).asSubclass(Plugin.class); // getting constructor only for checking Constructor<? extends Plugin> cons = clazz.getConstructor(ProviderSupport.class); Class<?> interfaces[] = clazz.getInterfaces(); for (Class<?> c : interfaces) { if (Plugin.class.isAssignableFrom(c)) { pluginsMap.put(c.asSubclass(Plugin.class), clazz); }//from w w w . j ava 2s .c o m } } } }
From source file:org.jgentleframework.utils.ReflectUtils.java
/** * Returns all interfaces implemented by the class or interface represented * by the given class./*from ww w. j ava2 s .c om*/ * <p> * <b>Note:</b> Each interface signature will only occur once, even if it is * implemented in multiple classes or interfaces. * * @param clazz * the given class * @param superClass * if specifies <code>true</code>, returning {@link Set} of * interfaces will be included all interfaces implemented by * super class of the given class, otherwise, if specifies * <code>false</code>, the returned interfaces will be found only * on the given class. * @return an {@link Set} of interfaces implemented by the given class. */ public static Set<Class<?>> getAllInterfaces(Class<?> clazz, boolean superClass) { Set<Class<?>> temp = new LinkedHashSet<Class<?>>(); temp.addAll(Arrays.asList(clazz.getInterfaces())); Set<Class<?>> result = new LinkedHashSet<Class<?>>(); while (temp.size() != 0) { for (Class<?> obj : temp) { if (!result.contains(obj)) { result.add(obj); } } Set<Class<?>> current = new LinkedHashSet<Class<?>>(); current.addAll(temp); temp.clear(); for (Class<?> obj : current) { temp.addAll(Arrays.asList(obj.getInterfaces())); } } if (superClass == true) { List<Class<?>> superClassList = ReflectUtils.getAllSuperClass(clazz, false); for (Class<?> scl : superClassList) { Set<Class<?>> sclInterfaces = ReflectUtils.getAllInterfaces(scl, false); for (Class<?> sclinterface : sclInterfaces) { if (!result.contains(sclinterface)) { result.add(sclinterface); } } } } return result; }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Does the given class and/or its superclasses at least have one or more * methods (with any argument types)? Includes non-public methods. * @param clazz the clazz to check// w w w. j a va2 s . c o m * @param methodName the name of the method * @return whether there is at least one method with the given name */ public static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); Method[] declaredMethods = clazz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { Method method = declaredMethods[i]; if (method.getName().equals(methodName)) { return true; } } Class[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { if (hasAtLeastOneMethodWithName(ifcs[i], methodName)) { return true; } } return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName)); }
From source file:org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.java
/** * Implementation for {@link #getDescription(AstEditor, Class)}. *//* ww w .jav a2 s . c o m*/ private static ComponentDescription getDescription0(AstEditor editor, Class<?> componentClass) throws Exception { // we should use component class that can be loaded, for example ignore anonymous classes for (;; componentClass = componentClass.getSuperclass()) { String componentClassName = componentClass.getName(); // stop if not an inner class int index = componentClassName.indexOf('$'); if (index == -1) { break; } // stop if anonymous implementation of some interface if (componentClass.getInterfaces().length != 0) { break; } // stop if not an anonymous class String innerPart = componentClassName.substring(index + 1); if (!StringUtils.isNumeric(innerPart)) { break; } } // OK, get description ComponentDescriptionKey key = new ComponentDescriptionKey(componentClass); return getDescription0(editor, key, ImmutableList.<ClassResourceInfo>of()); }
From source file:org.atemsource.atem.impl.pojo.PojoEntityTypeRepository.java
protected void initializeEntityType(AbstractEntityType entityType) { entityType.setMetaType(entityTypeCreationContext.getEntityTypeReference(EntityType.class)); Class clazz = entityType.getEntityClass(); Class superclass = clazz.getSuperclass(); if (clazz.isInterface() && clazz.getInterfaces().length == 1) { // TODO workaround for interface inheritance hierachy (Attribute) superclass = clazz.getInterfaces()[0]; }//from w w w.j a va 2 s . com if (superclass != null && !superclass.equals(Object.class)) { final EntityType superType = getEntityTypeReference(superclass); entityType.setSuperEntityType(superType); // TODO this only works for AbstractEntityType but actually should // work for all. if (superType instanceof AbstractEntityType) { ((AbstractEntityType) superType).addSubEntityType(entityType); } } addAttributes(entityType); attacheServicesToEntityType(entityType); entityType.initializeIncomingAssociations(entityTypeCreationContext); entityTypeCreationContext.lazilyInitialized(entityType); }