View Javadoc
1   package org.kuali.ole.converters;
2   
3   import com.thoughtworks.xstream.converters.Converter;
4   import com.thoughtworks.xstream.converters.MarshallingContext;
5   import com.thoughtworks.xstream.converters.UnmarshallingContext;
6   import com.thoughtworks.xstream.io.HierarchicalStreamReader;
7   import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
8   import org.kuali.ole.bo.explain.OleSRUExplainSchema;
9   
10  /**
11   * Created with IntelliJ IDEA.
12   * User: ?
13   * Date: 7/19/12
14   * Time: 7:02 PM
15   * To change this template use File | Settings | File Templates.
16   */
17  public class OleSRUExplainSchemaInfoConverter implements Converter {
18  
19  
20      @Override
21      public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter,
22                          MarshallingContext marshallingContext) {
23          OleSRUExplainSchema oleSRUExplainSchema = (OleSRUExplainSchema) o;
24          hierarchicalStreamWriter.addAttribute("name", oleSRUExplainSchema.getName());
25          hierarchicalStreamWriter.addAttribute("identifier", oleSRUExplainSchema.getIdentifier());
26          hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getValue());
27          hierarchicalStreamWriter.startNode("zr:title");
28          hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getTitle());
29          hierarchicalStreamWriter.endNode();
30      }
31  
32      @Override
33      public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader,
34                              UnmarshallingContext unmarshallingContext) {
35          OleSRUExplainSchema oleSRUExplainSchema = new OleSRUExplainSchema();
36          oleSRUExplainSchema.setName(hierarchicalStreamReader.getAttribute("name"));
37          oleSRUExplainSchema.setIdentifier(hierarchicalStreamReader.getAttribute("identifier"));
38          oleSRUExplainSchema.setValue(hierarchicalStreamReader.getValue());
39          while (hierarchicalStreamReader.hasMoreChildren()) {
40              hierarchicalStreamReader.moveDown();
41              if ("zr:title".equals(hierarchicalStreamReader.getNodeName()))
42                  oleSRUExplainSchema.setTitle(hierarchicalStreamReader.getValue());
43              hierarchicalStreamReader.moveUp();
44          }
45          return oleSRUExplainSchema;
46      }
47  
48      @Override
49      public boolean canConvert(Class aClass) {
50          return aClass.equals(OleSRUExplainSchema.class);
51      }
52  }