LocalRuleExecutionSetProvider.java :  » Rule-Engine » hammurapi-rules » biz » hammurapi » rules » jsr94 » admin » Java Open Source

Java Open Source » Rule Engine » hammurapi rules 
hammurapi rules » biz » hammurapi » rules » jsr94 » admin » LocalRuleExecutionSetProvider.java
package biz.hammurapi.rules.jsr94.admin;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

import javax.rules.admin.RuleExecutionSet;
import javax.rules.admin.RuleExecutionSetCreateException;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import biz.hammurapi.config.ConfigurationException;
import biz.hammurapi.xml.dom.DOMUtils;


/**
 * Local Rule Execution Set Provider
 * @author Pavel Vlasov
 * @revision $Revision$
 */
class LocalRuleExecutionSetProvider implements  javax.rules.admin.LocalRuleExecutionSetProvider {
  
  private Map properties=new HashMap();

  /**
   * Constructs provider.
   * @param properties
   */
  public LocalRuleExecutionSetProvider(Map properties) {
    if (properties!=null) {
      this.properties.putAll(properties);
    }
  }

  /**
   * Reads XML definition from input stream.
   */
  public RuleExecutionSet createRuleExecutionSet(InputStream in, Map properties) throws RuleExecutionSetCreateException, IOException {
    try {
      return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet(DOMUtils.parse(in).getDocumentElement(), properties);
    } catch (ConfigurationException e) {
      throw new RuleExecutionSetCreateException("Could not instantiate rules: "+e, e);
    } catch (TransformerException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (SAXException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (IOException e) {
      throw new RuleExecutionSetCreateException("Could not load XML: "+e, e);
    } catch (ParserConfigurationException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (FactoryConfigurationError e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e);
    }
  }

  /**
   * Reads XML definition from Reader.
   */
  public RuleExecutionSet createRuleExecutionSet(Reader in, Map properties) throws RuleExecutionSetCreateException, IOException {
    try {
      return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet(DOMUtils.parse(in).getDocumentElement(), properties);
    } catch (ConfigurationException e) {
      throw new RuleExecutionSetCreateException("Could not instantiate rules: "+e, e);
    } catch (TransformerException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (SAXException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (IOException e) {
      throw new RuleExecutionSetCreateException("Could not load XML: "+e, e);
    } catch (ParserConfigurationException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    } catch (FactoryConfigurationError e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e);
    }
  }

  /**
   * Directly uses XML definition (the first parameter).
   */
  public RuleExecutionSet createRuleExecutionSet(Object holder, Map properties) throws RuleExecutionSetCreateException {
    try {
      return new biz.hammurapi.rules.jsr94.admin.RuleExecutionSet((Element) holder, properties);
    } catch (ConfigurationException e) {
      throw new RuleExecutionSetCreateException("Could not instantiate rules: "+e, e);
    } catch (TransformerException e) {
      throw new RuleExecutionSetCreateException("Could not parse XML: "+e, e);
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.