1 package hudson.util; 2 3 import com.rc.retroweaver.runtime.Enum_; 4 import com.thoughtworks.xstream.converters.Converter; 5 import com.thoughtworks.xstream.converters.MarshallingContext; 6 import com.thoughtworks.xstream.converters.UnmarshallingContext; 7 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 8 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 9 10 20 public class RetroweaverEnumConverter implements Converter { 21 22 public boolean canConvert(Class type) { 23 return Enum_.class.isAssignableFrom(type); 24 } 25 26 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { 27 writer.setValue(((Enum_)source).name()); 28 } 29 30 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 31 Class type = context.getRequiredType(); 32 if (type.getSuperclass() != Enum_.class) { 33 type = type.getSuperclass(); } 35 String value = reader.getValue(); 36 if(value==null || value.trim().length()==0) { 37 46 47 while(reader.hasMoreChildren()) { 48 reader.moveDown(); 49 if(reader.getNodeName().equals("name")) 50 value = reader.getValue(); 51 reader.moveUp(); 52 } 53 } 54 55 return Enum_.valueOf(type, value); 56 } 57 } 58 | Popular Tags |