001: package org.drools.jsr94.rules.admin;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.Map;
020:
021: import javax.rules.admin.LocalRuleExecutionSetProvider;
022: import javax.rules.admin.RuleAdministrator;
023: import javax.rules.admin.RuleExecutionSet;
024: import javax.rules.admin.RuleExecutionSetDeregistrationException;
025: import javax.rules.admin.RuleExecutionSetProvider;
026: import javax.rules.admin.RuleExecutionSetRegisterException;
027:
028: /**
029: * The Drools implementation of the <code>RuleAdministrator</code> interface
030: * which is used by rule execution set administrators to load rule execution
031: * sets from external sources and create a <code>RuleExecutionSet</code>
032: * runtime object. <p/> The <code>RuleAdministrator</code> should be accessed
033: * by calling: <p/> <code>
034: * RuleServiceProvider ruleServiceProvider =
035: * RuleServiceProvider.newInstance();<br/>
036: * RuleAdministrator ruleAdministration =
037: * ruleServiceProvider.getRuleAdministrator();
038: * </code>
039: * <p/> In an additional step the administrator may also choose to bind the
040: * <code>RuleExecutionSet</code> instance to a URI so that it is globally
041: * accessible and <code>RuleSession</code>s can be created for the
042: * <code>RuleExecutionSet</code> through the RuleRuntime.
043: *
044: * @see RuleAdministrator
045: *
046: * @author N. Alex Rupp (n_alex <at>codehaus.org)
047: * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
048: */
049: public class RuleAdministratorImpl implements RuleAdministrator,
050: java.io.Serializable {
051: private RuleExecutionSetRepository repository;
052:
053: /** Default constructor. */
054: public RuleAdministratorImpl(
055: final RuleExecutionSetRepository repository) {
056: super ();
057: this .repository = repository;
058: }
059:
060: /**
061: * Returns a <code>RuleExecutionSetProvider</code> implementation.
062: *
063: * @param properties
064: * additional properties
065: *
066: * @return The created <code>RuleExecutionSetProvider</code>.
067: */
068: public RuleExecutionSetProvider getRuleExecutionSetProvider(
069: final Map properties) {
070: return new RuleExecutionSetProviderImpl();
071: }
072:
073: /**
074: * Returns a <code>LocalRuleExecutionSetProvider</code> implementation.
075: *
076: * Returns a <code>LocalRuleExecutionSetProvider</code> implementation or
077: * null if this implementation does not support creating a
078: * <code>RuleExecutionSet</code> from non-serializable resources.
079: *
080: * @param properties
081: * additional properties
082: *
083: * @return The created <code>LocalRuleExecutionSetProvider</code>.
084: */
085: public LocalRuleExecutionSetProvider getLocalRuleExecutionSetProvider(
086: final Map properties) {
087: return new LocalRuleExecutionSetProviderImpl();
088: }
089:
090: /**
091: * Registers a <code>RuleExecutionSet</code> and associates it with a
092: * given URI. Once a <code>RuleExecutionSet</code> has been registered it
093: * is accessible to runtime clients through the <code>RuleRuntime</code>.
094: * If a <code>RuleExecutionSet</code> has already been associated with the
095: * URI it should be deregistered (as if
096: * <code>deregisterRuleExecutionSet/</code> had been called) and the URI
097: * should be associated with the new <code>RuleExecutionSet</code>.
098: *
099: * @param bindUri
100: * the URI to associate with the <code>RuleExecutionSet</code>.
101: * @param set
102: * the <code>RuleExecutionSet</code> to associate with the URI
103: * @param properties
104: * additional properties used to perform the registration
105: *
106: * @throws RuleExecutionSetRegisterException
107: * if an error occurred that prevented registration
108: */
109: public void registerRuleExecutionSet(final String bindUri,
110: final RuleExecutionSet set, final Map properties)
111: throws RuleExecutionSetRegisterException {
112: // Note: an existing RuleExecutionSet is simply replaced
113: this .repository.registerRuleExecutionSet(bindUri, set);
114: }
115:
116: /**
117: * Unregisters a previously registered <code>RuleExecutionSet</code> from
118: * a URI.
119: *
120: * @param bindUri
121: * the URI to disassociate with the <code>RuleExecutionSet</code>.
122: * @param properties
123: * additional properties used to perform the deregistration
124: *
125: * @throws RuleExecutionSetDeregistrationException
126: * if an error occurred that prevented unregistration
127: */
128: public void deregisterRuleExecutionSet(final String bindUri,
129: final Map properties)
130: throws RuleExecutionSetDeregistrationException {
131: if (this .repository.getRuleExecutionSet(bindUri) == null) {
132: throw new RuleExecutionSetDeregistrationException(
133: "no execution set bound to: " + bindUri);
134: }
135:
136: this.repository.unregisterRuleExecutionSet(bindUri);
137: }
138: }
|