|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RuleExecutionSetRepository.java | 75% | 86.7% | 100% | 86.2% |
|
1 | package org.drools.jsr94.rules.admin; | |
2 | ||
3 | /* | |
4 | * $Id: RuleExecutionSetRepository.java,v 1.11 2004/12/04 04:54:07 dbarnett Exp $ | |
5 | * | |
6 | * Copyright 2002-2004 (C) The Werken Company. All Rights Reserved. | |
7 | * | |
8 | * Redistribution and use of this software and associated documentation | |
9 | * ("Software"), with or without modification, are permitted provided that the | |
10 | * following conditions are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain copyright statements and | |
13 | * notices. Redistributions must also contain a copy of this document. | |
14 | * | |
15 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * | |
19 | * 3. The name "drools" must not be used to endorse or promote products derived | |
20 | * from this Software without prior written permission of The Werken Company. | |
21 | * For written permission, please contact bob@werken.com. | |
22 | * | |
23 | * 4. Products derived from this Software may not be called "drools" nor may | |
24 | * "drools" appear in their names without prior written permission of The Werken | |
25 | * Company. "drools" is a registered trademark of The Werken Company. | |
26 | * | |
27 | * 5. Due credit should be given to The Werken Company. | |
28 | * (http://drools.werken.com/). | |
29 | * | |
30 | * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' | |
31 | * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE | |
34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
40 | * POSSIBILITY OF SUCH DAMAGE. | |
41 | * | |
42 | */ | |
43 | ||
44 | import java.util.ArrayList; | |
45 | import java.util.HashMap; | |
46 | import java.util.List; | |
47 | import java.util.Map; | |
48 | ||
49 | import javax.rules.admin.RuleExecutionSet; | |
50 | import javax.rules.admin.RuleExecutionSetRegisterException; | |
51 | ||
52 | /** | |
53 | * Stores the registered <code>RuleExecutionSet</code> objects. | |
54 | * | |
55 | * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a> | |
56 | */ | |
57 | public final class RuleExecutionSetRepository | |
58 | { | |
59 | /** The Singleton instance of the repository. */ | |
60 | private static RuleExecutionSetRepository REPOSITORY; | |
61 | ||
62 | /** Holds the registered <code>RuleExecutionSet</code> objects. */ | |
63 | private Map map = new HashMap( ); | |
64 | ||
65 | /** Private constructor; use <code>getInstance</code> instead. */ | |
66 | 2 | private RuleExecutionSetRepository( ) |
67 | { | |
68 | // Hide the constructor. | |
69 | } | |
70 | ||
71 | /** | |
72 | * Gets the Singleton instance of a <code>RuleExecutionSetRepository</code>. | |
73 | * | |
74 | * @return The Singleton instance of the repository. | |
75 | */ | |
76 | 138 | public static synchronized RuleExecutionSetRepository getInstance( ) |
77 | { | |
78 | 138 | if ( RuleExecutionSetRepository.REPOSITORY != null ) |
79 | { | |
80 | 136 | return RuleExecutionSetRepository.REPOSITORY; |
81 | } | |
82 | 2 | return RuleExecutionSetRepository.REPOSITORY = |
83 | new RuleExecutionSetRepository( ); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Retrieves a <code>List</code> of the URIs that currently have | |
88 | * <code>RuleExecutionSet</code>s associated with them. | |
89 | * | |
90 | * An empty list is returned is there are no associations. | |
91 | * | |
92 | * @return a <code>List</code> of the URIs that currently have | |
93 | * <code>RuleExecutionSet</code>s associated with them. | |
94 | */ | |
95 | 5 | public List getRegistrations( ) |
96 | { | |
97 | 5 | List list = new ArrayList( ); |
98 | 5 | list.addAll( this.map.keySet( ) ); |
99 | 5 | return list; |
100 | } | |
101 | ||
102 | /** | |
103 | * Get the <code>RuleExecutionSet</code> bound to this URI, or return | |
104 | * <code>null</code>. | |
105 | * | |
106 | * @param bindUri the URI associated with the wanted | |
107 | * <code>RuleExecutionSet</code>. | |
108 | * | |
109 | * @return the <code>RuleExecutionSet</code> bound to the given URI. | |
110 | */ | |
111 | 89 | public RuleExecutionSet getRuleExecutionSet( String bindUri ) |
112 | { | |
113 | 89 | return ( RuleExecutionSet ) this.map.get( bindUri ); |
114 | } | |
115 | ||
116 | /** | |
117 | * Register a <code>RuleExecutionSet</code> under the given URI. | |
118 | * | |
119 | * @param bindUri the URI to associate with the | |
120 | * <code>RuleExecutionSet</code>. | |
121 | * @param ruleSet the <code>RuleExecutionSet</code> to associate with the | |
122 | * URI | |
123 | * | |
124 | * @throws RuleExecutionSetRegisterException if an error occurred that | |
125 | * prevented registration | |
126 | * (i.e. if bindUri or ruleSet are <code>null</code>) | |
127 | */ | |
128 | 48 | public void registerRuleExecutionSet( |
129 | String bindUri, RuleExecutionSet ruleSet ) | |
130 | throws RuleExecutionSetRegisterException | |
131 | { | |
132 | 48 | if ( bindUri == null ) |
133 | { | |
134 | 0 | throw new RuleExecutionSetRegisterException( |
135 | "bindUri cannot be null" ); | |
136 | } | |
137 | 48 | if ( ruleSet == null ) |
138 | { | |
139 | 1 | throw new RuleExecutionSetRegisterException( |
140 | "ruleSet cannot be null" ); | |
141 | } | |
142 | 47 | this.map.put( bindUri, ruleSet ); |
143 | } | |
144 | ||
145 | /** | |
146 | * Unregister a <code>RuleExecutionSet</code> from the given URI. | |
147 | * | |
148 | * @param bindUri the URI to disassociate with the | |
149 | * <code>RuleExecutionSet</code>. | |
150 | */ | |
151 | 8 | public void unregisterRuleExecutionSet( String bindUri ) |
152 | { | |
153 | 8 | if ( bindUri == null ) |
154 | { | |
155 | 0 | throw new NullPointerException( "bindUri cannot be null" ); |
156 | } | |
157 | 8 | this.map.remove( bindUri ); |
158 | } | |
159 | } |
|