View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.docstore.model.xstream.ingest;
17  
18  import com.thoughtworks.xstream.converters.Converter;
19  import com.thoughtworks.xstream.converters.MarshallingContext;
20  import com.thoughtworks.xstream.converters.UnmarshallingContext;
21  import com.thoughtworks.xstream.io.HierarchicalStreamReader;
22  import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
23  import org.kuali.ole.docstore.model.xmlpojo.ingest.LinkInfo;
24  
25  
26  /**
27   * Created by IntelliJ IDEA.
28   * User: pvsubrah
29   * Date: 9/9/11
30   * Time: 1:55 PM
31   * To change this template use File | Settings | File Templates.
32   */
33  public class LinkInfoConverter implements Converter {
34      @Override
35      public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) {
36          LinkInfo linkInfo = (LinkInfo) o;
37          hierarchicalStreamWriter.addAttribute("from", linkInfo.getFrom());
38          hierarchicalStreamWriter.addAttribute("to", linkInfo.getTo());
39      }
40  
41      @Override
42      public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
43          LinkInfo linkInfo = new LinkInfo();
44          linkInfo.setFrom(hierarchicalStreamReader.getAttribute("from"));
45          linkInfo.setTo(hierarchicalStreamReader.getAttribute("to"));
46          return linkInfo;
47      }
48  
49      @Override
50      public boolean canConvert(Class aClass) {
51          return aClass.equals(LinkInfo.class);
52      }
53  }