1 package org.drools.tags.rule;
2
3 /*
4 $Id: SemanticsTagLibrary.java,v 1.7 2003/03/25 19:47:32 tdiesler Exp $
5
6 Copyright 2002 (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
10 that the following conditions are met:
11
12 1. Redistributions of source code must retain copyright
13 statements and notices. Redistributions must also contain a
14 copy of this document.
15
16 2. Redistributions in binary form must reproduce the
17 above copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
20
21 3. The name "drools" must not be used to endorse or promote
22 products derived from this Software without prior written
23 permission of The Werken Company. For written permission,
24 please contact bob@werken.com.
25
26 4. Products derived from this Software may not be called "drools"
27 nor may "drools" appear in their names without prior written
28 permission of The Werken Company. "drools" is a registered
29 trademark of The Werken Company.
30
31 5. Due credit should be given to The Werken Company.
32 (http://drools.werken.com/).
33
34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
45 OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 */
48
49 import org.apache.commons.jelly.JellyTagException;
50 import org.apache.commons.jelly.impl.DynamicTagLibrary;
51 import org.drools.smf.SemanticModule;
52
53 import java.util.Iterator;
54 import java.util.Set;
55
56 /*** Dyanmic tag library for loading <code>SemanticModule</code>s.
57 *
58 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
59 *
60 * @version $Id: SemanticsTagLibrary.java,v 1.7 2003/03/25 19:47:32 tdiesler Exp $
61 */
62 class SemanticsTagLibrary extends DynamicTagLibrary
63 {
64 // ------------------------------------------------------------
65 // Instance members
66 // ------------------------------------------------------------
67
68 /*** The module. */
69 private SemanticModule module;
70
71 // ------------------------------------------------------------
72 // Constructors
73 // ------------------------------------------------------------
74
75 /*** Construct.
76 *
77 * @param module The module to make available as a taglib.
78 *
79 * @throws JellyTagException If an error occurs while attempting
80 * to initialize the module as a tag library.
81 */
82 SemanticsTagLibrary(SemanticModule module) throws JellyTagException
83 {
84 super( module.getUri() );
85 this.module = module;
86
87 registerObjectTypes();
88 registerConditions();
89 registerExtractors();
90 registerConsequences();
91 }
92
93 // ------------------------------------------------------------
94 // Instance methods
95 // ------------------------------------------------------------
96
97 /*** Retrieve the <code>SemanticModule</code>.
98 *
99 * @return The semantic module.
100 */
101 protected SemanticModule getSemanticModule()
102 {
103 return this.module;
104 }
105
106 /*** Register <code>ObjectType</code>s.
107 *
108 * @throws JellyTagException If an error occurs while attempting
109 * to register this module's object-types.
110 */
111 protected void registerObjectTypes() throws JellyTagException
112 {
113 Set names = getSemanticModule().getObjectTypeNames();
114
115 Iterator nameIter = names.iterator();
116 String eachName = null;
117 Class eachClass = null;
118
119 while ( nameIter.hasNext() )
120 {
121 eachName = (String) nameIter.next();
122 eachClass = getSemanticModule().getObjectType( eachName );
123
124 registerObjectType( eachName,
125 eachClass );
126 }
127 }
128
129 /*** Register an <code>ObjectType</code>.
130 *
131 * @param name The name.
132 * @param beanClass The class.
133 *
134 * @throws JellyTagException If an error occurs while attempting
135 * to register the object-type.
136 */
137 protected void registerObjectType(final String name,
138 final Class beanClass) throws JellyTagException
139 {
140 registerBeanTag( name,
141 new ComponentTagFactory( beanClass,
142 ObjectTypeComponentTag.class ) );
143 }
144
145 /*** Register <code>Condition</code>s.
146 *
147 * @throws JellyTagException If an error occurs while attempting
148 * to register this module's conditions.
149 */
150 protected void registerConditions() throws JellyTagException
151 {
152 Set names = getSemanticModule().getConditionNames();
153
154 Iterator nameIter = names.iterator();
155 String eachName = null;
156 Class eachClass = null;
157
158 while ( nameIter.hasNext() )
159 {
160 eachName = (String) nameIter.next();
161 eachClass = getSemanticModule().getCondition( eachName );
162
163 registerCondition( eachName,
164 eachClass );
165 }
166 }
167
168 /*** Register an <code>Condition</code>.
169 *
170 * @param name The name.
171 * @param beanClass The class.
172 *
173 * @throws JellyTagException If an error occurs while attempting
174 * to register the condition.
175 */
176 protected void registerCondition(final String name,
177 final Class beanClass) throws JellyTagException
178 {
179 registerBeanTag( name,
180 new ComponentTagFactory( beanClass,
181 ConditionComponentTag.class ) );
182 }
183
184 /*** Register <code>Extractors</code>s.
185 *
186 * @throws JellyTagException If an error occurs while attempting
187 * to register this module's extractors.
188 */
189 protected void registerExtractors() throws JellyTagException
190 {
191 Set names = getSemanticModule().getExtractorNames();
192
193 Iterator nameIter = names.iterator();
194 String eachName = null;
195 Class eachClass = null;
196
197 while ( nameIter.hasNext() )
198 {
199 eachName = (String) nameIter.next();
200 eachClass = getSemanticModule().getExtractor( eachName );
201
202 registerExtractor( eachName,
203 eachClass );
204 }
205 }
206
207 /*** Register an <code>Extractor</code>.
208 *
209 * @param name The name.
210 * @param beanClass The class.
211 *
212 * @throws JellyTagException If an error occurs while attempting
213 * to register the extractor.
214 */
215 protected void registerExtractor(final String name,
216 final Class beanClass) throws JellyTagException
217 {
218 registerBeanTag( name,
219 new ComponentTagFactory( beanClass,
220 ExtractorComponentTag.class ) );
221 }
222
223 /*** Register <code>Consequence</code>s.
224 *
225 * @throws JellyTagException If an error occurs while attempting
226 * to register this module's consequences.
227 */
228 protected void registerConsequences() throws JellyTagException
229 {
230 Set names = getSemanticModule().getConsequenceNames();
231
232 Iterator nameIter = names.iterator();
233 String eachName = null;
234 Class eachClass = null;
235
236 while ( nameIter.hasNext() )
237 {
238 eachName = (String) nameIter.next();
239 eachClass = getSemanticModule().getConsequence( eachName );
240
241 registerConsequence( eachName,
242 eachClass );
243 }
244 }
245
246 /*** Register an <code>Consequence</code>.
247 *
248 * @param name The name.
249 * @param beanClass The class.
250 *
251 * @throws JellyTagException If an error occurs while attempting
252 * to register the consequence.
253 */
254 protected void registerConsequence(final String name,
255 final Class beanClass) throws JellyTagException
256 {
257 registerBeanTag( name,
258 new ComponentTagFactory( beanClass,
259 ConsequenceComponentTag.class ) );
260 }
261 }
This page was automatically generated by Maven