|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RuleRuntimeImpl.java | 75% | 88.9% | 100% | 87.5% |
|
1 | package org.drools.jsr94.rules; | |
2 | ||
3 | /* | |
4 | * $Id: RuleRuntimeImpl.java,v 1.12 2004/11/15 01:12:22 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.List; | |
45 | import java.util.Map; | |
46 | ||
47 | import javax.rules.RuleExecutionSetNotFoundException; | |
48 | import javax.rules.RuleRuntime; | |
49 | import javax.rules.RuleSession; | |
50 | import javax.rules.RuleSessionTypeUnsupportedException; | |
51 | ||
52 | import org.drools.jsr94.rules.admin.RuleExecutionSetRepository; | |
53 | ||
54 | /** | |
55 | * The Drools implementation of the <code>RuleRuntime</code> interface which is | |
56 | * the access point for runtime execution of <code>RuleExecutionSet</code>s. | |
57 | * It provides methods to create <code>RuleSession</code> implementation as well | |
58 | * as methods to retrieve <code>RuleExecutionSet</code>s that have been | |
59 | * previously registered using the <code>RuleAdministrator</code>. | |
60 | * <p/> | |
61 | * The <code>RuleRuntime</code> should be accessed through the | |
62 | * <code>RuleServiceProvider</code>. An instance of the <code>RuleRuntime</code> | |
63 | * can be retrieved by calling: | |
64 | * <p/> | |
65 | * <code> | |
66 | * RuleServiceProvider ruleServiceProvider = | |
67 | * RuleServiceProvider.newInstance();<br/> | |
68 | * RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); | |
69 | * </code> | |
70 | * <p/> | |
71 | * Note: the release method must be called on the <code>RuleSession</code> to | |
72 | * clean up all resources used by the <code>RuleSession</code>. | |
73 | * | |
74 | * @see RuleRuntime | |
75 | * @author N. Alex Rupp (n_alex <at>codehaus.org) | |
76 | */ | |
77 | public class RuleRuntimeImpl implements RuleRuntime | |
78 | { | |
79 | /** | |
80 | * Create a new <code>RuleRuntimeImpl</code>. | |
81 | */ | |
82 | 44 | public RuleRuntimeImpl( ) |
83 | { | |
84 | // no special initialization required | |
85 | } | |
86 | ||
87 | /** | |
88 | * Creates a <code>RuleSession</code> implementation using the supplied | |
89 | * Drools-specific rule execution set registration URI. | |
90 | * | |
91 | * @param uri the URI for the <code>RuleExecutionSet</code> | |
92 | * @param properties additional properties used to create the | |
93 | * <code>RuleSession</code> implementation. | |
94 | * @param ruleSessionType the type of rule session to create. | |
95 | * | |
96 | * @throws RuleSessionTypeUnsupportedException if the ruleSessionType is not | |
97 | * supported by Drools or the RuleExecutionSet | |
98 | * @throws RuleExecutionSetNotFoundException if the URI could not be | |
99 | * resolved into a <code>RuleExecutionSet</code> | |
100 | * | |
101 | * @return The created <code>RuleSession</code>. | |
102 | */ | |
103 | 76 | public RuleSession createRuleSession( |
104 | String uri, Map properties, int ruleSessionType ) | |
105 | throws RuleSessionTypeUnsupportedException, | |
106 | RuleExecutionSetNotFoundException | |
107 | { | |
108 | ||
109 | 76 | if ( ruleSessionType == RuleRuntime.STATELESS_SESSION_TYPE ) |
110 | { | |
111 | 41 | StatelessRuleSessionImpl session = |
112 | new StatelessRuleSessionImpl( uri, properties ); | |
113 | 40 | return session; |
114 | } | |
115 | ||
116 | 35 | if ( ruleSessionType == RuleRuntime.STATEFUL_SESSION_TYPE ) |
117 | { | |
118 | 35 | StatefulRuleSessionImpl session = |
119 | new StatefulRuleSessionImpl( uri, properties ); | |
120 | 34 | return session; |
121 | } | |
122 | ||
123 | 0 | throw new RuleSessionTypeUnsupportedException( |
124 | "invalid session type: " + ruleSessionType ); | |
125 | } | |
126 | ||
127 | /** | |
128 | * Retrieves a <code>List</code> of the URIs that currently have | |
129 | * <code>RuleExecutionSet</code>s associated with them. | |
130 | * An empty list is returned is there are no associations. | |
131 | * | |
132 | * @return a <code>List</code> of <code>String</code>s (URIs) | |
133 | */ | |
134 | 2 | public List getRegistrations( ) |
135 | { | |
136 | 2 | RuleExecutionSetRepository repository = |
137 | RuleExecutionSetRepository.getInstance( ); | |
138 | 2 | return repository.getRegistrations( ); |
139 | } | |
140 | } |
|