View Javadoc

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