List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:com.agimatec.validation.jsr303.Jsr303MetaBeanFactory.java
/** * add the validation features to the metabean that come from jsr303 * annotations in the beanClass/* w w w . j a va 2 s . c o m*/ */ public void buildMetaBean(MetaBean metabean) { try { final Class<?> beanClass = metabean.getBeanClass(); processGroupSequence(beanClass, metabean); for (Class interfaceClass : beanClass.getInterfaces()) { processClass(interfaceClass, metabean); } // process class, superclasses and interfaces List<Class> classSequence = new ArrayList<Class>(); Class theClass = beanClass; while (theClass != null && theClass != Object.class) { classSequence.add(theClass); theClass = theClass.getSuperclass(); } // start with superclasses and go down the hierarchy so that // the child classes are processed last to have the chance to overwrite some declarations // of their superclasses and that they see what they inherit at the time of processing for (int i = classSequence.size() - 1; i >= 0; i--) { Class eachClass = classSequence.get(i); processClass(eachClass, metabean); } } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(e.getTargetException()); } }
From source file:org.nuunframework.cli.NuunCliPlugin.java
protected Specification<Class<?>> ancestorImplements(final Class<?> interfaceClass) { return new AbstractSpecification<Class<?>>() { @Override/*w ww . j a v a 2 s.c om*/ public boolean isSatisfiedBy(Class<?> candidate) { if (candidate == null) return false; boolean result = false; Class<?>[] allInterfacesAndClasses = getAllInterfacesAndClasses(candidate); for (Class<?> clazz : allInterfacesAndClasses) { if (!clazz.isInterface()) { for (Class<?> i : clazz.getInterfaces()) { if (i.equals(interfaceClass)) { result = true; break; } } } } return result; } }; }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Return the number of methods with a given name (with any argument types), * for the given class and/or its superclasses. Includes non-public methods. * @param clazz the clazz to check//from w w w . j ava2 s. c o m * @param methodName the name of the method * @return the number of methods with the given name */ public static int getMethodCountForName(Class<?> clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (Method method : declaredMethods) { if (methodName.equals(method.getName())) { count++; } } Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { count += getMethodCountForName(ifc, methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; }
From source file:org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter.java
public JavaClassToDBCConverter(Class serviceClass) { this.serviceClass = serviceClass; classes = new ArrayList<Class>(); establishClassHierarchy(serviceClass); establishInterfaceHierarchy(serviceClass.getInterfaces()); establishExceptionClasses(serviceClass); }
From source file:com.googlecode.ddom.weaver.reactor.Reactor.java
public ClassInfo getClassInfo(ClassRef classRef) { String className = classRef.getClassName(); ClassInfo classInfo = classInfos.get(className); if (classInfo != null) { return classInfo; } else {/*from ww w . ja va 2 s . com*/ WeavableClassInfoBuilder builder = weavableClassInfoBuilders.get(className); if (builder != null) { WeavableClassInfo weavableClassInfo = builder.build(this); weavableClassInfoBuilders.remove(className); weavableClasses.add(weavableClassInfo); classInfo = weavableClassInfo; } else { Class<?> clazz; try { clazz = classRef.load(); } catch (ClassNotFoundException ex) { throw new ReactorException("Class not found: " + classRef.getClassName()); } Class<?> superclass = clazz.getSuperclass(); Class<?>[] interfaces = clazz.getInterfaces(); ClassInfo[] interfaceInfos = new ClassInfo[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceInfos[i] = getClassInfo(new ClassRef(interfaces[i])); } Extensions extensions = new Extensions(); NonWeavableClassInfo nonWeavableClassInfo = new NonWeavableClassInfo(className, clazz.isInterface(), superclass == null ? null : getClassInfo(new ClassRef(clazz.getSuperclass())), interfaceInfos, extensions); for (ReactorPlugin plugin : plugins) { plugin.processNonWeavableClassInfo(nonWeavableClassInfo, clazz, extensions, this); } classInfo = nonWeavableClassInfo; } classInfos.put(className, classInfo); return classInfo; } }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeansGenerator.java
protected void createService(BeanDefinitionRegistry registry, ModelContext modelContext) throws NotFoundException, CannotCompileException { if (modelContext.getServiceDefinition() == null) { String newBeanClassName = modelContext.getGeneratedClassNamePrefix() + "Service"; String newBeanRegistryName = StringUtils.uncapitalize(newBeanClassName); String newBeanPackage = this.serviceBasePackage + '.'; // grab the generic types List<Class<?>> genericTypes = modelContext.getGenericTypes(); // extend the base service interface Class<?> newServiceInterface = JavassistUtil.createInterface(newBeanPackage + newBeanClassName, ModelService.class, genericTypes); ArrayList<Class<?>> interfaces = new ArrayList<Class<?>>(1); interfaces.add(newServiceInterface); // create a service implementation bean CreateClassCommand createServiceCmd = new CreateClassCommand( newBeanPackage + "impl." + newBeanClassName + "Impl", AbstractModelServiceImpl.class); createServiceCmd.setInterfaces(interfaces); createServiceCmd.setGenericTypes(genericTypes); createServiceCmd.addGenericType(modelContext.getRepositoryType()); HashMap<String, Object> named = new HashMap<String, Object>(); named.put("value", newBeanRegistryName); createServiceCmd.addTypeAnnotation(Named.class, named); // create and register a service implementation bean Class<?> serviceClass = JavassistUtil.createClass(createServiceCmd); AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(serviceClass).getBeanDefinition(); registry.registerBeanDefinition(newBeanRegistryName, def); // note in context as a dependency to a controller modelContext.setServiceDefinition(def); modelContext.setServiceInterfaceType(newServiceInterface); modelContext.setServiceImplType(serviceClass); } else {// ww w . j av a2 s .com Class<?> serviceType = ClassUtils.getClass(modelContext.getServiceDefinition().getBeanClassName()); // grab the service interface if (!serviceType.isInterface()) { Class<?>[] serviceInterfaces = serviceType.getInterfaces(); if (ArrayUtils.isNotEmpty(serviceInterfaces)) { for (Class<?> interfaze : serviceInterfaces) { if (ModelService.class.isAssignableFrom(interfaze)) { modelContext.setServiceInterfaceType(interfaze); break; } } } } Assert.notNull(modelContext.getRepositoryType(), "Found a service bean definition for " + modelContext.getGeneratedClassNamePrefix() + " but failed to figure out the service interface type."); } }
From source file:org.jboss.ejb3.locator.client.Ejb3ServiceLocator.java
/** * Adds the specified class and all superclasses to the cache of bound * objects//from w w w . ja va 2 s. c o m * * @param interfaze * @param obj */ private <T> void addInterfaceAndSuperinterfacesToCache(Class<T> interfaze, T obj) { // Ensure not already cached, escape if (!this.isObjectCached(interfaze)) { // Add the object to the list of objects implementing this // interface this.objectCache.put(interfaze, obj); } // Add all super interfaces recursively for (Class<T> superInterface : interfaze.getInterfaces()) { this.addInterfaceAndSuperinterfacesToCache(superInterface, obj); } }
From source file:com.freetmp.common.util.ClassUtils.java
public static int getMethodCountForName(Class<?> clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (Method method : declaredMethods) { if (methodName.equals(method.getName())) { count++;/*from ww w. j a v a 2s . co m*/ } } Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { count += getMethodCountForName(ifc, methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; }
From source file:org.sakaiproject.component.app.scheduler.SchedulerManagerImpl.java
private boolean doesImplementJobInterface(Class cl) { Class[] classArr = cl.getInterfaces(); for (int i = 0; i < classArr.length; i++) { if (classArr[i].getName().equals(JOB_INTERFACE) || classArr[i].getName().equals(STATEFULJOB_INTERFACE)) { return true; }//from w w w . j ava 2 s.c o m } return false; }
From source file:org.kuali.rice.ksb.api.bus.support.RestServiceDefinition.java
/** * does some simple validation of this RESTServiceDefinition * * @see org.kuali.rice.ksb.AbstractServiceDefinition.ServiceDefinition#validate() *//* w ww . j a va 2s . c o m*/ @Override public void validate() { List<Object> resources = getResources(); if (resources != null && !resources.isEmpty()) { resourceToClassNameMap = new DualHashBidiMap(); for (Object resource : resources) { // If there is no service set then we have to assume that it's the first resource if (getService() == null) { setService(resource); } Class<?> resourceClass = resource.getClass(); if (resourceClass != null) { Class<?>[] interfaces = null; if (resourceClass.isInterface()) { interfaces = new Class[1]; interfaces[0] = resourceClass; } else { interfaces = resourceClass.getInterfaces(); } if (interfaces != null) { for (Class<?> iface : interfaces) { Path pathAnnotation = (Path) iface.getAnnotation(Path.class); if (pathAnnotation != null) { String pathAnnotationValue = pathAnnotation.value(); String resourceId = pathAnnotationValue == null || pathAnnotationValue.equals("/") ? iface.getSimpleName() : pathAnnotationValue; resourceToClassNameMap.put(resourceId, iface.getName()); } else { // If no path annotation exists, use the simple class name resourceToClassNameMap.put(iface.getSimpleName(), iface.getName()); } } } } } } super.validate(); // if interface is null, set it to the service class if (getResourceClass() == null) { Class<?>[] interfaces = getService().getClass().getInterfaces(); if (interfaces != null && interfaces.length > 0) { setResourceClass(interfaces[0].getName()); } else { throw new ConfigurationException("resource class must be set to export a REST service"); } } // Validate that the JAX-WS annotated class / interface is available to the classloader. try { Class.forName(getResourceClass()); } catch (ClassNotFoundException e) { throw new ConfigurationException( "resource class '" + getResourceClass() + "' could not be found in the classpath"); } }