hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hivemind-...@jakarta.apache.org
Subject [Jakarta HiveMind Wiki] Updated: ExtendingSmartTranslator
Date Thu, 15 Jul 2004 18:45:48 GMT
   Date: 2004-07-15T11:45:47
   Editor: KurtHoehn <khoehn@etechstudios.com>
   Wiki: Jakarta HiveMind Wiki
   Page: ExtendingSmartTranslator
   URL: http://wiki.apache.org/jakarta-hivemind/ExtendingSmartTranslator

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -10,18 +10,18 @@
 -- Howard Lewis Ship''
 ----
 Back to the drawing board.  With the hint from Howard Lewis Ship, the light clicked on and
I was back in business.  I knew the Smart Translator uses Property Editors to work with types,
but only primitive types in java are supported without having to create an editor.  I needed
one for type “java.lang.Class”, so I created one.
-== Property Editor (ClassEditor.java) ==
-public class !ClassEditor extends !PropertyEditorSupport
+= Property Editor (ClassEditor.java) =
+{{{public class ClassEditor extends PropertyEditorSupport
 {
-  public void setAsText( String text ) throws java.lang.!IllegalArgumentException
+  public void setAsText( String text ) throws java.lang.IllegalArgumentException
   {
     try
     {
       setValue( Class.forName(text) );
     }
-    catch( !ClassNotFoundException cnfe )
+    catch( ClassNotFoundException cnfe )
     {
-      throw new java.lang.!IllegalArgumentException();
+      throw new java.lang.IllegalArgumentException();
     }
   }
 
@@ -32,4 +32,132 @@
   public String getAsText(){
     return getValue().toString();
   }
+} }}}
+Since this editor needed to be registered with the !PropertyEditorManager, I created a service
to handle the task.
+= PropertyEditorLoader Service =
+== Service Interface (PropertyEditorLoader.java) ==
+{{{
+public interface PropertyEditorLoader 
+{
+  void setPropertyEditors( List editors );
+  void register();
+}
+}}}
+== Service Implementation (PropertyEditorLoaderImpl.java) ==
+{{{
+public class PropertyEditorLoaderImpl implements PropertyEditorLoader
+{
+  private List _editors;
+    
+  public void register()
+  {
+    for( int i=0; i < _editors.size(); i++ )
+    {
+      PropertyEditorParameters editors = (PropertyEditorParameters) _editors.get(i);
+
+      try
+      {
+        Class targetType = Class.forName( editors.getTargetType() );
+        Class editorClass = Class.forName( editors.getEditorClass() );
+                
+        PropertyEditorManager.registerEditor( targetType, editorClass );
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+    }
+  }
+
+  public void setPropertyEditors(List editors)
+  { 
+    _editors = editors; 
+  }
+}
+}}}
+== Supporting Class (PropertyEditorParameters.java) ==
+{{{
+public class PropertyEditorParameters
+{
+  private String _targetType;
+  private String _editorClass;
+
+  public String getTargetType()
+  {
+    return _targetType;
+  }
+
+  public void setTargetType(String targetType)
+  {
+    _targetType = targetType; 
+  }
+
+  public String getEditorClass()
+  {
+    return _editorClass; 
+  }
+    
+  public void setEditorClass(String editorClass)
+  {
+    _editorClass = editorClass;
+  }
+}
+}}}
+= Wiring Hivemind =
+hivemind.sdl
+{{{
+module (id=my.stuff version=”1.0.0”) 
+{
+...
+configuration-point ( id=PropertyEditors )
+{
+  schema
+  {
+    element (name=editor)
+    {
+      attribute (name=target-type  required=true)
+      {
+        "The class name of a custom data type"
+      }
+  	  	 	 	
+      attribute (name=editor-class required=true)
+      {
+        "The class name of and editor for a custom data type"
+      }
+
+      conversion (class=propertyeditor.PropertyEditorParameters)
+      {
+        map (attribute=target-type property=targetType)
+        map (attribute=editor-class property=editorClass)
+      }   		
+    }
+  }
+}
+		
+service-point ( id=PropertyEditorLoader interface=propertyeditor.PropertyEditorLoader)
+{
+  "Register an editor class to be used to edit values of a given target class"
+	    
+  invoke-factory( service-id=hivemind.BuilderFactory )
+  {
+    construct ( class=propertyeditor.PropertyEditorLoaderImpl initialize-method=register
)
+    {
+      set-configuration( property=propertyEditors configuration-id=PropertyEditors )
+    }	                 
+  }
+}
+
+contribution (configuration-id=PropertyEditors)
+{
+  editor ( target-type=java.lang.Class editor-class=propertyeditor.ClassEditor)	
+}
+
+contribution (configuration-id=hivemind.EagerLoad)
+{
+  load ( service-id=PropertyEditorLoader )	    
+}
+...
 }
+}}}
+Using a configuration point for the !PropertyEditors gives me the capability of implementing
any number of !PropertyEditors I want.
+= Conclusion =
+The Property Editor is created and registered with hivemind and the Smart Translator is now
aware of type "java.lang.Class" and my problems are solved.   ''“It just works”'' 

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message