/** * */ public String convertToString(Class<?> val) { return val==null? "": SReflect.getInnerClassName(val); } }
/** * Test if the processor is applicable. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return True, if is applicable. */ public boolean isApplicable(Object object, Type type, boolean clone, ClassLoader targetcl) { Class<?> clazz = SReflect.getClass(type); return SReflect.isSupertype(Enumeration.class, clazz); }
/** * Get the iterator. * @return The iterator. */ public java.util.Iterator<T> iterator() { return SReflect.getIterator(iter); } }
/** * Init caches if not initialized. */ private void init() { if (optionalClass == null) { optionalClass = SReflect.classForName0(OPTIONAL_CLASSNAME, null); ofMethod = SReflect.getMethod(optionalClass, "of", new Class[]{Object.class}); emptyMethod = SReflect.getMethod(optionalClass, "empty", new Class[]{}); getMethod = SReflect.getMethod(optionalClass, "get", new Class[]{}); isPresentMethod = SReflect.getMethod(optionalClass, "isPresent", new Class[]{}); } }
/** * Test if the processor is applicable. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return True, if is applicable. */ public boolean isApplicable(Object object, Type type, boolean clone, ClassLoader targetcl) { Class<?> clazz = SReflect.getClass(type); return clone && (object instanceof Cloneable) && !clazz.isArray() && (targetcl==null || clazz.equals(SReflect.classForName0(clazz.getName(), targetcl))); }
/** * Create a string representation. */ public String toString() { // return "ComponentFeatureFactory("+SReflect.getUnqualifiedClassName(type)+")"; return SReflect.getUnqualifiedClassName(type); } }
/** * Init the static methods. */ public static void init(ClassLoader classloader) { try { Class nug = SReflect.classForName("nuggets.Nuggets", classloader); otx = nug.getMethod("objectToXML", new Class[]{Object.class, ClassLoader.class}); ofx = nug.getMethod("objectFromXML", new Class[]{String.class, ClassLoader.class}); } catch(Exception e) { throw new RuntimeException("Nuggets not in classpath.", e); } }
/** * Find a class using imports. * @param name The class name. * @return The class. * @throws ClassNotFoundException when the class is not found in the imports. */ protected Class findClass(String name) throws ClassNotFoundException { return SReflect.findClass(name, imports, classloader); }
/** * Find a class using imports. * @param name The class name. * @return The class, or null if not found. */ protected Class findClass0(String name) { return SReflect.findClass0(name, imports, classloader); }
/** * */ public Object getReturnObject(Object object, Class<?> clazz, boolean clone, ClassLoader targetcl) { if(clazz!=null && targetcl!=null) clazz = SReflect.classForName0(SReflect.getClassName(clazz), targetcl); if(clazz==null) clazz = Object.class; int length = ((JsonArray)object).size(); return Array.newInstance(clazz, length); } }
/** * Tests if the decoder can decode the class. * @param clazz The class. * @return True, if the decoder can decode this class. */ public boolean isApplicable(Class<?> clazz) { return SReflect.isSupertype(InetAddress.class, clazz); }
/** * Get listener add method */ protected Method getAddMethod(Object object) { // Do not use Class.getMethod (slow). Method meth = SReflect.getMethod(object.getClass(), "addPropertyChangeListener", PCL); return meth; } }
/** * Get the rms codec info that needs to be used for encoding/decoding content. */ public Map<Class<?>, Object[]> getCodecInfo() { Map<Class<?>, Object[]> infos = new HashMap<Class<?>, Object[]>(); Object[] bininfo = new Object[]{getBinaryReadInfo(), getBinaryWriteInfo()}; infos.put(JadexBinaryContentCodec.class, bininfo); // Only use xml if jadex-xml module present (todo: remove compile time dependency) if(!SReflect.isAndroid() && SReflect.classForName0("jadex.xml.reader.Reader", getClass().getClassLoader())!=null) { Object[] xmlinfo = new Object[]{getXMLReadInfo(), getXMLWriteInfo()}; infos.put(JadexXMLContentCodec.class, xmlinfo); } return infos; }
/** * Get a method of the class. * Unlike {@link Class#getMethod(String, Class[])}, * this uses the methodcache. * @param clazz The class to search. * @param name The name of the method to search for. * @param types The parameter types. * @return The method (or null if not found). */ public static Method getMethod(Class clazz, String name, Class[] types) { Method meth = null; Method[] ms = getMethods(clazz, name); for(int i=0; i<ms.length; i++) { Class[] ptypes = ms[i].getParameterTypes(); boolean match = ptypes.length==types.length; for(int j=0; match && j<ptypes.length; j++) { match = ptypes[j].equals(types[j]); } if(match) { meth = ms[i]; break; } } return meth; }
/** * Extension for Class.forName(), because primitive * types are not supported. * Uses static cache to speed up lookup. * @param name The class name. * @return The class, or null if not found. */ public static Class<?> classForName0(String name, ClassLoader classloader) { return classForName0(name, true, classloader); }
Class<?>[] allinterfaces = SReflect.getSuperInterfaces(interfaces); SReflect.getMethod(allinterfaces[i], method.getName(), method.getParameterTypes())!=null)
Method[] ms = SReflect.getMethods(clazz, getText()); ArrayList ames = new ArrayList(); for(int i=0; i<ms.length; i++) int[] matches = SReflect.matchArgumentTypes(argtypes, paramtypes);
/** * Init caches if not initialized. */ private void init() { if (optionalClass == null) { optionalClass = SReflect.classForName0(OPTIONAL_CLASSNAME, null); ofMethod = SReflect.getMethod(optionalClass, "of", new Class[]{Object.class}); emptyMethod = SReflect.getMethod(optionalClass, "empty", new Class[]{}); getMethod = SReflect.getMethod(optionalClass, "get", new Class[]{}); isPresentMethod = SReflect.getMethod(optionalClass, "isPresent", new Class[]{}); } }
/** * Get a string representation. */ public String toString() { return SReflect.getUnqualifiedClassName(getClass())+"("+sid+")"; }
/** * Init the static methods. */ public static void init(ClassLoader classloader) { try { Class nug = SReflect.classForName("nuggets.Nuggets", classloader); otx = nug.getMethod("objectToXML", new Class[]{Object.class, ClassLoader.class}); ofx = nug.getMethod("objectFromXML", new Class[]{String.class, ClassLoader.class}); } catch(Exception e) { throw new RuntimeException("Nuggets not in classpath.", e); } }