Hi,

I did some prototyping with my old idea, "why not use java to do a java expression". I have always hated OGNL/whatever-way to do expressions, they always break when doing refactoring, and when they don't, they just look plain stupid.

I wrote a proof-of-concept code to do following:

First, a couple of models..

public class User {
   String name;
   Group group;

   public String getName(){
       return name;
   }

   public void setName(String name){
       this.name=name;
   }

   public Group getGroup(){
       return group;
   }

   public void setGroup(Group group){
       this.group=group;
   }
}

and

public class Group {
   String name;

   public String getName(){
       return name;
   }

   public void setName(String name){
       this.name=name;
   }

}


then one little interface:

public interface IQuery {

   public Object get(Object model);
   public void set(Object model,Object value);

}


Then I wrote a tiny little class called Querilla which uses ASM (http://asm.objectweb.org/) bytecode-analyzer to analyze the expressions from code like this:

       User user=new User();
       user.setName("James Bond");
       Group group=new Group();
       group.setName("secret");
       user.setGroup(group);

       System.out.println(new Querilla(user,new IQuery(){

               public Object get(Object model){
                   return ((User)model).getGroup().getName();
               }

               public void set(Object model,Object value){
                   ((User)model).getGroup().setName((String)value);
               }

           }).execute());



And, yeah, it really works.

What do you think, could this way be an more wicket way to do a thing like PropertyModel? No bloody scripting like OGNL (even if it's not in use anymore.) I like the refactorability, even if it means few lines of more code. Result of the bytecode analyzis can of course be cached, so this would be as fast as for example wicket.util.object.Objects.

Cheers,

Janne

--
Janne Hietamäki
Cemron Ltd
http://www.cemron.com/



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_idv28&alloc_id845&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to