List of usage examples for org.apache.commons.lang ClassUtils getAllSuperclasses
public static List<Class<?>> getAllSuperclasses(Class<?> cls)
Gets a List
of superclasses for the given class.
From source file:net.datenwerke.transloader.ClassWrapper.java
private static boolean classIsAssignableToType(Class rootClass, String typeName) { List allClasses = new ArrayList(); allClasses.add(rootClass);/*from w ww . j a v a 2 s . co m*/ allClasses.addAll(ClassUtils.getAllSuperclasses(rootClass)); allClasses.addAll(ClassUtils.getAllInterfaces(rootClass)); List allClassNames = ClassUtils.convertClassesToClassNames(allClasses); return allClassNames.contains(typeName); }
From source file:jenkins.authentication.tokens.api.AuthenticationTokenSource.java
/** * Score the goodness of match.//from w ww.j a va2 s.c o m * @param tokenClass the token class. * @param credentials the credentials instance. * @return the match score (higher the better) or {@code null} if not a match. * @since 1.1 */ /*package*/ final Integer score(Class<?> tokenClass, Credentials credentials) { if (!produces(tokenClass) || !consumes(credentials)) { return null; } short producerScore; if (this.tokenClass.equals(tokenClass)) { producerScore = Short.MAX_VALUE; } else { if (this.tokenClass.isInterface()) { // TODO compute a goodness of fit producerScore = 0; } else { producerScore = (short) ClassUtils.getAllSuperclasses(tokenClass).indexOf(this.tokenClass); } } short consumerScore; if (this.credentialsClass.equals(credentials.getClass())) { consumerScore = Short.MAX_VALUE; } else { if (this.credentialsClass.isInterface()) { // TODO compute a goodness of fit consumerScore = 0; } else { consumerScore = (short) ClassUtils.getAllSuperclasses(credentials.getClass()) .indexOf(this.credentialsClass); } } return ((int) producerScore) << 16 | (int) consumerScore; }
From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java
private static void findType(ConstructorDoc constr, Formatter formatter) throws Exception { Map<String, String> paramTags = new HashMap<String, String>(); for (ParamTag params : constr.paramTags()) { paramTags.put(params.parameterName(), params.parameterComment()); }//from w w w . ja v a 2s . c om boolean first = true; boolean array = false; for (Parameter p : constr.parameters()) { if (array) { throw new Exception( "Error: something after a dimensioned parameter: " + constr.name() + "." + p.name()); } if (p.type().dimension().length() > 0) { array = true; // throw new Exception("Error: Dimensioned parameter " + constr.name() + "." + p.name()); } if (first) { /* if (!"BatchRule".equals(constr.name())) { if (!Path.class.getName().equals(p.type().qualifiedTypeName()) || !p.name().equals("srcPath")) { throw new Exception("To be published in XML, a rule should have the first parameter (Path srcPath, while found (" + p.type().qualifiedTypeName() + " " + p.name() + " in " + constr.name()); } } */ } boolean foundType = false; if (String.class.getName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:String", array); foundType = true; } if (Property.class.getName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Property", array); foundType = true; } if (Resource.class.getName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Resource", array); foundType = true; } if (Graph.class.getName().equals(p.type().qualifiedTypeName())) { if (first && !p.name().startsWith("dstGraph")) { throw new Exception( "First parameter of type Graph is expected to start with dstGraph, while found (" + p.type().qualifiedTypeName() + " " + p.name() + " in " + constr.name()); } formatter.formatElementStart(p.name(), "ac:Graph", array); foundType = true; } if (Path.class.getName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Path", array); foundType = true; } if (Lang.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Lang", array); foundType = true; } if (Namespace.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Namespace", array); foundType = true; } if (VocabularyOfTerms.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:VocabularyOfTerms", array); foundType = true; } if (VocabularyOfPlaces.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:VocabularyOfPlaces", array); foundType = true; } if (VocabularyOfPeople.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:VocabularyOfPeople", array); foundType = true; } if (VocabularyOfTime.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:VocabularyOfTime", array); foundType = true; } if (p.name().equals("rule")) { Class ruleClass = Class.forName(p.type().qualifiedTypeName()); List superClasses = ClassUtils.getAllSuperclasses(ruleClass); if (!superClasses.contains(Rule.class)) { throw new Exception( "Error: Parameter 'rule' should be of class Rule o its subclasses, while found " + p.type().qualifiedTypeName()); } formatter.formatElementStart(p.name(), "ac:Rule", array); foundType = true; } if (XConverterFactory.MapObjectToObject.class.getCanonicalName().equals(p.type().qualifiedTypeName())) { formatter.formatElementStart(p.name(), "ac:Map", array); foundType = true; } if (paramTags.containsKey(p.name())) { formatter.formatDocumentation(paramTags.get(p.name())); } formatter.formatElementEnd(p.name()); if (!foundType) { throw new Exception("Error: parameter " + constr.name() + "." + p.name() + " of type " + p.typeName() + " that is not allowed in XML signatures"); } first = false; } }
From source file:com.haulmont.cuba.core.sys.listener.EntityListenerManager.java
protected List<String> getDeclaredListeners(Class<? extends Entity> entityClass) { List<String> listeners = new ArrayList<>(); List<Class> superclasses = ClassUtils.getAllSuperclasses(entityClass); Collections.reverse(superclasses); for (Class superclass : superclasses) { Set<String> set = dynamicListeners.get(superclass); if (set != null) { listeners.addAll(set);/* w ww.ja v a 2 s . c o m*/ } Listeners annotation = (Listeners) superclass.getAnnotation(Listeners.class); if (annotation != null) { listeners.addAll(Arrays.asList(annotation.value())); } } Set<String> set = dynamicListeners.get(entityClass); if (set != null) { listeners.addAll(set); } Listeners annotation = entityClass.getAnnotation(Listeners.class); if (annotation != null) { listeners.addAll(Arrays.asList(annotation.value())); } return listeners; }
From source file:org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.java
/** * Verify if a method has <code>@java.lang.Override()</code> annotation or if it is an inherited method * from an interface or a super class. The goal is to handle <code>{@inheritDoc}</code> tag. * * @param javaMethod not null//from w w w . j ava2 s . co m * @return <code>true</code> if the method is inherited, <code>false</code> otherwise. * @throws MojoExecutionException if any */ private boolean isInherited(JavaMethod javaMethod) throws MojoExecutionException, SecurityException { if (javaMethod.getAnnotations() != null) { for (int i = 0; i < javaMethod.getAnnotations().length; i++) { Annotation annotation = javaMethod.getAnnotations()[i]; if (annotation.toString().equals("@java.lang.Override()")) { return true; } } } Class<?> clazz = getClass(javaMethod.getParentClass().getFullyQualifiedName()); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); for (Class<?> intface : interfaces) { if (isInherited(intface, javaMethod)) { return true; } } List<Class<?>> classes = ClassUtils.getAllSuperclasses(clazz); for (Class<?> superClass : classes) { if (isInherited(superClass, javaMethod)) { return true; } } return false; }
From source file:org.jdal.ui.bind.ConfigurableBinderFactory.java
/** * Try to find a binder for a Class, use super Class if none is configured. * /* w w w. j a va 2s . c om*/ * @param clazz Class to looking for * @return a Binder for that class or null if none */ @SuppressWarnings({ "unchecked", "rawtypes" }) public PropertyBinder getBinder(Class<?> clazz) { Class<? extends PropertyBinder> binderClass = null; PropertyBinder binder = null; binderClass = binders.get(clazz); if (binderClass == null) { // try with superclasses List superclasses = ClassUtils.getAllSuperclasses(clazz); superclasses.addAll(ClassUtils.getAllInterfaces(clazz)); Iterator iter = superclasses.iterator(); while (iter.hasNext() && binderClass == null) { binderClass = binders.get(iter.next()); } } if (binderClass != null) { try { binder = binderClass.newInstance(); } catch (InstantiationException e) { log.error(e); } catch (IllegalAccessException e) { log.error(e); } } else { binder = new ControlBinder(controlAccessorFactory); } return binder; }
From source file:org.jdal.ui.bind.ConfigurableControlAccessorFactory.java
/** * {@inheritDoc}//from w ww . j a va 2s . c om */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ControlAccessor getControlAccessor(Object control) { Class<? extends ControlAccessor> accessorClass = null; ControlAccessor accessor = null; Class<? extends Object> clazz = control.getClass(); accessorClass = accessors.get(clazz); if (accessorClass == null) { // try with superclasses List superclasses = ClassUtils.getAllSuperclasses(clazz); superclasses.addAll(ClassUtils.getAllInterfaces(clazz)); Iterator iter = superclasses.iterator(); while (iter.hasNext() && accessorClass == null) { accessorClass = accessors.get(iter.next()); } } if (accessorClass != null) { try { Constructor<? extends ControlAccessor> ctor = accessorClass.getConstructor(Object.class); accessor = ctor.newInstance(control); } catch (InstantiationException e) { log.error(e); } catch (IllegalAccessException e) { log.error(e); } catch (SecurityException e) { log.error(e); } catch (NoSuchMethodException e) { log.error(e); } catch (IllegalArgumentException e) { log.error(e); } catch (InvocationTargetException e) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(baos)); log.error(baos); } } else { log.warn("Can't find a accessor for class: " + clazz.getName()); } return accessor; }
From source file:org.jdal.vaadin.ui.form.ConfigurableFieldFactory.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Object findByClass(Class<?> clazz, Map<Class<?>, ?> map) { Object target;// w w w . j a v a 2s. c o m target = map.get(clazz); if (target == null) { // try with superclasses List superclasses = ClassUtils.getAllSuperclasses(clazz); superclasses.addAll(ClassUtils.getAllInterfaces(clazz)); Iterator iter = superclasses.iterator(); while (iter.hasNext() && target == null) { target = map.get(iter.next()); } } return target; }
From source file:org.opencms.ui.CmsVaadinUtils.java
/** * Reads the declarative design for a component and localizes it using a messages object.<p> * * The design will need to be located in the same directory as the component's class and have '.html' as a file extension. * * @param component the component for which to read the design * @param messages the message bundle to use for localization * @param macros the macros to use on the HTML template *//* ww w. ja v a 2s. c o m*/ @SuppressWarnings("resource") public static void readAndLocalizeDesign(Component component, CmsMessages messages, Map<String, String> macros) { Class<?> componentClass = component.getClass(); List<Class<?>> classes = Lists.newArrayList(); classes.add(componentClass); classes.addAll(ClassUtils.getAllSuperclasses(componentClass)); InputStream designStream = null; for (Class<?> cls : classes) { if (cls.getName().startsWith("com.vaadin")) { break; } String filename = cls.getSimpleName() + ".html"; designStream = cls.getResourceAsStream(filename); if (designStream != null) { break; } } if (designStream == null) { throw new IllegalArgumentException("Design not found for : " + component.getClass()); } readAndLocalizeDesign(component, designStream, messages, macros); }
From source file:org.openengsb.core.persistence.internal.DefaultPersistenceIndex.java
@Override @SuppressWarnings("unchecked") public void indexObject(Class<?> bean, File beanLocation) { ObjectInfo objectInfo = new ObjectInfo(bean.getName(), beanLocation.toString()); List<Class<?>> allInterfaces = ClassUtils.getAllInterfaces(bean); for (Class<?> class1 : allInterfaces) { objectInfo.addType(class1); }//w w w .j a va 2s. c om List<Class<?>> allSuperClasses = ClassUtils.getAllSuperclasses(bean); for (Class<?> class1 : allSuperClasses) { if (isObjectClassToIgnore(class1)) { continue; } objectInfo.addType(class1); } objectInfo.addType(bean); synchronized (index) { index.add(objectInfo); } LOGGER.debug("Adding to index {}: {}", indexFile.toString(), objectInfo.toString()); }