View Javadoc

1   package org.kuali.ole.ingest.krms.builder;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.kuali.ole.ingest.krms.pojo.*;
5   
6   import java.io.IOException;
7   import java.net.URISyntaxException;
8   
9   /**
10   * Created with IntelliJ IDEA.
11   * User: vivekb
12   * Date: 8/22/12
13   * Time: 3:04 PM
14   * To change this template use File | Settings | File Templates.
15   */
16  public class OleKrmsObjectGeneratorFromXML {
17      /**
18       *  This method returns Krms object from fileContent.
19       *  The xStream will convert the fileContent into Krms Object.
20       * @param fileContent
21       * @return Krms object
22       * @throws java.net.URISyntaxException
23       * @throws java.io.IOException
24       */
25      public OleKrms buildKrmsFromFileContent(String fileContent) throws URISyntaxException, IOException {
26          XStream xStream = new XStream();
27          xStream.alias("agendas", OleKrms.class);
28          xStream.alias("agenda", OleKrmsAgenda.class);
29          xStream.alias("rule", OleKrmsRule.class);
30          xStream.alias("oleProposition",OleKrmsProposition.class);
31          xStream.alias("simpleProposition",OleSimpleProposition.class);
32          xStream.alias("compoundProposition",OleCompoundProposition.class);
33          xStream.alias("action", OleKrmsAction.class);
34          xStream.alias("value", OleValue.class);
35          xStream.alias("term", OleTerm.class);
36          xStream.addImplicitCollection(OleKrms.class,"agendas");
37          xStream.addImplicitCollection(OleCompoundProposition.class,"simplePropositions",OleSimpleProposition.class);
38          xStream.addImplicitCollection(OleCompoundProposition.class,"compoundPropositions",OleCompoundProposition.class);
39          xStream.addImplicitCollection(OleKrmsRuleAction.class,"krmsActions",OleKrmsAction.class);
40          xStream.addImplicitCollection(OleKrmsRuleAction.class,"krmsRules",OleKrmsRule.class);
41          xStream.addImplicitCollection(OleSimpleProposition.class,"terms",OleTerm.class);
42          Object object = xStream.fromXML(fileContent);
43          return (OleKrms) object;
44      }
45  }