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.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import javax.rules.admin.RuleExecutionSet;
026: import javax.rules.admin.RuleExecutionSetRegisterException;
027:
028: /**
029: * Stores the registered <code>RuleExecutionSet</code> objects.
030: *
031: * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
032: */
033: public final class RuleExecutionSetRepository implements Serializable {
034: private static final long serialVersionUID = 400L;
035:
036: /** The Singleton instance of the repository. */
037: // private static RuleExecutionSetRepository REPOSITORY;
038: /** Holds the registered <code>RuleExecutionSet</code> objects. */
039: private final Map map = new HashMap();
040:
041: /** Private constructor; use <code>getInstance</code> instead. */
042: public RuleExecutionSetRepository() {
043: // Hide the constructor.
044: }
045:
046: /**
047: * Gets the Singleton instance of a <code>RuleExecutionSetRepository</code>.
048: *
049: * @return The Singleton instance of the repository.
050: */
051: // public static synchronized RuleExecutionSetRepository getInstance( )
052: // {
053: // if ( RuleExecutionSetRepository.REPOSITORY != null )
054: // {
055: // return RuleExecutionSetRepository.REPOSITORY;
056: // }
057: // return RuleExecutionSetRepository.REPOSITORY =
058: // new RuleExecutionSetRepository( );
059: // }
060: /**
061: * Retrieves a <code>List</code> of the URIs that currently have
062: * <code>RuleExecutionSet</code>s associated with them.
063: *
064: * An empty list is returned is there are no associations.
065: *
066: * @return a <code>List</code> of the URIs that currently have
067: * <code>RuleExecutionSet</code>s associated with them.
068: */
069: public List getRegistrations() {
070: final List list = new ArrayList();
071: list.addAll(this .map.keySet());
072: return list;
073: }
074:
075: /**
076: * Get the <code>RuleExecutionSet</code> bound to this URI, or return
077: * <code>null</code>.
078: *
079: * @param bindUri
080: * the URI associated with the wanted
081: * <code>RuleExecutionSet</code>.
082: *
083: * @return the <code>RuleExecutionSet</code> bound to the given URI.
084: */
085: public RuleExecutionSet getRuleExecutionSet(final String bindUri) {
086: return (RuleExecutionSet) this .map.get(bindUri);
087: }
088:
089: /**
090: * Register a <code>RuleExecutionSet</code> under the given URI.
091: *
092: * @param bindUri
093: * the URI to associate with the <code>RuleExecutionSet</code>.
094: * @param ruleSet
095: * the <code>RuleExecutionSet</code> to associate with the URI
096: *
097: * @throws RuleExecutionSetRegisterException
098: * if an error occurred that prevented registration (i.e. if
099: * bindUri or ruleSet are <code>null</code>)
100: */
101: public void registerRuleExecutionSet(final String bindUri,
102: final RuleExecutionSet ruleSet)
103: throws RuleExecutionSetRegisterException {
104: if (bindUri == null) {
105: throw new RuleExecutionSetRegisterException(
106: "bindUri cannot be null");
107: }
108: if (ruleSet == null) {
109: throw new RuleExecutionSetRegisterException(
110: "ruleSet cannot be null");
111: }
112: this .map.put(bindUri, ruleSet);
113: }
114:
115: /**
116: * Unregister a <code>RuleExecutionSet</code> from the given URI.
117: *
118: * @param bindUri
119: * the URI to disassociate with the <code>RuleExecutionSet</code>.
120: */
121: public void unregisterRuleExecutionSet(final String bindUri) {
122: if (bindUri == null) {
123: throw new NullPointerException("bindUri cannot be null");
124: }
125: this.map.remove(bindUri);
126: }
127: }
|