I ran some tests and was getting the same error as you.  I believe that the 
problem lies in the fact that new Integer() expects a String or an int.  When 
you use your original line:

 return new Integer((($2.get("Quantity")!= null) ? $2.get("Quantity") : 
"1").toString()); 

you leave the possibility of returning $2.get("Quantity"), which returns an 
Object (as opposed to a String or an int).  If I change the return statement to:

 return new Integer((($2.get("Quantity")!= null) ? 
$2.get("Quantity").toString() : "1").toString()); 

then the error went away.

For reference, here is example code that compiles without errors:

package quicktest;
  | 
  | import javassist.*;
  | import java.lang.reflect.*;
  | import java.util.*;
  | 
  | public class Main {
  |     
  |     public Main() {
  |     }
  | 
  |     public static void main(String[] args) {
  |         ClassPool pool = ClassPool.getDefault();
  |         CtClass newCtClass = pool.makeClass( "TestClass" );
  |         String body =  "public Object translate(java.util.Map m, 
java.util.Map v) {" +
  |                         "return new 
Integer((($2.get(\"Quantity\").equals(null)) ? $2.get(\"Quantity\").toString() 
: \"1\").toString());}";
  |         
  |         try
  |         {
  |             CtMethod testCtMethod = CtNewMethod.make( body, newCtClass );
  |             newCtClass.addMethod( testCtMethod ); 
  |             
  |             Class newCreatedClass = newCtClass.toClass();
  |             
  |             Method testMethod = newCreatedClass.getDeclaredMethod( 
"translate", new Class[] { Map.class, Map.class } );
  |             Object testObject = newCreatedClass.newInstance();
  | 
  |         
  |         }catch( Exception e )
  |         {
  |             e.printStackTrace( System.err );
  |         }  
  |     }   
  | }

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3928930#3928930

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3928930


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to