1 Reply Latest reply on Oct 28, 2004 2:48 AM by Thibaut Arts

    use n times a class created

    d s Newbie

      hi,

      I need to create a class and execute it n times, and i get this error "duplicate class definition: linkage Error", and really i don't know that is wrong.


       public static ArrayList MacTestScript(String inputTextScript, Mensaje inMsg) throws NotFoundException, IOException, CannotCompileException{
       String nameScript = "testConsole";
       ArrayList msg2 = null;
       try{
       ClassPool pool;
      
       pool = ClassPool.getDefault();
      
       pool.appendClassPath(classPath);
       CtClass newClass=null;
      
       try{
       newClass = pool.get( packageName + nameScript + suffixClass);
       newClass.defrost();
       newClass.detach();
       newClass = null;
      
       }
       catch(NotFoundException e){
       System.out.println("no esta creada la clase aun");
       newClass = pool.makeClass( packageName + nameScript + suffixClass );
       newClass.stopPruning(true);
      
       }
      
       System.out.println("buscando super" + packageName + suffixClass);
       CtClass superClass = null;
       superClass = pool.get( packageName + suffixClass );
       System.out.println("super encontrada");
      
      
       newClass.setSuperclass(superClass);
       System.out.println("seteando super");
      
       newClass.addConstructor(CtNewConstructor.defaultConstructor(newClass));
       String executeBody = "";
      
       java.util.List list = new java.util.ArrayList();
       executeBody = executeBody + "public java.util.ArrayList execute(){";
       executeBody = executeBody + "java.util.ArrayList list = new java.util.ArrayList();";
       executeBody = executeBody + inputTextScript ;
       executeBody = executeBody + "return list;";
       executeBody = executeBody + "}";
      
       newClass.addMethod(CtNewMethod.make(executeBody, newClass));
      
       System.out.println("Clase creada");
      
       Class testObject = newClass.toClass();
       System.out.println("Nombre Clase: " + testObject.getName());
      
       Method m[] = testObject.getDeclaredMethods();
       System.out.println("Metodos =" + m.length);
       for (int i = 0; i < m.length; i++)
       System.out.println("Metodos =<" + m.toString() + ">");
      
       Constructor c[] = testObject.getDeclaredConstructors();
       for (int i = 0; i < c.length; i++)
       System.out.println("Constructor =<" + c.toString() + ">");
      
       //Object testConstructed = con.newInstance(arguments);
       System.out.println("Constr...");
       Object testConstructed = testObject.newInstance();
       System.out.println("Cast");
       Script testInstance = (Script) testConstructed;
       System.out.println("setMessage");
       testInstance.setMsg(inMsg);
       System.out.println("Execute");
       msg2 = testInstance.execute();
      
       newClass.detach();
      
      
       }
       catch (NotFoundException e ){
       throw e;
      
       }
       catch (CannotCompileException e ){
       throw e;
       }
       catch (InstantiationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch (IllegalAccessException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       return msg2;
       }



      Thanks
      maría de los Angeles