List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:no.sesat.search.datamodel.DataModelFactoryImplTest.java
private void scan(final Class<? extends Annotation> type, final Class<?> cls, final Command command) throws IntrospectionException { LOG.info("scanning " + cls.getSimpleName()); final PropertyDescriptor[] properties = Introspector.getBeanInfo(cls).getPropertyDescriptors(); for (PropertyDescriptor property : properties) { final Class<?> propCls = property instanceof MappedPropertyDescriptor ? ((MappedPropertyDescriptor) property).getMappedPropertyType() : property.getPropertyType(); LOG.info(" checking property " + property.getName() + " [" + propCls.getSimpleName() + ']'); if (null != propCls.getAnnotation(type)) { command.execute(propCls);/*from www.j ava2 s .c om*/ } if (null != propCls.getAnnotation(DataNode.class)) { // also descend down dataNodes in the datamodel scan(type, propCls, command); } } // repeat again on all implemented interfaces for (Class<?> c : cls.getInterfaces()) { scan(type, c, command); } }
From source file:com.wingnest.play2.frames.plugin.orientdb.FramesOrientDBPlugin.java
private void maintainClasses(OrientGraph graph, Set<Class<?>> javaClasses, boolean bForVertex) { final OSchema schema = graph.getRawGraph().getMetadata().getSchema(); for (final Class<?> javaClass : javaClasses) { final String entityName = javaClass.getSimpleName(); {//www . j a v a2 s . c om if (!schema.existsClass(entityName)) { if (bForVertex) { FramesLogger.debug("Custom Vertex: %s", entityName); graph.createVertexType(entityName); } else { FramesLogger.debug("Custom Edge: %s", entityName); graph.createEdgeType(entityName); } } graphEntityMap.put(entityName, javaClass); } } for (final Class<?> javaClass : javaClasses) { final String entityName = javaClass.getSimpleName(); final OClass oClass = schema.getClass(entityName); OClass baseClass = bForVertex ? schema.getClass("V") : schema.getClass("E"); oClass.setSuperClass(baseClass); final Set<Class<?>> parentClasses = new HashSet<Class<?>>(); parentClasses.add(javaClass.getSuperclass()); parentClasses.addAll(Arrays.asList(javaClass.getInterfaces())); for (final Class<?> sclass : parentClasses) { if (javaClasses.contains(sclass)) { final OClass sClass = schema.getClass(sclass.getSimpleName()); oClass.setSuperClass(sClass); break; } } maintainProperties(oClass, javaClass); } }
From source file:com.google.dexmaker.ProxyBuilder.java
public Class<? extends T> buildProxyClass() throws IOException { Class<? extends T> proxyClass = null; synchronized (baseClass) { // we only populate the map with matching types proxyClass = (Class) generatedProxyClasses.get(baseClass); if (proxyClass != null && proxyClass.getClassLoader().getParent() == parentClassLoader && interfaces.equals(asSet(proxyClass.getInterfaces()))) { return proxyClass; // cache hit! }/*w ww.j a va2 s .com*/ // --------------------------------------------------------------------------------------- // ??class??class DexMaker dexMaker = new DexMaker(application); String generatedName = getMethodNameForProxyOf(baseClass); ClassLoader classLoader = dexMaker.getJarClassLoader(parentClassLoader, dexCache, generatedName); ArrayList<MethodEntity> entities = null; if (proxy.containsKey(generatedName)) { entities = proxy.get(generatedName); } else { entities = getObject(generatedName); if (null != entities) { proxy.put(generatedName, methods); } } Method[] methodsToProxy = null; if (classLoader == null || entities == null) { // the cache missed; generate the class TypeId<? extends T> generatedType = TypeId.get("L" + generatedName + ";"); TypeId<T> superType = TypeId.get(baseClass); generateConstructorsAndFields(dexMaker, generatedType, superType, baseClass); methodsToProxy = getMethodsToProxyRecursive(); generateCodeForAllMethods(dexMaker, generatedType, methodsToProxy, superType); dexMaker.declare(generatedType, generatedName + ".generated", PUBLIC, superType, getInterfacesAsTypeIds()); classLoader = dexMaker.generateAndLoad(parentClassLoader, dexCache, generatedName); setObject(generatedName, methods); proxy.put(generatedName, methods); } else { methodsToProxy = new Method[entities.size()]; int i = 0; for (MethodEntity entity : entities) { Method method = null; try { method = entity.clazz.getDeclaredMethod(entity.name, entity.params); } catch (NoSuchMethodException e) { e.printStackTrace(); } methodsToProxy[i++] = method; } } try { proxyClass = loadClass(classLoader, generatedName); } catch (IllegalAccessError e) { throw new UnsupportedOperationException("cannot proxy inaccessible class " + baseClass, e); } catch (ClassNotFoundException e) { throw new AssertionError(e); } catch (Exception e) { e.printStackTrace(); } setMethodsStaticField(proxyClass, methodsToProxy); generatedProxyClasses.put(baseClass, proxyClass); } return proxyClass; }
From source file:org.powertac.logtool.common.DomainObjectReader.java
private Object resolveArg(Type type, String arg) throws MissingDomainObject { // type can be null in a few cases - nothing to be done about it? if (null == type) { return null; }/*from w w w.jav a 2s.c om*/ // check for non-parameterized types if (type instanceof Class) { Class<?> clazz = (Class<?>) type; if (clazz.isEnum()) { return Enum.valueOf((Class<Enum>) type, arg); } else { return resolveSimpleArg(clazz, arg); } } // check for collection, denoted by leading ( if (type instanceof ParameterizedType) { ParameterizedType ptype = (ParameterizedType) type; Class<?> clazz = (Class<?>) ptype.getRawType(); boolean isCollection = false; if (clazz.equals(Collection.class)) isCollection = true; else { Class<?>[] ifs = clazz.getInterfaces(); for (Class<?> ifc : ifs) { if (ifc.equals(Collection.class)) { isCollection = true; break; } } } if (isCollection) { // expect arg to start with "(" log.debug("processing collection " + clazz.getName()); if (arg.charAt(0) != '(') { log.error("Collection arg " + arg + " does not start with paren"); return null; } // extract element type and resolve recursively Type[] tas = ptype.getActualTypeArguments(); if (1 == tas.length) { Class<?> argClazz = (Class<?>) tas[0]; // create an instance of the collection Collection<Object> coll; // resolve interfaces into actual classes if (clazz.isInterface()) clazz = ifImplementors.get(clazz); try { coll = (Collection<Object>) clazz.newInstance(); } catch (Exception e) { log.error("Exception creating collection: " + e.toString()); return null; } // at this point, we can split the string and resolve recursively String body = arg.substring(1, arg.indexOf(')')); String[] items = body.split(","); for (String item : items) { coll.add(resolveSimpleArg(argClazz, item)); } return coll; } } } // if we get here, no resolution log.error("unresolved arg: type = " + type + ", arg = " + arg); return null; }
From source file:no.sesat.search.datamodel.DataModelTest.java
private void collectProperties(final Class<?> cls, final Collection<Method> propertyMethods) throws IntrospectionException { final List<PropertyDescriptor> props = Arrays .asList(Introspector.getBeanInfo(cls).getPropertyDescriptors()); // = new ArrayList<PropertyDescriptor>(); // props.addAll(Arrays.asList(Introspector.getBeanInfo(cls, Introspector.IGNORE_ALL_BEANINFO).getPropertyDescriptors())); // Introspector.flushFromCaches(cls); // props.addAll(Arrays.asList(Introspector.getBeanInfo(cls, Introspector.USE_ALL_BEANINFO).getPropertyDescriptors())); // Introspector.flushFromCaches(cls); for (PropertyDescriptor property : props) { LOG.info(" property --> " + property.getName()); handleProperty(propertyMethods, property); if (property instanceof MappedPropertyDescriptor) { handleMappedProperty(propertyMethods, (MappedPropertyDescriptor) property); }/*from w w w . j ava 2s. c o m*/ } // repeat again on all implemented interfaces for (Class<?> c : cls.getInterfaces()) { collectProperties(c, propertyMethods); } }
From source file:com.mycila.plugin.Cglib2AopProxy.java
public Object getProxy(ClassLoader classLoader) { if (logger.isDebugEnabled()) { logger.debug("Creating CGLIB2 proxy: target source is " + this.advised.getTargetSource()); }/*from w w w. j av a 2s. co m*/ try { Class rootClass = this.advised.getTargetClass(); Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy"); Class proxySuperClass = rootClass; if (AopUtils.isCglibProxyClass(rootClass)) { proxySuperClass = rootClass.getSuperclass(); Class[] additionalInterfaces = rootClass.getInterfaces(); for (Class additionalInterface : additionalInterfaces) { this.advised.addInterface(additionalInterface); } } // Validate the class, writing log messages as necessary. validateClassIfNecessary(proxySuperClass); // Configure CGLIB Enhancer... Enhancer enhancer = createEnhancer(); if (classLoader != null) { enhancer.setClassLoader(classLoader); if (classLoader instanceof SmartClassLoader && ((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) { enhancer.setUseCache(false); } } enhancer.setSuperclass(proxySuperClass); enhancer.setStrategy(new UndeclaredThrowableStrategy(UndeclaredThrowableException.class)); enhancer.setInterfaces(AopProxyUtils.completeProxiedInterfaces(this.advised)); enhancer.setInterceptDuringConstruction(false); Callback[] callbacks = getCallbacks(rootClass); enhancer.setCallbacks(callbacks); enhancer.setCallbackFilter(new ProxyCallbackFilter(this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset)); Class[] types = new Class[callbacks.length]; for (int x = 0; x < types.length; x++) { types[x] = callbacks[x].getClass(); } enhancer.setCallbackTypes(types); // Generate the proxy class and create a proxy instance. Object proxy; if (this.constructorArgs != null) { proxy = enhancer.create(this.constructorArgTypes, this.constructorArgs); } else { proxy = enhancer.create(); } return proxy; } catch (CodeGenerationException ex) { throw new AopConfigException( "Could not generate CGLIB subclass of class [" + this.advised.getTargetClass() + "]: " + "Common causes of this problem include using a final class or a non-visible class", ex); } catch (IllegalArgumentException ex) { throw new AopConfigException( "Could not generate CGLIB subclass of class [" + this.advised.getTargetClass() + "]: " + "Common causes of this problem include using a final class or a non-visible class", ex); } catch (Exception ex) { // TargetSource.getTarget() failed throw new AopConfigException("Unexpected AOP exception", ex); } }
From source file:org.diorite.config.impl.ConfigTemplateImpl.java
private void scanInterface(@Nullable Class<?> type, LinkedList<MethodInvoker> methods) { if ((type == null) || (type == Config.class)) { return;//from w w w. j ava2 s.co m } for (Method method : type.getDeclaredMethods()) { MethodInvoker methodInvoker = new MethodInvoker(method); if (methodInvoker.isPrivate() && (methodInvoker.getParameterCount() == 0) && (methodInvoker.getReturnType() != void.class) && methodInvoker.isAnnotationPresent(Property.class)) { methods.add(methodInvoker); continue; } if (methodInvoker.isPublic()) { methods.add(methodInvoker); } if (methodInvoker.isAnnotationPresent(ToKeyMapperFunction.class) || methodInvoker.isAnnotationPresent(ToStringMapperFunction.class)) { methods.add(methodInvoker); } } for (Class<?> subType : type.getInterfaces()) { this.scanInterface(subType, methods); } }
From source file:org.castor.jaxb.reflection.ClassInfoBuilder.java
/** * Build the ClassInfo representation for a Class. * //from w w w. j ava 2 s. c o m * @param type * the Class to introspect * @return ClassInfo build from the Class */ public ClassInfo buildClassInfo(final Class<?> type) { if (type == null) { String message = "Argument type must not be null."; LOG.warn(message); throw new IllegalArgumentException(message); } if (!isDescribeable(type)) { if (LOG.isDebugEnabled()) { String message = "Class: " + type + " cannot be described using this builder."; LOG.debug(message); } return null; } if (LOG.isInfoEnabled()) { LOG.info("Now starting to build ClassInfo for: " + type); } ClassInfo classInfo = createClassInfo(javaNaming.getClassName(type)); JaxbClassNature jaxbClassNature = new JaxbClassNature(classInfo); jaxbClassNature.setType(type); jaxbClassNature.setSupertype(type.getSuperclass()); jaxbClassNature.setInterfaces(type.getInterfaces()); jaxbClassNature.setHasPublicEmptyConstructor(hasPublicEmptyConstructor(type)); Annotation[] unprocessedClassAnnotations = this.classAnnotationProcessingService .processAnnotations(jaxbClassNature, type.getAnnotations()); for (Field field : type.getDeclaredFields()) { if (LOG.isInfoEnabled()) { LOG.info("Now evaluating field: " + field); } if (isDescribeable(type, field)) { buildFieldInfo(classInfo, field); } else { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring field: " + field + " of type: " + type.getName() + " it is not useable for mapping."); } } } for (Method method : type.getDeclaredMethods()) { if (LOG.isInfoEnabled()) { LOG.info("Now evaluating method: " + method); } if (isDescribeable(type, method)) { buildFieldInfo(classInfo, method); } else { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring method: " + method + " of type: " + type.getName() + " it is not useable for mapping."); } } } PackageInfo pi = buildPackageInfo(type.getPackage()); classInfo.setPackageInfo(pi); if (LOG.isInfoEnabled()) { LOG.info("ClassInfo for: " + type + " build is: " + classInfo); } return classInfo; }
From source file:org.apache.ojb.broker.metadata.DescriptorRepository.java
/** * Internal method for recursivly searching for a class descriptor that avoids * class loading when we already have a class object. * * @param clazz The class whose descriptor we need to find * @return ClassDescriptor for <code>clazz</code> or <code>null</code> * if no ClassDescriptor could be located. *//*w w w .j a v a 2s. co m*/ private ClassDescriptor discoverDescriptor(Class clazz) { ClassDescriptor result = (ClassDescriptor) descriptorTable.get(clazz.getName()); if (result == null) { Class superClass = clazz.getSuperclass(); // only recurse if the superClass is not java.lang.Object if (superClass != null) { result = discoverDescriptor(superClass); } if (result == null) { // we're also checking the interfaces as there could be normal // mappings for them in the repository (using factory-class, // factory-method, and the property field accessor) Class[] interfaces = clazz.getInterfaces(); if ((interfaces != null) && (interfaces.length > 0)) { for (int idx = 0; (idx < interfaces.length) && (result == null); idx++) { result = discoverDescriptor(interfaces[idx]); } } } if (result != null) { descriptorTable.put(clazz.getName(), result); } } return result; }
From source file:SubClassMap.java
private static int getTypeDistance(Class<?> clazz, Class<?> subClass) { if (clazz == subClass) return 0; int dist = getTypeDistance(clazz, subClass.getSuperclass()); if (dist >= 0) return dist + 1; for (Class<?> intf : subClass.getInterfaces()) { dist = getTypeDistance(clazz, intf); if (dist >= 0) return dist + 1; }// ww w . j a v a 2 s .c o m return -1; }