Virtually Initialized Accessors

I never thought I'd actually use AnonymousInnerClasses but they've really been useful in my development platform of SimpleThinJavaServerPages. Often, there is an incompatibility between the Java Servlet Beans, and the way SimpleThinJavaServerPages access these beans to display the data. So what I do, is develop an interface that the JSP understands, and runtime, when the JavaServerPage calls the GetterAccessor I generate an anonymous innerclass object that transforms the Java Servlet Bean data to Java Server Page Simple Data.

This technique seems to be fundamental to good WebApp development under VAJ/EJB and SimpleThinJavaServerPage.

An example? Hmmmm.. Ok sure. Using the RightsManagement application. We have BaseRight object which is basically just a Code, and a Description. Like {23, "Canada"}.

Here's the Interface that the JavaServerPage thinks it's accessing:

 Interface GrantOfRight_UI {
  public BaseRight_UI getTerritory();

Interface BaseRight_UI { public String getCode(); public String getDescription(); }

But in the real GrantOfRight class, all we have is int territoryCode =23;, the code value for "Canada". Here's the VirtuallyInitializedAccessors:

 Class GrantOfRight implements GrantOfRight_UI {
  int territoryCode; ...

... public BaseRight_UI getTerritory() { String thisDescript = getContext().getTerritoryList().getDescriptForCode( territoryCode ); // Generate an anonymous inner class and return it here. return new BaseRight_UI() { public String getCode(){ return Integer.toString( territoryCode ); } public String getDescript(){ return thisDescript; } }; } }

-- KimballSampson

View edit of December 2, 2005 or FindPage with title or text search