// Path: src/main/java/com/tibco/exchange/tibreview/exception/ParsingException.java
// public class ParsingException extends Exception {
// 
// 	private static final long serialVersionUID = 89526587L;
// 
// 	public ParsingException() {
// 		super();
// 	}
// 	
// 	public ParsingException(String message) {
// 		super(message);
// 	}
// 	
// 	public ParsingException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 	
// 	public ParsingException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: src/main/java/com/tibco/exchange/tibreview/model/rules/Tibrules.java
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "tibrules", propOrder = {
//     "process",
//     "resource",
//     "xpathfunctions"
// })
// public class Tibrules {
// 
//     protected Process process;
//     protected Resource resource;
//     protected Xpathfunctions xpathfunctions;
// 
//     /**
//      * Gets the value of the process property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Process }
//      *     
//      */
//     public Process getProcess() {
//         return process;
//     }
// 
//     /**
//      * Sets the value of the process property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Process }
//      *     
//      */
//     public void setProcess(Process value) {
//         this.process = value;
//     }
// 
//     /**
//      * Gets the value of the resource property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Resource }
//      *     
//      */
//     public Resource getResource() {
//         return resource;
//     }
// 
//     /**
//      * Sets the value of the resource property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Resource }
//      *     
//      */
//     public void setResource(Resource value) {
//         this.resource = value;
//     }
// 
//     /**
//      * Gets the value of the xpathfunctions property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Xpathfunctions }
//      *     
//      */
//     public Xpathfunctions getXpathfunctions() {
//         return xpathfunctions;
//     }
// 
//     /**
//      * Sets the value of the xpathfunctions property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Xpathfunctions }
//      *     
//      */
//     public void setXpathfunctions(Xpathfunctions value) {
//         this.xpathfunctions = value;
//     }
// 
// }


import java.io.File;
import java.io.FileInputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import com.tibco.exchange.tibreview.exception.ParsingException;
import com.tibco.exchange.tibreview.model.rules.Tibrules;
package com.tibco.exchange.tibreview.parser;




public class RulesParser {
	private static RulesParser instance = null;
	private static final String SCHEMA_FILE = "schemas/tibrules.xsd";
	
	private RulesParser() {
		
	}
	
	public static RulesParser getInstance() {
		if(instance == null) {
			instance = new RulesParser();
		}
		
		return instance;
	}

	public Tibrules parseFile(String file) throws ParsingException {
		File f = new File(file);

		if (!f.exists()) {
			throw new IllegalArgumentException("File " + file + " does not exist");
		}

		FileInputStream is = null;
		try {
			is = new FileInputStream(f);
			Source source = new StreamSource(is);
			
			SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
			
			Schema schema = sf.newSchema(getClass().getClassLoader().getResource(SCHEMA_FILE));
			JAXBContext jc = JAXBContext.newInstance("com.tibco.exchange.tibreview.model.rules");
			
			Unmarshaller unmarshaller = jc.createUnmarshaller();
			unmarshaller.setSchema(schema);

// Path: src/main/java/com/tibco/exchange/tibreview/exception/ParsingException.java
// public class ParsingException extends Exception {
// 
// 	private static final long serialVersionUID = 89526587L;
// 
// 	public ParsingException() {
// 		super();
// 	}
// 	
// 	public ParsingException(String message) {
// 		super(message);
// 	}
// 	
// 	public ParsingException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 	
// 	public ParsingException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: src/main/java/com/tibco/exchange/tibreview/model/rules/Tibrules.java
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "tibrules", propOrder = {
//     "process",
//     "resource",
//     "xpathfunctions"
// })
// public class Tibrules {
// 
//     protected Process process;
//     protected Resource resource;
//     protected Xpathfunctions xpathfunctions;
// 
//     /**
//      * Gets the value of the process property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Process }
//      *     
//      */
//     public Process getProcess() {
//         return process;
//     }
// 
//     /**
//      * Sets the value of the process property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Process }
//      *     
//      */
//     public void setProcess(Process value) {
//         this.process = value;
//     }
// 
//     /**
//      * Gets the value of the resource property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Resource }
//      *     
//      */
//     public Resource getResource() {
//         return resource;
//     }
// 
//     /**
//      * Sets the value of the resource property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Resource }
//      *     
//      */
//     public void setResource(Resource value) {
//         this.resource = value;
//     }
// 
//     /**
//      * Gets the value of the xpathfunctions property.
//      * 
//      * @return
//      *     possible object is
//      *     {@link Xpathfunctions }
//      *     
//      */
//     public Xpathfunctions getXpathfunctions() {
//         return xpathfunctions;
//     }
// 
//     /**
//      * Sets the value of the xpathfunctions property.
//      * 
//      * @param value
//      *     allowed object is
//      *     {@link Xpathfunctions }
//      *     
//      */
//     public void setXpathfunctions(Xpathfunctions value) {
//         this.xpathfunctions = value;
//     }
// 
// }


// Path: src/main/java/com/tibco/exchange/tibreview/parser/RulesParser.java
import java.io.File;
import java.io.FileInputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import com.tibco.exchange.tibreview.exception.ParsingException;
import com.tibco.exchange.tibreview.model.rules.Tibrules;

package com.tibco.exchange.tibreview.parser;




public class RulesParser {
	private static RulesParser instance = null;
	private static final String SCHEMA_FILE = "schemas/tibrules.xsd";
	
	private RulesParser() {
		
	}
	
	public static RulesParser getInstance() {
		if(instance == null) {
			instance = new RulesParser();
		}
		
		return instance;
	}

	public Tibrules parseFile(String file) throws ParsingException {
		File f = new File(file);

		if (!f.exists()) {
			throw new IllegalArgumentException("File " + file + " does not exist");
		}

		FileInputStream is = null;
		try {
			is = new FileInputStream(f);
			Source source = new StreamSource(is);
			
			SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
			
			Schema schema = sf.newSchema(getClass().getClassLoader().getResource(SCHEMA_FILE));
			JAXBContext jc = JAXBContext.newInstance("com.tibco.exchange.tibreview.model.rules");
			
			Unmarshaller unmarshaller = jc.createUnmarshaller();
			unmarshaller.setSchema(schema);

			JAXBElement<Tibrules> root = unmarshaller.unmarshal(source, Tibrules.class);