/** * 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); }
/** * */ public Class<?>[] scanForFactories() { List<Class<?>> ret = new ArrayList<Class<?>>(); String[] facs = scanForFiles(new String[]{"Factory.class"}); try { Class<?> type = SReflect.findClass("jadex.bridge.service.types.factory.IComponentFactory", null, getClassLoader()); for(int i=0; i<facs.length; i++) { String clname = facs[i].substring(0, facs[i].length()-6).replace('/', '.'); // System.out.println("Found candidate: "+clname); Class<?> fac = SReflect.findClass0(clname, null, getClassLoader()); if(fac!=null && !fac.isInterface() && SReflect.isSupertype(type, fac)) { ret.add(fac); } } } catch(Exception e) { e.printStackTrace(); } return ret.toArray(new Class[ret.size()]); }
/** * */ public Constructor<?> getConstructor(ClassLoader cl) { try { if(method==null) { Class<?>[] types = new Class[parametertypes.length]; for(int i=0; i<types.length; i++) { types[i] = SReflect.findClass(parametertypes[i], null, cl); } Class<?> cla = SReflect.findClass(classname, null, cl); method = cla.getDeclaredConstructor(types); } return method; } catch(RuntimeException e) { throw e; } catch(Exception e) { throw new RuntimeException(e); } }
/** * Get the constructor via classloader. * @param cl The classloader. * @return The constructor. */ public Constructor<?> getConstructor(ClassLoader cl) { try { if(method==null || classloader != cl) { Class<?>[] types = new Class[parametertypes.length]; for(int i=0; i<types.length; i++) { types[i] = SReflect.findClass(parametertypes[i], null, cl); } Class<?> cla = SReflect.findClass(classname, null, cl); method = cla.getDeclaredConstructor(types); classloader = cl; } return method; } catch(Exception e) { throw new JadexBDIGenerationRuntimeException("Could not find Constructor for class: " + classname, e); } }
public Object createObject(IContext context, Map rawattributes) throws Exception { Object ret = null; String clname = (String)rawattributes.get("class"); String msg = (String)rawattributes.get("message"); Class<?> cl = SReflect.findClass(clname, null, context.getClassLoader()); try { Constructor<?> con = cl.getConstructor(new Class<?>[]{String.class}); ret = con.newInstance(new Object[]{msg}); } catch(Exception e) { // Try find empty constructor Constructor<?> con = cl.getConstructor(new Class<?>[0]); ret = con.newInstance(new Object[0]); } return ret; } }),
/** * */ protected static Class<?> getClazz(Object object, ClassLoader targetcl) { Class<?> ret = null; String clname = (String)((JsonObject)object).getString(JsonTraverser.CLASSNAME_MARKER, null); if(clname!=null) { try { ret = SReflect.findClass(clname, null, targetcl); } catch(Exception e) { e.printStackTrace(); } } return ret; } }
Class<?> cla = SReflect.findClass(classname, null, cl); ret = cla.getDeclaredField(name);
/** * */ public Method getMethod(ClassLoader cl) { try { if(method==null || classloader != cl) { Class<?>[] types = new Class[parametertypes.length]; for(int i=0; i<types.length; i++) { types[i] = parametertypes[i].getType(cl); } Class<?> cla = SReflect.findClass(classname, null, cl); method = cla.getDeclaredMethod(name, types); classloader = cl; } return method; } catch(RuntimeException e) { throw e; } catch(Exception e) { throw new RuntimeException(e); } }
public Object createObject(IContext context, Map rawattributes) throws Exception { Image ret = null; String encdata = (String) rawattributes.get("imgdata"); byte[] data = Base64.decode(encdata.getBytes()); String classname = (String) rawattributes.get("classname"); ret = SGUI.imageFromBytes(data, SReflect.findClass(classname, null, context.getClassLoader())); // if(classname.indexOf("Toolkit")!=-1) // { // Toolkit t = Toolkit.getDefaultToolkit(); // ret = t.createImage(data); // } // else // { // ret = ImageIO.read(new ByteArrayInputStream(data)); // } return ret; } }), new MappingInfo(null, new AttributeInfo[]
/** * Helper method for decoding an object (used for recursion). * @param context The decoding context. * @return Decoded object. */ protected static Object decodeObject(IDecodingContext context) { String classname = context.readClassname(); Class<?> clazz = null; try { if (classname.equals(NULL_MARKER)) return null; else if (classname.equals(REFERENCE_MARKER)) return context.getKnownObjects().get(Integer.valueOf((int) context.readVarInt())); else clazz = SReflect.findClass(classname, null, context.getClassloader()); } catch (ClassNotFoundException e) { //throw new RuntimeException(e); clazz = null; } return decodeRawObject(clazz, context); }
public Object convertString(String val, Object context) throws Exception { ClassInfo ret = new ClassInfo(SReflect.findClass((String)val, ((IModelInfo)((IContext)context).getRootObject()).getAllImports(), ((IContext)context).getClassLoader())); return ret; } };
public Object convertString(String val, Object context) throws Exception { return new ClassInfo(SReflect.findClass((String)val, ((IModelInfo)((IContext)context).getRootObject()).getAllImports(), ((IContext)context).getClassLoader())); } };
public Object postProcess(IContext context, Object object) { try { BDIXModel model = (BDIXModel)context.getRootObject(); MCapability mcapa = model.getCapability(); AReadContext ar = (AReadContext)context; Map<String, String> rawattrs = ar.getTopStackElement().getRawAttributes(); String service = rawattrs.get("class"); String method = rawattrs.get("method"); MGoal mgoal = (MGoal)ar.getStackElement(ar.getStackSize()-2).getObject(); Class<?> iface = SReflect.findClass(service, model.getAllImports(), ar.getClassLoader()); ClassInfo ci = new ClassInfo(iface.getName()); // Just use first method if no name is given if(method==null) method = iface.getDeclaredMethods()[0].getName(); mcapa.addGoalPublication(ci, mgoal, method); } catch(Exception e) { throw new RuntimeException(e); } return null; }
/** * Load class. */ public Object postProcess(IContext context, Object object) { Map ouc = (Map)context.getUserContext(); IOAVState state = (IOAVState)ouc.get(OAVObjectReaderHandler.CONTEXT_STATE); String value = (String)state.getAttributeValue(object, classnameattr); if(value!=null) { try { Class clazz = SReflect.findClass(value, ((IModelInfo)context.getRootObject()).getAllImports(), state.getTypeModel().getClassLoader()); state.setAttributeValue(object, classattr, clazz); } catch(Exception e) { reportError(context, e.toString()); } } return null; }
public IFuture<IExtensionInstance> execute(IInternalAccess ia) { IFuture<IExtensionInstance> ret; try { Class<AbstractEnvironmentSpace> clazz = SReflect.findClass(spacetype.getClassName(), access.getModel().getAllImports(), ia.getClassLoader()); AbstractEnvironmentSpace space = clazz.newInstance(); space.setInitData(ia, MEnvSpaceInstance.this, fetcher); ret = new Future<IExtensionInstance>(space); } catch(Exception e) { ret = new Future<IExtensionInstance>(e); } return ret; } });
if(clname!=null) Class clazz = SReflect.findClass(clname, interpreter.getModel(rcapability).getAllImports(), state.getTypeModel().getClassLoader());
if(impl!=null) Class<?> implcl = SReflect.findClass(impl, null, getClassLoader()); val = implcl.newInstance();
if(impl!=null) Class<?> implcl = SReflect.findClass(impl, null, getComponent().getClassLoader()); val = implcl.newInstance();
if(impl!=null) Class<?> implcl = SReflect.findClass(impl, null, getComponent().getClassLoader()); val = implcl.newInstance();