List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.eclipse.emf.teneo.hibernate.mapping.eav.EAVObjectTuplizer.java
@Override protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { if (persistentClass.getClassName() == null) { // an entity, no proxy return null; }/*from w w w . j av a 2 s. c o m*/ final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass); final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName()); if (eclass == null) { 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) { proxyInterfaces.add(pInterface); } final Class<?> mappedClass = persistentClass.getMappedClass(); 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.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:org.drools.semantics.lang.dl.DL_9_CompilationTest.java
private void extractInterfaces(Class x, Set<String> l) { for (Class itf : x.getInterfaces()) { l.add(itf.getName());/* www .j a v a 2 s.c o m*/ extractInterfaces(itf, l); } }
From source file:org.apache.hadoop.hbase.io.FSDataInputStreamWrapper.java
/** * This will free sockets and file descriptors held by the stream only when the stream implements * org.apache.hadoop.fs.CanUnbuffer. NOT THREAD SAFE. Must be called only when all the clients * using this stream to read the blocks have finished reading. If by chance the stream is * unbuffered and there are clients still holding this stream for read then on next client read * request a new socket will be opened by Datanode without client knowing about it and will serve * its read request. Note: If this socket is idle for some time then the DataNode will close the * socket and the socket will move into CLOSE_WAIT state and on the next client request on this * stream, the current socket will be closed and a new socket will be opened to serve the * requests.//from w w w.ja v a2 s . c o m */ @SuppressWarnings({ "rawtypes" }) public void unbuffer() { FSDataInputStream stream = this.getStream(this.shouldUseHBaseChecksum()); if (stream != null) { InputStream wrappedStream = stream.getWrappedStream(); // CanUnbuffer interface was added as part of HDFS-7694 and the fix is available in Hadoop // 2.6.4+ and 2.7.1+ versions only so check whether the stream object implements the // CanUnbuffer interface or not and based on that call the unbuffer api. final Class<? extends InputStream> streamClass = wrappedStream.getClass(); if (this.instanceOfCanUnbuffer == null) { // To ensure we compute whether the stream is instance of CanUnbuffer only once. this.instanceOfCanUnbuffer = false; Class<?>[] streamInterfaces = streamClass.getInterfaces(); for (Class c : streamInterfaces) { if (c.getCanonicalName().toString().equals("org.apache.hadoop.fs.CanUnbuffer")) { try { this.unbuffer = streamClass.getDeclaredMethod("unbuffer"); } catch (NoSuchMethodException | SecurityException e) { if (isLogTraceEnabled) { LOG.trace("Failed to find 'unbuffer' method in class " + streamClass + " . So there may be a TCP socket connection " + "left open in CLOSE_WAIT state.", e); } return; } this.instanceOfCanUnbuffer = true; break; } } } if (this.instanceOfCanUnbuffer) { try { this.unbuffer.invoke(wrappedStream); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { if (isLogTraceEnabled) { LOG.trace("Failed to invoke 'unbuffer' method in class " + streamClass + " . So there may be a TCP socket connection left open in CLOSE_WAIT state.", e); } } } else { if (isLogTraceEnabled) { LOG.trace("Failed to find 'unbuffer' method in class " + streamClass + " . So there may be a TCP socket connection " + "left open in CLOSE_WAIT state. For more details check " + "https://issues.apache.org/jira/browse/HBASE-9393"); } } } }
From source file:com.bfd.harpc.config.ServerConfig.java
/** * ??iface/*from w ww.j av a2 s. co m*/ * <p> * * @return {@link Responder} */ @SuppressWarnings("rawtypes") protected Class reflectProtocolClass() { Class serviceClass = getRef().getClass(); Class<?>[] interfaces = serviceClass.getInterfaces(); if (interfaces.length == 0) { throw new RpcException("Service class should implements avro's interface!"); } // ?Responder for (Class clazz : interfaces) { try { clazz.getDeclaredField("PROTOCOL").get(null); return clazz; // return new SpecificResponder(clazz, ref); } catch (Exception e) { } } throw new RpcException("Service class should implements avro's interface!"); }
From source file:cn.aposoft.util.spring.ReflectionUtils.java
/** * Perform the given callback operation on all matching methods of the given * class and superclasses (or given interface and super-interfaces). * <p>//from ww w .ja v a 2s . c o m * The same named method occurring on subclass and superclass will appear * twice, unless excluded by the specified {@link MethodFilter}. * * @param clazz * the class to introspect * @param mc * the callback to invoke for each method * @param mf * the filter that determines the methods to apply the callback * to */ public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf) { // Keep backing up the inheritance hierarchy. Method[] methods = getDeclaredMethods(clazz); for (Method method : methods) { if (mf != null && !mf.matches(method)) { continue; } try { mc.doWith(method); } catch (IllegalAccessException ex) { throw new IllegalStateException("Not allowed to access method '" + method.getName() + "': " + ex); } } if (clazz.getSuperclass() != null) { doWithMethods(clazz.getSuperclass(), mc, mf); } else if (clazz.isInterface()) { for (Class<?> superIfc : clazz.getInterfaces()) { doWithMethods(superIfc, mc, mf); } } }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Does the given class or one of its superclasses at least have one or more * methods with the supplied name (with any argument types)? * Includes non-public methods./*from www . java 2 s .c o m*/ * @param clazz the clazz to check * @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) { org.springframework.util.Assert.notNull(clazz, "Class must not be null"); org.springframework.util.Assert.notNull(methodName, "Method name must not be null"); Method[] declaredMethods = clazz.getDeclaredMethods(); for (Method method : declaredMethods) { if (method.getName().equals(methodName)) { return true; } } Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { if (hasAtLeastOneMethodWithName(ifc, methodName)) { return true; } } return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName)); }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeanGeneratingRegistryPostProcessor.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 = modelContext.getBeansBasePackage() + ".service"; // 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 {/* w ww.j a v a 2 s . c o m*/ 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.apache.fineract.infrastructure.jobs.service.JobRegisterServiceImpl.java
private Object getBeanObject(final Class<?> classType) throws ClassNotFoundException { final List<Class<?>> typesList = new ArrayList<>(); final Class<?>[] interfaceType = classType.getInterfaces(); if (interfaceType.length > 0) { typesList.addAll(Arrays.asList(interfaceType)); } else {//www. jav a 2 s . c o m Class<?> superclassType = classType; while (!Object.class.getName().equals(superclassType.getSuperclass().getName())) { superclassType = superclassType.getSuperclass(); } typesList.add(superclassType); } final List<String> beanNames = new ArrayList<>(); for (final Class<?> clazz : typesList) { beanNames.addAll(Arrays.asList(this.applicationContext.getBeanNamesForType(clazz))); } Object targetObject = null; for (final String beanName : beanNames) { final Object nextObject = this.applicationContext.getBean(beanName); String targetObjName = nextObject.toString(); targetObjName = targetObjName.substring(0, targetObjName.lastIndexOf("@")); if (classType.getName().equals(targetObjName)) { targetObject = nextObject; break; } } return targetObject; }
From source file:org.eclipse.emf.teneo.ERuntime.java
/** * Walks through a interface inheritance structure and determines if a superclass is contained * if so then the class is added to the containedclasses *//*w w w.j a va2 s.c o m*/ private boolean isSelfOrSuperContained(Class<?> checkClass, ArrayList<Class<?>> containedClasses) { // assert (checkClass.isInterface()); if (containedClasses.contains(checkClass)) { return true; } final Class<?>[] interfaces = checkClass.getInterfaces(); for (Class<?> element : interfaces) { if (isSelfOrSuperContained(element, containedClasses)) { return true; } } return false; }
From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java
/** * Adds the class implements interface links. * //from w w w. java 2s.c o m * @param root the root * @param clazz the clazz * @param javaClass the java class */ private void addClassImplementsInterfaceLinks(final Context root, final Class<?> clazz, final JavaClass javaClass) { final Class<?>[] iFaces = clazz.getInterfaces(); for (final Class<?> iFace : iFaces) { final Package iFacePack = iFace.getPackage(); final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, iFacePack.getName()); // javaPackage.setCaption(iFacePack.getName()); final JavaInterface javaInterface = writer.addChildNode(javaPackage, JavaInterface.class, iFace.getName()); // javaInterface.setCaption(iFace.getName()); final ClassImplementsInterface link = writer.addLink(ClassImplementsInterface.class, javaClass, javaInterface); link.setTag(randomTag()); } }