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  
21  
22      @Override
23      public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter,
24                          MarshallingContext marshallingContext) {
25          OleSRUExplainSchema oleSRUExplainSchema = (OleSRUExplainSchema) o;
26          hierarchicalStreamWriter.addAttribute("name", oleSRUExplainSchema.getName());
27          hierarchicalStreamWriter.addAttribute("identifier", oleSRUExplainSchema.getIdentifier());
28          hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getValue());
29          hierarchicalStreamWriter.startNode("zr:title");
30          hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getTitle());
31          hierarchicalStreamWriter.endNode();
32      }
33  
34      @Override
35      public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader,
36                              UnmarshallingContext unmarshallingContext) {
37          OleSRUExplainSchema oleSRUExplainSchema = new OleSRUExplainSchema();
38          oleSRUExplainSchema.setName(hierarchicalStreamReader.getAttribute("name"));
39          oleSRUExplainSchema.setIdentifier(hierarchicalStreamReader.getAttribute("identifier"));
40          oleSRUExplainSchema.setValue(hierarchicalStreamReader.getValue());
41          while(hierarchicalStreamReader.hasMoreChildren()) {
42              hierarchicalStreamReader.moveDown();
43              if ("zr:title".equals(hierarchicalStreamReader.getNodeName()))
44                  oleSRUExplainSchema.setTitle(hierarchicalStreamReader.getValue());
45              hierarchicalStreamReader.moveUp();
46          }
47          return oleSRUExplainSchema;
48      }
49  
50      @Override
51      public boolean canConvert(Class aClass) {
52          return aClass.equals(OleSRUExplainSchema.class);
53      }
54  }