View Javadoc

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