001 package org.kuali.ole.converters; 002 003 import com.thoughtworks.xstream.converters.Converter; 004 import com.thoughtworks.xstream.converters.MarshallingContext; 005 import com.thoughtworks.xstream.converters.UnmarshallingContext; 006 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 007 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 008 import org.kuali.ole.bo.explain.OleSRUExplainSchema; 009 010 /** 011 * Created with IntelliJ IDEA. 012 * User: ? 013 * Date: 7/19/12 014 * Time: 7:02 PM 015 * To change this template use File | Settings | File Templates. 016 */ 017 public class OleSRUExplainSchemaInfoConverter implements Converter { 018 019 020 021 022 @Override 023 public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter, 024 MarshallingContext marshallingContext) { 025 OleSRUExplainSchema oleSRUExplainSchema = (OleSRUExplainSchema) o; 026 hierarchicalStreamWriter.addAttribute("name", oleSRUExplainSchema.getName()); 027 hierarchicalStreamWriter.addAttribute("identifier", oleSRUExplainSchema.getIdentifier()); 028 hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getValue()); 029 hierarchicalStreamWriter.startNode("zr:title"); 030 hierarchicalStreamWriter.setValue(oleSRUExplainSchema.getTitle()); 031 hierarchicalStreamWriter.endNode(); 032 } 033 034 @Override 035 public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, 036 UnmarshallingContext unmarshallingContext) { 037 OleSRUExplainSchema oleSRUExplainSchema = new OleSRUExplainSchema(); 038 oleSRUExplainSchema.setName(hierarchicalStreamReader.getAttribute("name")); 039 oleSRUExplainSchema.setIdentifier(hierarchicalStreamReader.getAttribute("identifier")); 040 oleSRUExplainSchema.setValue(hierarchicalStreamReader.getValue()); 041 while(hierarchicalStreamReader.hasMoreChildren()) { 042 hierarchicalStreamReader.moveDown(); 043 if ("zr:title".equals(hierarchicalStreamReader.getNodeName())) 044 oleSRUExplainSchema.setTitle(hierarchicalStreamReader.getValue()); 045 hierarchicalStreamReader.moveUp(); 046 } 047 return oleSRUExplainSchema; 048 } 049 050 @Override 051 public boolean canConvert(Class aClass) { 052 return aClass.equals(OleSRUExplainSchema.class); 053 } 054 }