001: package biz.hammurapi.rules.jsr94.admin;
002:
003: import java.io.IOException;
004: import java.io.InputStream;
005: import java.io.Reader;
006: import java.util.HashMap;
007: import java.util.Map;
008:
009: import javax.rules.admin.RuleExecutionSet;
010: import javax.rules.admin.RuleExecutionSetCreateException;
011: import javax.xml.parsers.FactoryConfigurationError;
012: import javax.xml.parsers.ParserConfigurationException;
013: import javax.xml.transform.TransformerException;
014:
015: import org.w3c.dom.Element;
016: import org.xml.sax.SAXException;
017:
018: import biz.hammurapi.config.ConfigurationException;
019: import biz.hammurapi.xml.dom.DOMUtils;
020:
021: /**
022: * Local Rule Execution Set Provider
023: * @author Pavel Vlasov
024: * @revision $Revision$
025: */
026: class LocalRuleExecutionSetProvider implements
027: javax.rules.admin.LocalRuleExecutionSetProvider {
028:
029: private Map properties = new HashMap();
030:
031: /**
032: * Constructs provider.
033: * @param properties
034: */
035: public LocalRuleExecutionSetProvider(Map properties) {
036: if (properties != null) {
037: this .properties.putAll(properties);
038: }
039: }
040:
041: /**
042: * Reads XML definition from input stream.
043: */
044: public RuleExecutionSet createRuleExecutionSet(InputStream in,
045: Map properties) throws RuleExecutionSetCreateException,
046: IOException {
047: try {
048: return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet(
049: DOMUtils.parse(in).getDocumentElement(), properties);
050: } catch (ConfigurationException e) {
051: throw new RuleExecutionSetCreateException(
052: "Could not instantiate rules: " + e, e);
053: } catch (TransformerException e) {
054: throw new RuleExecutionSetCreateException(
055: "Could not parse XML: " + e, e);
056: } catch (SAXException e) {
057: throw new RuleExecutionSetCreateException(
058: "Could not parse XML: " + e, e);
059: } catch (IOException e) {
060: throw new RuleExecutionSetCreateException(
061: "Could not load XML: " + e, e);
062: } catch (ParserConfigurationException e) {
063: throw new RuleExecutionSetCreateException(
064: "Could not parse XML: " + e, e);
065: } catch (FactoryConfigurationError e) {
066: throw new RuleExecutionSetCreateException(
067: "Could not parse XML: " + e);
068: }
069: }
070:
071: /**
072: * Reads XML definition from Reader.
073: */
074: public RuleExecutionSet createRuleExecutionSet(Reader in,
075: Map properties) throws RuleExecutionSetCreateException,
076: IOException {
077: try {
078: return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet(
079: DOMUtils.parse(in).getDocumentElement(), properties);
080: } catch (ConfigurationException e) {
081: throw new RuleExecutionSetCreateException(
082: "Could not instantiate rules: " + e, e);
083: } catch (TransformerException e) {
084: throw new RuleExecutionSetCreateException(
085: "Could not parse XML: " + e, e);
086: } catch (SAXException e) {
087: throw new RuleExecutionSetCreateException(
088: "Could not parse XML: " + e, e);
089: } catch (IOException e) {
090: throw new RuleExecutionSetCreateException(
091: "Could not load XML: " + e, e);
092: } catch (ParserConfigurationException e) {
093: throw new RuleExecutionSetCreateException(
094: "Could not parse XML: " + e, e);
095: } catch (FactoryConfigurationError e) {
096: throw new RuleExecutionSetCreateException(
097: "Could not parse XML: " + e);
098: }
099: }
100:
101: /**
102: * Directly uses XML definition (the first parameter).
103: */
104: public RuleExecutionSet createRuleExecutionSet(Object holder,
105: Map properties) throws RuleExecutionSetCreateException {
106: try {
107: return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet(
108: (Element) holder, properties);
109: } catch (ConfigurationException e) {
110: throw new RuleExecutionSetCreateException(
111: "Could not instantiate rules: " + e, e);
112: } catch (TransformerException e) {
113: throw new RuleExecutionSetCreateException(
114: "Could not parse XML: " + e, e);
115: }
116: }
117:
118: }
|