Date: 2004-07-15T11:15:51
Editor: KurtHoehn <[EMAIL PROTECTED]>
Wiki: Jakarta HiveMind Wiki
Page: ExtendingSmartTranslator
URL: http://wiki.apache.org/jakarta-hivemind/ExtendingSmartTranslator
no comment
Change Log:
------------------------------------------------------------------------------
@@ -1,2 +1,38 @@
= Extending Smart Translator via Property Editors =
-I've been working with Hivemind for a couple of months and I'm very happy with
it, so I would like to contribute my 2 cents. I came across a situation where
I was using a service that has getters/setters that were of type Class and
every time it would exception out on trying to get/set the values from these
methods. So I took it upon myself in open source fashion and dug into the
code. I found where the exception was coming from and I knew a way to fix it,
but was it the correct way?
+I've been working with Hivemind for a couple of months and I'm very happy with
it, so I would like to contribute my 2 cents. I came across a situation where
I was using a service that has getters/setters that were of type Class and
every time it would exception out on trying to get/set the values from these
methods. So I took it upon myself in open source fashion and dug into the
code. I found where the exception was coming from and I knew a way to fix it
in the source code, but was this the most correct way? NO!
+
+----
+
+''I'd rather add startup code to register a proper Property Editor with
+the Java Beans framework. There's an extension point for this purpose
+(hivemind.Startup). Once the Property Editor is defined, it should "just
work".
+
+Better a solution for that, than to start introducing special cases
+into the code.
+
+-- 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
+{
+ public void setAsText( String text ) throws
java.lang.!IllegalArgumentException
+ {
+ try
+ {
+ setValue( Class.forName(text) );
+ }
+ catch( !ClassNotFoundException cnfe )
+ {
+ throw new java.lang.!IllegalArgumentException();
+ }
+ }
+
+ public Object getValue(){
+ return super.getValue();
+ }
+
+ public String getAsText(){
+ return getValue().toString();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]