View Javadoc
1 package org.drools.smf; 2 3 /* 4 $Id: SimpleSemanticModule.java,v 1.6 2002/08/18 23:24:48 bob 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.drools.spi.ObjectType; 50 import org.drools.spi.Condition; 51 import org.drools.spi.Extractor; 52 import org.drools.spi.Consequence; 53 54 import java.util.Map; 55 import java.util.HashMap; 56 import java.util.Set; 57 58 /*** Simple implementation of a Semantic Module. 59 * 60 * @see org.drools.spi 61 * 62 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 63 */ 64 public class SimpleSemanticModule implements SemanticModule 65 { 66 // ------------------------------------------------------------ 67 // Instance members 68 // ------------------------------------------------------------ 69 70 /*** URI of this module. */ 71 private String uri; 72 73 /*** Object type implementations. */ 74 private Map objectTypes; 75 76 /*** Condition implementations. */ 77 private Map conditions; 78 79 /*** Extractor implementations. */ 80 private Map extractors; 81 82 /*** Consequence implementations. */ 83 private Map consequences; 84 85 // ------------------------------------------------------------ 86 // Constructors 87 // ------------------------------------------------------------ 88 89 /*** Construct with a URI. 90 * 91 * @param uri The URI the identifies this semantic module. 92 */ 93 public SimpleSemanticModule(String uri) 94 { 95 this.uri = uri; 96 97 this.objectTypes = new HashMap(); 98 this.conditions = new HashMap(); 99 this.extractors = new HashMap(); 100 this.consequences = new HashMap(); 101 } 102 103 // ------------------------------------------------------------ 104 // Instance methods 105 // ------------------------------------------------------------ 106 107 /*** Retrieve the URI that identifies this semantic module. 108 * 109 * @return The URI. 110 */ 111 public String getUri() 112 { 113 return this.uri; 114 } 115 116 /*** Set the URI. 117 * 118 * @param uri The URI. 119 */ 120 void setUri(String uri) 121 { 122 this.uri = uri; 123 } 124 125 /*** Add a semantic object type. 126 * 127 * @param name The object type name. 128 * @param objectType The object type implementation. 129 * 130 * @throws InvalidObjectTypeException If a class that is not a 131 * object type is added. 132 */ 133 public void addObjectType(String name, 134 Class objectType) throws InvalidObjectTypeException 135 { 136 if ( ! ObjectType.class.isAssignableFrom( objectType ) ) 137 { 138 throw new InvalidObjectTypeException( objectType ); 139 } 140 141 this.objectTypes.put( name, 142 objectType ); 143 } 144 145 /*** Retrieve a semantic object type by name. 146 * 147 * @param name the name. 148 * 149 * @return The object type implementation or <code>null</code> 150 * if none is bound to the name. 151 */ 152 public Class getObjectType(String name) 153 { 154 return (Class) this.objectTypes.get( name ); 155 } 156 157 /*** Retrieve the set of all object type names. 158 * 159 * @return The set of names. 160 */ 161 public Set getObjectTypeNames() 162 { 163 return this.objectTypes.keySet(); 164 } 165 166 /*** Add a semantic condition. 167 * 168 * @param name The condition name. 169 * @param condition The condition implementation. 170 * 171 * @throws InvalidConditionException If a class that is not a 172 * condition is added. 173 */ 174 public void addCondition(String name, 175 Class condition) throws InvalidConditionException 176 { 177 if ( ! Condition.class.isAssignableFrom( condition ) ) 178 { 179 throw new InvalidConditionException( condition ); 180 } 181 182 this.conditions.put( name, 183 condition ); 184 } 185 186 /*** Retrieve a semantic condition by name. 187 * 188 * @param name the name. 189 * 190 * @return The condition implementation or <code>null</code> 191 * if none is bound to the name. 192 */ 193 public Class getCondition(String name) 194 { 195 return (Class) this.conditions.get( name ); 196 } 197 198 /*** Retrieve the set of all condition names. 199 * 200 * @return The set of names. 201 */ 202 public Set getConditionNames() 203 { 204 return this.conditions.keySet(); 205 } 206 207 /*** Add a semantic extractor. 208 * 209 * @param name The extractor name. 210 * @param extractor The extractor implementation. 211 * 212 * @throws InvalidExtractorException If a class that is not a 213 * extractor is added. 214 */ 215 public void addExtractor(String name, 216 Class extractor) throws InvalidExtractorException 217 { 218 if ( ! Extractor.class.isAssignableFrom( extractor ) ) 219 { 220 throw new InvalidExtractorException( extractor ); 221 } 222 223 this.extractors.put( name, 224 extractor ); 225 } 226 227 /*** Retrieve a semantic extractor by name. 228 * 229 * @param name the name. 230 * 231 * @return The extractor implementation or <code>null</code> 232 * if none is bound to the name. 233 */ 234 public Class getExtractor(String name) 235 { 236 return (Class) this.extractors.get( name ); 237 } 238 239 /*** Retrieve the set of all object type names. 240 * 241 * @return The set of names. 242 */ 243 public Set getExtractorNames() 244 { 245 return this.extractors.keySet(); 246 } 247 248 /*** Add a semantic consequence. 249 * 250 * @param name The consequence name. 251 * @param consequence The consequence implementation. 252 * 253 * @throws InvalidConsequenceException If a class that is not a 254 * consequence is added. 255 */ 256 public void addConsequence(String name, 257 Class consequence) throws InvalidConsequenceException 258 { 259 if ( ! Consequence.class.isAssignableFrom( consequence ) ) 260 { 261 throw new InvalidConsequenceException( consequence ); 262 } 263 264 this.consequences.put( name, 265 consequence ); 266 } 267 268 /*** Retrieve a semantic consequence by name. 269 * 270 * @param name the name. 271 * 272 * @return The consequence implementation or <code>null</code> 273 * if none is bound to the name. 274 */ 275 public Class getConsequence(String name) 276 { 277 return (Class) this.consequences.get( name ); 278 } 279 280 /*** Retrieve the set of all object type names. 281 * 282 * @return The set of names. 283 */ 284 public Set getConsequenceNames() 285 { 286 return this.consequences.keySet(); 287 } 288 }

This page was automatically generated by Maven