Re: [Simple-support] cannot use @Convert with @Attributes!?...
Brought to you by:
niallg
|
From: -=}\\*/{=- <rui...@gm...> - 2011-12-13 19:32:37
|
for now i'm going with JavaBean workaround...
private Pattern match;
@Attribute
public String getMatch() {return match.pattern();}
@Attribute
public void setMatch(String re) {match = Pattern.compile(re);}
... but this makes me write it every time.
On 13 December 2011 00:36, -=}\*/{=- <rui...@gm...> wrote:
> Exception in thread "main"
> org.simpleframework.xml.core.AttributeException: Cannot use
> @org.simpleframework.xml.Attribute(name=, empty=, required=true) to
> represent field 'match' java.util.regex.Pattern abc.kis.Url.match
> at
> org.simpleframework.xml.core.AttributeLabel.getConverter(AttributeLabel.java:110)
> at
> org.simpleframework.xml.core.CacheLabel.getConverter(CacheLabel.java:312)
> at
> org.simpleframework.xml.core.Composite.readVariable(Composite.java:666)
> at org.simpleframework.xml.core.Composite.readInstance(Composite.java:635)
>
>
> class Url {
> @Attribute
> Pattern match;
>
> @Attribute
> String target;
> }
>
> <url match=".*/" target="index.html"/>
>
> i'm using a RegistryStrategy with a PatternConverter that works fine with
> @Element...
>
> <url target="index.html">
> <match>.*/</match>
> </url>
>
> ... but that match belongs to an attribute not an element...
> i though of converting the Url class instead... or make a pattern wrapper,
> but rather get the pattern working as an @Attribute, since i'll need it
> several times and seams more correct.
>
>
>
> the converter below:
>
> public class PatternConverter extends SimpleConverter<Pattern> {
>
> public static Registry bind(Registry r) {
> return bind(r, Pattern.class, PatternConverter.class);
> }
>
> @Override
> public Pattern read(InputNode in) throws Exception {
> return Pattern.compile(in.getValue());
> }
>
> @Override
> public void write(OutputNode on, Pattern p) {
> on.setValue(p.toString());
> }
>
> }
>
>
|