01: package org.vraptor.config.xml;
02:
03: import org.vraptor.config.RegexViewManagerConfig;
04:
05: import com.thoughtworks.xstream.converters.Converter;
06: import com.thoughtworks.xstream.converters.MarshallingContext;
07: import com.thoughtworks.xstream.converters.UnmarshallingContext;
08: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
09: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
10:
11: /**
12: * A regex view manager converter.
13: *
14: * @author Guilherme Silveira
15: */
16: public class RegexViewManagerConfigConverter implements Converter {
17:
18: /**
19: * Can it convert this class type?
20: */
21: public boolean canConvert(Class clazz) {
22: return clazz.equals(RegexViewManagerConfig.class);
23: }
24:
25: /**
26: * Translates an object in the space to a xml string
27: */
28: public void marshal(Object value, HierarchicalStreamWriter writer,
29: MarshallingContext context) {
30: RegexViewManagerConfig object = (RegexViewManagerConfig) value;
31: writer.setValue(object.getRegex());
32: }
33:
34: /**
35: * Translates xml to an object
36: */
37: public Object unmarshal(HierarchicalStreamReader reader,
38: UnmarshallingContext context) {
39: return new RegexViewManagerConfig(reader.getValue());
40: }
41:
42: }
|