/** * 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); }
/** * Test if action is available in current context. * @return True, if available. */ public boolean isEnabled() { Class cl = SReflect.findClass0("jadex.platform.service.dependency.maven.MavenDependencyResolverService", null, null); // return cl!=null && treepanel.getTree().getLastSelectedPathComponent()==null && !treepanel.isRemote(); return cl!=null; // return (ITreeNode)treepanel.getTree().getLastSelectedPathComponent()==null && !treepanel.isRemote(); }
/** * Get the target. * @return The target. */ public Class<?> getTargetClass(ClassLoader cl) { if(targetclass==null) { targetclass = SReflect.findClass0(target, null, cl); } return targetclass; }
/** * Get the target. * @return The target. */ public Class<?> getTargetClass(ClassLoader cl) { if((lastcl!=cl && target != null) || (targetclass==null && target!=null)) { lastcl = cl; targetclass = SReflect.findClass0(target, null, cl); } return targetclass; }
/** * Find a class. * When the class name is not fully qualified, the list of * imported packages is searched for the class. * @param clname The class name. * @param imports The comma separated list of imported packages. * @throws ClassNotFoundException when the class is not found in the imports. */ public static <T> Class<T> findClass(String clname, String[] imports, ClassLoader classloader) throws ClassNotFoundException { Class clazz = findClass0(clname, imports, classloader); if(clazz==null) { throw new ClassNotFoundException("Class "+clname+" not found in imports"); //: "+SUtil.arrayToString(imports)); } return clazz; }
/** * Get the mirco agent class. */ // todo: make use of cache protected Class<?> getMicroAgentClass(String clname, String[] imports, ClassLoader classloader) { Class<?> ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); int idx; while(ret==null && (idx=clname.indexOf('.'))!=-1) { clname = clname.substring(idx+1); ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); } if(ret==null)// || !cma.isAssignableFrom(IMicroAgent.class)) throw new RuntimeException("No micro agent file: "+clname); return ret; }
/** * Get the mirco agent class. */ // todo: make use of cache protected Class getMicroAgentClass(String clname, String[] imports, ClassLoader classloader) { Class<?> ret = SReflect.findClass0(clname, imports, classloader); // System.out.println("getMAC:"+clname+" "+SUtil.arrayToString(imports)+" "+ret); int idx; while(ret==null && (idx=clname.indexOf('.'))!=-1) { clname = clname.substring(idx+1); ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); } if(ret==null)// || !cma.isAssignableFrom(IMicroAgent.class)) throw new RuntimeException("No bdi agent file: "+clname+" "+classloader); return ret; }
/** * Get the mirco agent class. */ // todo: make use of cache protected Class getMicroAgentClass(String clname, String[] imports, ClassLoader classloader) { Class<?> ret = SReflect.findClass0(clname, imports, classloader); // System.out.println("getMAC:"+clname+" "+SUtil.arrayToString(imports)+" "+ret); int idx; while(ret==null && (idx=clname.indexOf('.'))!=-1) { clname = clname.substring(idx+1); ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); } if(ret==null)// || !cma.isAssignableFrom(IMicroAgent.class)) throw new RuntimeException("No bdi agent file: "+clname+" "+classloader); return ret; }
/** * Get the mirco agent class. */ // todo: make use of cache protected Class<?> getMicroAgentClass(String clname, String[] imports, ClassLoader classloader) { Class<?> ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); int idx; while(ret==null && (idx=clname.indexOf('.'))!=-1) { clname = clname.substring(idx+1); ret = SReflect.findClass0(clname, imports, classloader); // System.out.println(clname+" "+cma+" "+ret); } if(ret==null)// || !cma.isAssignableFrom(IMicroAgent.class)) throw new RuntimeException("No micro agent file: "+clname); return ret; } }
Class ret = SReflect.findClass0(clname, imports, classloader); try ret = SReflect.findClass0(clname, imports, classloader);
/** * */ public Class<?> convertFromString(String val) { return SReflect.findClass0(val, null, getCombo().getClassLoader()); }
/** * */ public Class<?> convertFromString(String val) { return SReflect.findClass0(val, null, getCombo().getClassLoader()); }
Class<?> fac = SReflect.findClass0(clname, null, classloader);
/** * Get the type. * @return The type. */ public Class<?> getType(ClassLoader cl, String[] imports) { if(cl==null) { throw new IllegalArgumentException("Not allowed with cl==null, use getType0() instead!"); } if(classloader!=cl) { type = SReflect.findClass0(type!=null? SReflect.getClassName(type): typename, imports, 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 selected class. */ public Class<?> getSelectedClass() { Class<?> ret = null; int sel = results.getSelectedRow(); if(sel>0) { ClassInfo ci = ctm.getClass(sel); ret = SReflect.findClass0(ci.getPkg()+"."+ci.getName(), null, cl); } return ret; }
/** * */ 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()]); }
/** * Get an object type while considering imports for Java types. * @param tmodel The type model. * @param typename The name of the type to search for. * @param imports The imports (if any). * @param loader The class loader. * @return The type. */ protected static OAVObjectType getObjectType(OAVTypeModel tmodel, String typename, String[] imports) { OAVObjectType ret = null; try { ret = tmodel.getObjectType(typename); } catch(Exception e){} // If not found, search for class in imports. if(ret==null) { Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz==null) throw new RuntimeException("Type not found in type model: "+typename); ret = tmodel.getJavaType(clazz); } return ret; } }
/** * Get an object type while considering imports for Java types. * @param tmodel The type model. * @param typename The name of the type to search for. * @param imports The imports (if any). * @param loader The class loader. * @return The type. */ protected static OAVObjectType getObjectType(OAVTypeModel tmodel, String typename, String[] imports) { OAVObjectType ret = null; try { ret = tmodel.getObjectType(typename); } catch(Exception e){} // If not found, search for class in imports. if(ret==null) { Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz==null) throw new RuntimeException("Type not found in type model: "+typename); ret = tmodel.getJavaType(clazz); } return ret; } }
/** * Convert a string value to a type. * @param val The string value to convert. */ public Object convertString(String val, Object context) { Object ret = SReflect.findClass0((String)val, ((IModelInfo) ((IContext)context).getRootObject()).getAllImports(), ((IContext)context).getClassLoader()); if(ret==null) { reportError((IContext)context, "Class not found: "+val); } return ret; } }
/** * Precompute the type. */ public void precompile() { String name = getText(); // Get class object. Class clazz = SReflect.findClass0(getText(), imports, classloader); if(clazz==null) { // Shouldn't happen...? throw new ParseException("Class not found: "+name); } setConstantValue(clazz); setConstant(true); }