001package org.kuali.ole.ingest.krms.builder; 002 003import com.thoughtworks.xstream.XStream; 004import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.DataField; 005import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.SubField; 006import org.kuali.ole.docstore.model.xstream.work.bib.marc.DataFieldConverter; 007import org.kuali.ole.docstore.model.xstream.work.bib.marc.SubFieldConverter; 008import org.kuali.ole.ingest.ProfileAttributeConverter; 009import org.kuali.ole.ingest.krms.pojo.*; 010import org.kuali.ole.ingest.pojo.*; 011import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 012 013import java.io.IOException; 014import java.net.URISyntaxException; 015import java.util.ArrayList; 016import java.util.List; 017 018/** 019 * Created with IntelliJ IDEA. 020 * User: vivekb 021 * Date: 8/22/12 022 * Time: 3:04 PM 023 * To change this template use File | Settings | File Templates. 024 */ 025public class OleKrmsObjectGeneratorFromXML { 026 /** 027 * This method returns Krms object from fileContent. 028 * The xStream will convert the fileContent into Krms Object. 029 * @param fileContent 030 * @return Krms object 031 * @throws java.net.URISyntaxException 032 * @throws java.io.IOException 033 */ 034 public OleKrms buildKrmsFromFileContent(String fileContent) throws URISyntaxException, IOException { 035 XStream xStream = new XStream(); 036 xStream.alias("agendas", OleKrms.class); 037 xStream.alias("agenda", OleKrmsAgenda.class); 038 xStream.alias("rule", OleKrmsRule.class); 039 xStream.alias("attribute", ProfileAttributeBo.class); 040 xStream.alias("overlayOption", OverlayOption.class); 041 xStream.alias("datafield", DataField.class); 042 xStream.alias("subfield", SubField.class); 043 xStream.alias("oleProposition",OleKrmsProposition.class); 044 xStream.alias("simpleProposition",OleSimpleProposition.class); 045 xStream.alias("compoundProposition",OleCompoundProposition.class); 046 xStream.alias("action", OleKrmsAction.class); 047 xStream.alias("value", OleValue.class); 048 xStream.alias("term", OleTerm.class); 049 xStream.alias("parameter",OleParameter.class); 050 xStream.addImplicitCollection(OleKrms.class,"agendas"); 051 xStream.addImplicitCollection(OleCompoundProposition.class,"simplePropositions",OleSimpleProposition.class); 052 xStream.addImplicitCollection(OleCompoundProposition.class,"compoundPropositions",OleCompoundProposition.class); 053 xStream.addImplicitCollection(OleKrmsRuleAction.class,"krmsActions",OleKrmsAction.class); 054 xStream.addImplicitCollection(OleKrmsRuleAction.class,"krmsRules",OleKrmsRule.class); 055 xStream.addImplicitCollection(OleSimpleProposition.class,"terms",OleTerm.class); 056 xStream.addImplicitCollection(OleKrmsAction.class,"parameters",OleParameter.class); 057 xStream.registerConverter(new ProfileAttributeConverter()); 058 xStream.registerConverter(new DataFieldConverter()); 059 xStream.registerConverter(new SubFieldConverter()); 060 Object object = xStream.fromXML(fileContent); 061 return (OleKrms) object; 062 } 063}