|
From: Steven D. <ste...@gm...> - 2005-01-06 15:52:35
|
For clarities sake, this is the property editor I'm registering:
package sandbox;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
import java.util.HashMap;
import java.util.Map;
/**
* <p>Property editor that delegates to other property editors based on
* a prefix. This value should be:</p>
*
* <pre>
* <prefix>:some_value
* </pre>
*
* <p>So for example, to resolve class names add an entry to the delegates
* property with key "class" and value
* <code>org.springframework.beans.propertyeditors.ClassEditor</code>. A
* value that would match for <code>ClassEditor</code> would be:</p>
*
* <pre>
* class:mypackage.myClass
* </pre>
*
* <p>If not prefix is found or the prefix is registered the value is
* returned as a string.</p>
*
* @since 06-01-2005
* @author Steven Devijver
*/
public class DelegatingPropertyEditor extends PropertyEditorSupport {
private Map delegates = null;
public DelegatingPropertyEditor() {
super();
this.delegates = new HashMap();
}
public void setDelegates(Map delegates) {
this.delegates = delegates;
}
public void setAsText(String text) throws IllegalArgumentException {
boolean hasSemiColon = false;
String key = null;
String value = null;
if (text.indexOf(":") > -1) {
hasSemiColon = true;
key = text.substring(0, text.indexOf(":"));
value = text.substring(text.indexOf(":") + 1, text.length());
}
if (hasSemiColon && this.delegates.containsKey(key)) {
PropertyEditor propertyEditor = (PropertyEditor)this.delegates.get(key);
propertyEditor.setAsText(value);
setValue(propertyEditor.getValue());
} else {
/*
* It's a string!
*/
setValue(text);
}
}
}
On Thu, 6 Jan 2005 15:52:58 +0100, Steven Devijver
<ste...@gm...> wrote:
> The key is java.lang.Object, I want to explicitly register for that.
> My property editor works for a normal property that accepts an Object
> parameter but apparently not for lists.
>
> It would be nice to use the available property editors when handling
> lists and maps. The default editors would never be used as none are
> registered for Object. Likewise, when setting properties the default
> once would be used because they come first in the list.
>
>
> On Thu, 06 Jan 2005 14:14:30 +0000, Rob Harrop <ro...@ca...> wrote:
> > The key of the customEditors Map entries must be the name of the class
> > you are registering the property editor for.
> >
> > Rob
> >
> > Steven Devijver wrote:
> >
> > >I register a delegating property editor like this:
> > >
> > > <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
> > > <property name="customEditors">
> > > <map>
> > > <entry key="java.lang.Object">
> > > <bean class="sandbox.DelegatingPropertyEditor">
> > > <property name="delegates">
> > > <map>
> > > <entry key="classpath">
> > > <bean class="org.springframework.beans.propertyeditors.InputStreamEditor"/>
> > > </entry>
> > > <entry key="class">
> > > <bean class="org.springframework.beans.propertyeditors.ClassEditor"/>
> > > </entry>
> > > </map>
> > > </property>
> > > </bean>
> > > </entry>
> > > </map>
> > > </property>
> > > </bean>
> > >
> > >When I create this bean my property editor is not called. Why is that?
> > >
> > > <bean id="aList" class="java.util.ArrayList">
> > > <constructor-arg>
> > > <list>
> > > <value>classpath:sandbox.xml</value>
> > > <value>class:sandbox.TestSandBox</value>
> > > <value>a string</value>
> > > </list>
> > > </constructor-arg>
> > > </bean>
> > >
> > >Steven
> > >
> > >
> > >-------------------------------------------------------
> > >The SF.Net email is sponsored by: Beat the post-holiday blues
> > >Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> > >It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> > >_______________________________________________
> > >Springframework-developer mailing list
> > >Spr...@li...
> > >https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >
> > >
> > >
> > >
> >
> > -------------------------------------------------------
> > The SF.Net email is sponsored by: Beat the post-holiday blues
> > Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> > It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
> >
>
|