List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.apache.openjpa.util.ProxyManagerImpl.java
/** * Locate a concrete type to proxy for the given collection interface. *///from w w w.jav a 2s. com private static Class toConcreteType(Class intf, Map concretes) { Class concrete = (Class) concretes.get(intf); if (concrete != null) return concrete; Class[] intfs = intf.getInterfaces(); for (int i = 0; i < intfs.length; i++) { concrete = toConcreteType(intfs[i], concretes); if (concrete != null) return concrete; } return null; }
From source file:hu.netmind.beankeeper.modification.impl.ModificationTrackerImpl.java
/** * Set definite last modification serial for a class, and for all superclasses * and interfaces./* w ww.ja va2s . c om*/ */ private void setLastSerial(Class currentClass, Long serial) { if (currentClass == null) return; // Handle class lastSerialsByClass.put(currentClass, serial); // Superclass setLastSerial(currentClass.getSuperclass(), serial); // Interfaces Class interfaces[] = currentClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) setLastSerial(interfaces[i], serial); }
From source file:jef.database.DbUtils.java
/** * //w ww .j a v a 2s .c o m * * @param subclass * @param superclass * @return */ public static Type[] getTypeParameters(Class<?> subclass, Class<?> superclass) { if (superclass == null) {// ? if (subclass.getSuperclass() == Object.class && subclass.getInterfaces().length > 0) { superclass = subclass.getInterfaces()[0]; } else { superclass = subclass.getSuperclass(); } } Type type = GenericUtils.getSuperType(null, subclass, superclass); if (type instanceof ParameterizedType) { return ((ParameterizedType) type).getActualTypeArguments(); } throw new RuntimeException("Can not get the generic param type for class:" + subclass.getName()); }
From source file:com.bfd.harpc.config.ServerConfig.java
/** * ??TProcessor/*from w w w . j a va 2s. c om*/ * <p> * * @param rpcMonitor * @param serverNode * @return TProcessor */ @SuppressWarnings("rawtypes") protected TProcessor reflectProcessor(RpcMonitor rpcMonitor, ServerNode serverNode) { Class serviceClass = getRef().getClass(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = serviceClass.getInterfaces(); if (interfaces.length == 0) { throw new RpcException("Service class should implements Iface!"); } // ??,load "Processor"; TProcessor processor = null; for (Class clazz : interfaces) { String cname = clazz.getSimpleName(); if (!cname.equals("Iface")) { continue; } String pname = clazz.getEnclosingClass().getName() + "$Processor"; try { Class<?> pclass = classLoader.loadClass(pname); Constructor constructor = pclass.getConstructor(clazz); processor = (TProcessor) constructor .newInstance(getProxy(classLoader, clazz, getRef(), rpcMonitor, serverNode)); } catch (Exception e) { throw new RpcException("Refact error,please check your thift gen class!", e.getCause()); } } if (processor == null) { throw new RpcException("Service class should implements $Iface!"); } return processor; }
From source file:org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry.java
/** * Verifies if service class should be registered or not. * * @param appObject application object/*ww w .j av a 2 s. c o m*/ * @param appClass application class */ private void verifyApplicationRegistration(Object appObject, Class<?> appClass) { Class<?> managerClass = appObject.getClass(); Class<?>[] services = managerClass.getInterfaces(); List<Class<?>> classes = new ArrayList<>(); Collections.addAll(classes, services); if (!classes.contains(appClass)) { throw new RuntimeException("service class " + appClass.getName() + "is not being implemented by " + managerClass.getName()); } }
From source file:org.apache.hadoop.yarn.factories.impl.pb.RpcServerFactoryPBImpl.java
@Override public Server getServer(Class<?> protocol, Object instance, InetSocketAddress addr, Configuration conf, SecretManager<? extends TokenIdentifier> secretManager, int numHandlers, String portRangeConfig) { Constructor<?> constructor = serviceCache.get(protocol); if (constructor == null) { Class<?> pbServiceImplClazz = null; try {// w w w . j a v a 2s . co m pbServiceImplClazz = localConf.getClassByName(getPbServiceImplClassName(protocol)); } catch (ClassNotFoundException e) { throw new YarnRuntimeException( "Failed to load class: [" + getPbServiceImplClassName(protocol) + "]", e); } try { constructor = pbServiceImplClazz.getConstructor(protocol); constructor.setAccessible(true); serviceCache.putIfAbsent(protocol, constructor); } catch (NoSuchMethodException e) { throw new YarnRuntimeException("Could not find constructor with params: " + Long.TYPE + ", " + InetSocketAddress.class + ", " + Configuration.class, e); } } Object service = null; try { service = constructor.newInstance(instance); } catch (InvocationTargetException e) { throw new YarnRuntimeException(e); } catch (IllegalAccessException e) { throw new YarnRuntimeException(e); } catch (InstantiationException e) { throw new YarnRuntimeException(e); } Class<?> pbProtocol = service.getClass().getInterfaces()[0]; Method method = protoCache.get(protocol); if (method == null) { Class<?> protoClazz = null; try { protoClazz = localConf.getClassByName(getProtoClassName(protocol)); } catch (ClassNotFoundException e) { throw new YarnRuntimeException("Failed to load class: [" + getProtoClassName(protocol) + "]", e); } try { method = protoClazz.getMethod("newReflectiveBlockingService", pbProtocol.getInterfaces()[0]); method.setAccessible(true); protoCache.putIfAbsent(protocol, method); } catch (NoSuchMethodException e) { throw new YarnRuntimeException(e); } } try { return createServer(pbProtocol, addr, conf, secretManager, numHandlers, (BlockingService) method.invoke(null, service), portRangeConfig); } catch (InvocationTargetException e) { throw new YarnRuntimeException(e); } catch (IllegalAccessException e) { throw new YarnRuntimeException(e); } catch (IOException e) { throw new YarnRuntimeException(e); } }
From source file:gda.jython.accesscontrol.ProtectedMethodComponent.java
/** * Analyse the given class and add any methods annotated to be protected to the protectedMethods array. * /*from w w w. java2 s .com*/ * @param clazz */ @SuppressWarnings("rawtypes") private void analyseClass(Class clazz) { // loop over this classes methods Method[] newMethods = clazz.getMethods(); for (Method thisMethod : newMethods) { if (thisMethod.isAnnotationPresent(gda.jython.accesscontrol.MethodAccessProtected.class) && thisMethod.getAnnotation(MethodAccessProtected.class).isProtected()) { addMethod(thisMethod); } } // loop over the interfaces the class implements Class[] newInterfaces = clazz.getInterfaces(); for (Class thisInterface : newInterfaces) { // if its a new interface (for performance, ensure each interface only looked at once) if (!ArrayUtils.contains(analysedInterfaces, thisInterface)) { analysedInterfaces = (Class[]) ArrayUtils.add(analysedInterfaces, thisInterface); // check if any method in that interface is annotated that it should be protected for (Method method : thisInterface.getMethods()) { if (method.isAnnotationPresent(gda.jython.accesscontrol.MethodAccessProtected.class) && method.getAnnotation(MethodAccessProtected.class).isProtected()) { addMethod(method); } } } } }
From source file:com.phoenixnap.oss.ramlapisync.parser.SpringMvcResourceParser.java
/** * Gets a specified annotation from a class and optionally checks other types it inherits from * //from www . j a v a2s . c o m * @param clazz * @param annotation * @param inherit * @return */ private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotation, boolean inherit) { T foundAnnotation = clazz.getAnnotation(annotation); if (foundAnnotation == null && inherit) { for (Class<?> cInterface : clazz.getInterfaces()) { foundAnnotation = cInterface.getAnnotation(annotation); if (foundAnnotation != null) { return foundAnnotation; } } } return foundAnnotation; }
From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.java
@Override protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { if (persistentClass.getProxyInterface() == null) { // an entity, no // proxy/*from w w w.j a v a2 s .co m*/ return null; } final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass); final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName()); if (eclass == null && !persistentClass.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME)) { throw new HbMapperException("No eclass found for entityname: " + persistentClass.getEntityName()); } // get all the interfaces from the main class, add the real interface // first final Set<Class<?>> proxyInterfaces = new LinkedHashSet<Class<?>>(); final Class<?> pInterface = persistentClass.getProxyInterface(); if (pInterface != null && pInterface.isInterface()) { proxyInterfaces.add(pInterface); } Class<?> mappedClass = persistentClass.getMappedClass(); if (mappedClass == null) { mappedClass = DynamicEObjectImpl.class; } if (mappedClass.isInterface()) { proxyInterfaces.add(mappedClass); } proxyInterfaces.add(HibernateProxy.class); proxyInterfaces.add(TeneoInternalEObject.class); for (Class<?> interfaces : mappedClass.getInterfaces()) { proxyInterfaces.add(interfaces); } // iterate over all subclasses and add them also final Iterator<?> iter = persistentClass.getSubclassIterator(); while (iter.hasNext()) { final Subclass subclass = (Subclass) iter.next(); final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassClass = subclass.getMappedClass(); if (subclassProxy != null && subclassClass != null && !subclassClass.equals(subclassProxy)) { proxyInterfaces.add(subclassProxy); } } // get the idgettters/setters final Method theIdGetterMethod = idGetter == null ? null : idGetter.getMethod(); final Method theIdSetterMethod = idSetter == null ? null : idSetter.getMethod(); final Method proxyGetIdentifierMethod = theIdGetterMethod == null || pInterface == null ? null : ReflectHelper.getMethod(pInterface, theIdGetterMethod); final Method proxySetIdentifierMethod = theIdSetterMethod == null || pInterface == null ? null : ReflectHelper.getMethod(pInterface, theIdSetterMethod); ProxyFactory pf = Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); try { pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null); } catch (HbStoreException e) { log.warn("could not create proxy factory for:" + getEntityName(), e); pf = null; } return pf; }
From source file:com.springframework.core.annotation.AnnotationUtils.java
/** * Find a single {@link Annotation} of {@code annotationType} on the supplied * {@link Method}, traversing its super methods (i.e., from superclasses and * interfaces) if no annotation can be found on the given method itself. * <p>Correctly handles bridge {@link Method Methods} generated by the compiler. * <p>Meta-annotations will be searched if the annotation is not * <em>directly present</em> on the method. * <p>Annotations on methods are not inherited by default, so we need to handle * this explicitly./*from w ww . j a v a 2 s .c o m*/ * @param method the method to look for annotations on * @param annotationType the annotation type to look for * @return the matching annotation, or {@code null} if not found * @see #getAnnotation(Method, Class) */ @SuppressWarnings("unchecked") public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) { AnnotationCacheKey cacheKey = new AnnotationCacheKey(method, annotationType); A result = (A) findAnnotationCache.get(cacheKey); if (result == null) { Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method); result = findAnnotation((AnnotatedElement) resolvedMethod, annotationType); if (result == null) { result = searchOnInterfaces(method, annotationType, method.getDeclaringClass().getInterfaces()); } Class<?> clazz = method.getDeclaringClass(); while (result == null) { clazz = clazz.getSuperclass(); if (clazz == null || clazz.equals(Object.class)) { break; } try { Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); Method resolvedEquivalentMethod = BridgeMethodResolver.findBridgedMethod(equivalentMethod); result = findAnnotation((AnnotatedElement) resolvedEquivalentMethod, annotationType); } catch (NoSuchMethodException ex) { // No equivalent method found } if (result == null) { result = searchOnInterfaces(method, annotationType, clazz.getInterfaces()); } } if (result != null) { findAnnotationCache.put(cacheKey, result); } } return result; }