List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.nebulaframework.grid.cluster.manager.services.jobs.ClusterJobServiceImpl.java
public boolean findJobClass(Class<?> c, GridJobProfile profile, ClassLoader cl) { // If we have a executor for the interface if (executors.containsKey(c)) { // Attempt to Start GridJob boolean started = startExecution(executors.get(c), profile, cl); // If Success if (started) { return true; }//from w w w.jav a 2 s. com log.debug("Unable to Start GridJobManager for GridJob Type " + c.getName()); return false; } if (c.getSuperclass() != null) { if (findJobClass(c.getSuperclass(), profile, cl)) { return true; } } for (Class<?> clazz : c.getInterfaces()) { if (findJobClass(clazz, profile, cl)) { return true; } } return false; }
From source file:com.clarkparsia.empire.annotation.RdfGenerator.java
@SuppressWarnings("unchecked") private static <T> T getProxyOrDbObject(Object theAccessor, Class<T> theClass, Object theKey, DataSource theSource) throws Exception { long start = System.currentTimeMillis(); if (BeanReflectUtil.isFetchTypeLazy(theAccessor)) { // ========= start PATCH try {//from w ww .java2s . c o m // try to determine proper class from rdf:type T rdfObj = Empire.get().instance(theClass); asSupportsRdfId(rdfObj).setRdfId(asPrimaryKey(theKey)); theClass = determineClass(theClass, rdfObj, theSource, false); } catch (Exception ignore) { } // ========= end PATCH Proxy<T> aProxy = new Proxy<T>(theClass, asPrimaryKey(theKey), theSource); ProxyFactory aFactory = new ProxyFactory(); aFactory.setInterfaces(ObjectArrays.concat(theClass.getInterfaces(), EmpireGenerated.class)); if (!theClass.isInterface()) { aFactory.setSuperclass(theClass); } aFactory.setFilter(METHOD_FILTER); final ProxyHandler<T> aHandler = new ProxyHandler<T>(aProxy); Object aObj = aFactory.createClass(METHOD_FILTER).newInstance(); ((ProxyObject) aObj).setHandler(aHandler); return (T) aObj; } else { return fromRdf(theClass, asPrimaryKey(theKey), theSource); } }
From source file:org.callimachusproject.auth.AuthorizationManager.java
private void getAnnotationValues(Class<?> cls, Set<String> roles, Set<String> set) { for (Annotation ann : cls.getAnnotations()) { try {/*from w w w.j a va2 s .c o m*/ Method value = ann.annotationType().getMethod("value"); Iri iri = value.getAnnotation(Iri.class); if (iri != null && roles.contains(iri.value())) { Object obj = value.invoke(ann); if (obj instanceof String[]) { set.addAll(Arrays.asList((String[]) obj)); } } } catch (NoSuchMethodException e) { continue; } catch (IllegalAccessException e) { continue; } catch (IllegalArgumentException e) { logger.error(e.toString(), e); } catch (InvocationTargetException e) { logger.error(e.toString(), e); } } for (Class<?> face : cls.getInterfaces()) { getAnnotationValues(face, roles, set); } if (cls.getSuperclass() != null) { getAnnotationValues(cls.getSuperclass(), roles, set); } }
From source file:com.sun.faces.application.ApplicationImpl.java
public Converter createConverter(Class targetClass) { if (targetClass == null) { String message = Util.getExceptionMessageString(Util.NULL_PARAMETERS_ERROR_MESSAGE_ID); message = message + " targetClass " + targetClass; throw new NullPointerException(message); }/*from www . ja v a 2 s . com*/ Converter returnVal = (Converter) newThing(targetClass, converterTypeMap); if (returnVal != null) { if (log.isTraceEnabled()) { log.trace("Created converter of type " + returnVal.getClass().getName()); } return returnVal; } //Search for converters registered to interfaces implemented by //targetClass Class[] interfaces = targetClass.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { returnVal = createConverterBasedOnClass(interfaces[i]); if (returnVal != null) { if (log.isTraceEnabled()) { log.trace("Created converter of type " + returnVal.getClass().getName()); } return returnVal; } } } //Search for converters registered to superclasses of targetClass Class superclass = targetClass.getSuperclass(); if (superclass != null) { returnVal = createConverterBasedOnClass(superclass); if (returnVal != null) { if (log.isTraceEnabled()) { log.trace("Created converter of type " + returnVal.getClass().getName()); } return returnVal; } } return returnVal; }
From source file:org.compass.annotations.config.binding.AnnotationsMappingBinding.java
/** * Recursivly process the class to find all it's annotations. Lower level * class/interfaces with annotations will be added first. *//*from w w w. ja v a 2 s . c o m*/ private void processAnnotatedClass(Class<?> clazz) { if (clazz.equals(Class.class)) { return; } Class<?> superClazz = clazz.getSuperclass(); if (superClazz != null && !superClazz.equals(Object.class)) { processAnnotatedClass(superClazz); } Class<?>[] interfaces = clazz.getInterfaces(); for (Class<?> anInterface : interfaces) { processAnnotatedClass(anInterface); } SearchableConstant searchableConstant = clazz.getAnnotation(SearchableConstant.class); if (searchableConstant != null) { bindConstantMetaData(searchableConstant); } SearchableConstants searchableConstants = clazz.getAnnotation(SearchableConstants.class); if (searchableConstants != null) { for (SearchableConstant metaData : searchableConstants.value()) { bindConstantMetaData(metaData); } } SearchableDynamicMetaData searchableDynamicMetaData = clazz.getAnnotation(SearchableDynamicMetaData.class); if (searchableDynamicMetaData != null) { bindDynamicMetaData(searchableDynamicMetaData); } SearchableDynamicMetaDatas searchableDynamicMetaDatas = clazz .getAnnotation(SearchableDynamicMetaDatas.class); if (searchableDynamicMetaDatas != null) { for (SearchableDynamicMetaData metaData : searchableDynamicMetaDatas.value()) { bindDynamicMetaData(metaData); } } // handles recursive extends and the original extend if (clazz.isAnnotationPresent(Searchable.class)) { Searchable searchable = clazz.getAnnotation(Searchable.class); String[] extend = searchable.extend(); if (extend.length != 0) { ArrayList<String> extendedMappings = new ArrayList<String>(); if (classMapping.getExtendedAliases() != null) { extendedMappings.addAll(Arrays.asList(classMapping.getExtendedAliases())); } for (String extendedAlias : extend) { Alias extendedAliasLookup = valueLookup.lookupAlias(extendedAlias); if (extendedAliasLookup == null) { extendedMappings.add(extendedAlias); } else { extendedMappings.add(extendedAliasLookup.getName()); } } classMapping.setExtendedAliases(extendedMappings.toArray(new String[extendedMappings.size()])); } } // if the super class has Searchable annotation as well, add it to the list of extends ArrayList<Class> extendedClasses = new ArrayList<Class>(); if (clazz.getSuperclass() != null) { extendedClasses.add(clazz.getSuperclass()); } extendedClasses.addAll(Arrays.asList(clazz.getInterfaces())); for (Class<?> superClass : extendedClasses) { if (!superClass.isAnnotationPresent(Searchable.class)) { continue; } Searchable superSearchable = superClass.getAnnotation(Searchable.class); String alias = getAliasFromSearchableClass(superClass, superSearchable); HashSet<String> extendedMappings = new HashSet<String>(); if (classMapping.getExtendedAliases() != null) { extendedMappings.addAll(Arrays.asList(classMapping.getExtendedAliases())); } extendedMappings.add(alias); classMapping.setExtendedAliases(extendedMappings.toArray(new String[extendedMappings.size()])); } for (Field field : clazz.getDeclaredFields()) { for (Annotation annotation : field.getAnnotations()) { processsAnnotatedElement(clazz, field.getName(), "field", field.getType(), field.getGenericType(), annotation, field); } } for (Method method : clazz.getDeclaredMethods()) { if (!method.isSynthetic() && !method.isBridge() && !Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.getReturnType() != void.class && (method.getName().startsWith("get") || method.getName().startsWith("is"))) { for (Annotation annotation : method.getAnnotations()) { processsAnnotatedElement(clazz, ClassUtils.getShortNameForMethod(method), "property", method.getReturnType(), method.getGenericReturnType(), annotation, method); } } } }
From source file:org.apache.stratos.metadata.service.handlers.StratosAuthorizingHandler.java
/** * Goes through the class hierarchy and find the authorization annotations * attached to a certain/* w ww . ja v a 2 s .com*/ * method. * * @param clazz class to be scanned * @param authorizationActionMap the map to be populated */ private void findAuthorizationActions(Class<?> clazz, Map<String, String> authorizationActionMap) { if (clazz == null || clazz == Object.class) { return; } String classAuthorizationActionsAllowed = getAuthorizationActions(clazz.getAnnotations(), AUTHORIZATION_ANNOTATION_CLASS_NAME); for (Method m : clazz.getMethods()) { if (SKIP_METHODS.contains(m.getName())) { continue; } String methodAuthorizationActionsAllowed = getAuthorizationActions(m.getAnnotations(), AUTHORIZATION_ANNOTATION_CLASS_NAME); String authorizationActions = methodAuthorizationActionsAllowed != null ? methodAuthorizationActionsAllowed : classAuthorizationActionsAllowed; if (authorizationActions != null) { authorizationActionMap.put(m.getName(), authorizationActions); } } if (!authorizationActionMap.isEmpty()) { return; } findAuthorizationActions(clazz.getSuperclass(), authorizationActionMap); if (!authorizationActionMap.isEmpty()) { return; } for (Class<?> interfaceCls : clazz.getInterfaces()) { findAuthorizationActions(interfaceCls, authorizationActionMap); } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java
/** * @param clazz//from w w w .ja v a2 s .co m * the {@link Class} to check. * @param requiredClass * the name of {@link Class} that should be extended, or name of interface that should be * implemented. * * @return <code>true</code> if given {@link Class} extends <code>requiredClass</code> or * implements interface with this name. */ public static boolean isSuccessorOf(Class<?> clazz, String requiredClass) { if (clazz == null) { return false; } String clazzName = clazz.getName(); // check cache { IsSuccessorResult result = isSuccessorOf_checkCache(clazz, requiredClass); if (result == IsSuccessorResult.TRUE) { return true; } if (result == IsSuccessorResult.FALSE) { return false; } } // check this Class if (clazzName.equals(requiredClass)) { isSuccessorOf_addCache(clazz, requiredClass, IsSuccessorResult.TRUE); return true; } // check super-Class if (isSuccessorOf(clazz.getSuperclass(), requiredClass)) { isSuccessorOf_addCache(clazz, requiredClass, IsSuccessorResult.TRUE); return true; } // check interfaces for (Class<?> interfaceClass : clazz.getInterfaces()) { if (isSuccessorOf(interfaceClass, requiredClass)) { isSuccessorOf_addCache(clazz, requiredClass, IsSuccessorResult.TRUE); return true; } } // no, not required Class isSuccessorOf_addCache(clazz, requiredClass, IsSuccessorResult.FALSE); return false; }
From source file:com.tmind.framework.pub.utils.MethodUtils.java
public static Method findMethod(Class start, String methodName, int argCount, Class args[]) { // For overriden methods we need to find the most derived version. // So we start with the given class and walk up the superclass chain. for (Class cl = start; cl != null; cl = cl.getSuperclass()) { Method methods[] = getPublicDeclaredMethods(cl); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method == null) { continue; }/*www .ja v a2 s . c om*/ // skip static methods. int mods = method.getModifiers(); if (Modifier.isStatic(mods)) { continue; } // make sure method signature matches. Class params[] = method.getParameterTypes(); if (method.getName().equals(methodName) && params.length == argCount) { boolean different = false; if (argCount > 0) { for (int j = 0; j < argCount; j++) { if (params[j] != args[j]) { different = true; continue; } } if (different) { continue; } } return method; } } } // Now check any inherited interfaces. This is necessary both when // the argument class is itself an interface, and when the argument // class is an abstract class. Class ifcs[] = start.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { Method m = findMethod(ifcs[i], methodName, argCount); if (m != null) { return m; } } return null; }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Walk the interfaces of a class looking for a serializer for that * interface. Include any parent interfaces in the search also. * *///from www. j a va2 s .c o m private SerializerFactory getSerializerFactoryFromInterface(Class javaType, QName xmlType, TypeMapping tm) { SerializerFactory serFactory = null ; Class [] interfaces = javaType.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { Class iface = interfaces[i]; serFactory = (SerializerFactory) tm.getSerializer(iface, xmlType); if (serFactory == null) serFactory = getSerializerFactoryFromInterface(iface, xmlType, tm); if (serFactory != null) break; } } return serFactory; }
From source file:org.jabsorb.JSONRPCBridge.java
/** * Check whether a class is registered as a callable reference type. * * @param clazz The class object to check is a callable reference. * @return true if it is, false otherwise *///from w w w .j a va 2 s .c o m public boolean isCallableReference(Class clazz) { if (this == globalBridge) { return false; } if (!referencesEnabled) { return false; } if (callableReferenceSet.contains(clazz)) { return true; } // check if the class implements any interface that is // registered as a callable reference... Class[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (callableReferenceSet.contains(interfaces[i])) { return true; } } // check super classes as well... Class superClass = clazz.getSuperclass(); while (superClass != null) { if (callableReferenceSet.contains(superClass)) { return true; } superClass = superClass.getSuperclass(); } // should interfaces of each superclass be checked too??? // not sure... return globalBridge.isCallableReference(clazz); }