/** * 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); }
/** * Check if an inner class exists. * @param outer The outer class. * @param inner The name of the inner class. * @return The inner class, or null if not found. */ protected Class getInnerClass(Class outer, String inner) { return SReflect.classForName0(outer.getName()+"$"+inner, classloader); }
/** * 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. */ public static Class<?> classForName(String name, ClassLoader classloader) throws ClassNotFoundException { Object clazz = classForName0(name, classloader); if(clazz==null) { throw new ClassNotFoundException("Class "+name+" not found."); } return (Class)clazz; }
/** * Get the object that is returned. */ public Object getReturnObject(Object object, Class clazz, boolean clone, ClassLoader targetcl) { Object ret = object; if(clone || targetcl!=null && !clazz.equals(SReflect.classForName0(clazz.getName(), targetcl))) { if(targetcl!=null) clazz = SReflect.classForName0(clazz.getName(), targetcl); try { ret = clazz.newInstance(); } catch(Exception e) { throw new RuntimeException(e); } } return ret; } }
/** * 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))); }
/** * Find the class of an object. * @param object The object. * @return The objects class. */ public static Class<?> findClazzOfJsonObject(JsonObject object, ClassLoader targetcl) { Class<?> ret = null; String clname = object.getString(CLASSNAME_MARKER, null); if(clname!=null) ret = SReflect.classForName0(clname, targetcl); return ret; }
/** * */ public Object getReturnObject(Object object, Class clazz, boolean clone, ClassLoader targetcl) { Object ret = object; if(clone || targetcl!=null && !clazz.equals(SReflect.classForName0(SReflect.getClassName(clazz), targetcl))) { if(targetcl!=null) clazz = SReflect.classForName0(SReflect.getClassName(clazz), targetcl); int length = Array.getLength(object); Class type = clazz.getComponentType(); return Array.newInstance(type, length); } return ret; } }
/** * */ protected IFuture<IControlCenterPlugin> addPlugin(final String clname, ClassLoader cl) { assert SwingUtilities.isEventDispatchThread(); // System.out.println("add plugin: "+clname); // libservice.getClassLoader(controlcenter.getJCCAccess().getModel().getResourceIdentifier()) // .addResultListener(new DefaultResultListener<ClassLoader>() // { // public void resultAvailable(ClassLoader cl) // { Class plclass = SReflect.classForName0(clname, cl); return addPlugin(plclass); // } // }); }
/** * */ protected IFuture<IControlCenterPlugin> addPlugin(final String clname, ClassLoader cl) { assert SwingUtilities.isEventDispatchThread(); // System.out.println("add plugin: "+clname); // libservice.getClassLoader(controlcenter.getJCCAccess().getModel().getResourceIdentifier()) // .addResultListener(new DefaultResultListener<ClassLoader>() // { // public void resultAvailable(ClassLoader cl) // { Class plclass = SReflect.classForName0(clname, cl); return addPlugin(plclass); // } // }); }
public void itemStateChanged(ItemEvent e) { boolean active = ((JRadioButton)e.getSource()).isSelected(); for(int j=0; j<options.length; j++) { String dependency =(String)options[j].getClientProperty(PROPERTY_DEPENDENCY); options[j].setEnabled(active && (dependency==null || SReflect.classForName0(dependency, null)!=null)); } } });
/** * Set the OPENGL flag. * @param value */ @Override public void setOpenGl(boolean value) { setValue(OPENGL, value); Class<?> p2d = SReflect.classForName0("jadex.extension.envsupport.observer.perspective.Perspective2D", Starter.class.getClassLoader()); if(p2d!=null) { try { p2d.getField("OPENGL").set(null, Boolean.valueOf(value)); } catch(Exception e) { e.printStackTrace(); } } } /**
/** * */ 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); } }
/** * Get the type. * @return The type. */ public Class<?> getType(ClassLoader cl) { if(cl==null) { throw new IllegalArgumentException("Not allowed with cl==null, use getType0() instead!"); } if(classloader!=cl) { type = SReflect.classForName0(type!=null? SReflect.getClassName(type): typename, cl); // Todo: assert that classloader is always the same -> currently reload required for bdi class rewriting? assert type!=null || classloader==null : "Try to load type :"+getTypeName()+" with wrong classloader: "+classloader+", "+cl; if(type!=null) { classloader = cl; } } return type; }
/** * 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 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 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; }
/** * 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[]{}); } }
/** * 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[]{}); } }
/** * 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[]{}); } }
/** * 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[]{}); } }