Re: [Simple-support] Boolean Attribute 0 or 1
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-10-22 00:42:59
|
There is a RegistryMatcher, just use this. Register your classes with it. Its available in 2.6.2.
________________________________
From: jc.jourdon <jc....@7g...>
To: sim...@li...
Sent: Friday, 21 October 2011 10:52 AM
Subject: Re: [Simple-support] Boolean Attribute 0 or 1
Hello back,
i implemented a Matcher as you proposed, but i need a Matcher that
Transform many different Type of data (Transform<Float>,
Transform<Integer> and Transform<Boolean>).
how can i do this with a single implementation of Matcher class ?
my Matcher , with a single transformer, so far :
public class LigneArticleFloatMatcher implements Matcher, Transform<Float> {
@Override
public Float read(String value) throws Exception {
if((value!="null")&&(value!=""))
{
try{
return Float.valueOf(value);
}catch(Exception e){
return 0f;
}
}else{
return 0f;
}
}
@Override
public String write(Float value) throws Exception {
return String.valueOf(value);
}
@SuppressWarnings("rawtypes")
@Override
public Transform match(Class type) throws Exception {
if(type == Float.class) {
return this;
}
return null;
}
}
Thanks in advance ^^
> hello,
>
> you've done a great job with this tool and i already parsed many
> different XML from soap servers since last 3 days, but i encountered
> boolean attributes with "0" or "1"
>
> <list mybool1="0" mybool2="1" attr1="attr" attr2="attr">
> <page mybool3="1">
> ...
> </page>
> <page mybool3="0">
> ...
> </page>
> ...
> </list>
>
> I tried to create this class :
>
> public class Boolean01Converter implements Converter<Boolean>
> {
> @Override
> public Boolean read(InputNode node) throws Exception {
> return new Boolean(node.getValue().equals("1"));
> }
> @Override
> public void write(OutputNode node, Boolean value) throws Exception {
> node.setValue(value.booleanValue()?"1":"0");
> }
> }
>
> and implemented it on my object definition :
>
> @Root(name="list")
> public class ListFcts
> {
> @Attribute
> @Convert(Boolean01Converter.class)
> private Boolean mybool1;
>
> @Attribute
> @Convert(Boolean01Converter.class)
> private Boolean mybool2;
>
> @Attribute
> private int ...
>
> @ElementList(name="page", inline=true)
> private List<Page> pages;
> }
>
>
> But i still get false for every boolean.
>
> Also : how can I attach the converter to the Persister instead of
> declaring it on @Attributes hundred times ?
>
> Many thanks in advance !!
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support |