View Javadoc
1 package org.drools.tags.rule; 2 3 /* 4 $Id: SemanticsTag.java,v 1.6 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.*; 50 import org.drools.io.SemanticsLoader; 51 import org.drools.smf.SemanticModule; 52 53 /*** Load semantics. 54 * 55 * @see SemanticModule 56 * 57 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 58 * 59 * @version $Id: SemanticsTag.java,v 1.6 2003/03/25 19:47:32 tdiesler Exp $ 60 */ 61 public class SemanticsTag extends TagSupport 62 { 63 // ------------------------------------------------------------ 64 // Instance members 65 // ------------------------------------------------------------ 66 67 /*** The module id. */ 68 private String module; 69 70 /*** The variable. */ 71 private String var; 72 73 // ------------------------------------------------------------ 74 // Constructors 75 // ------------------------------------------------------------ 76 77 /*** Construct. 78 */ 79 public SemanticsTag() 80 { 81 super( true ); 82 this.module = null; 83 } 84 85 // ------------------------------------------------------------ 86 // Instance methods 87 // ------------------------------------------------------------ 88 89 /*** Set the module id to load. 90 * 91 * @param module The module id. 92 */ 93 public void setModule(String module) 94 { 95 this.module = module; 96 } 97 98 /*** Retrieve the module id. 99 * 100 * @return The module id. 101 */ 102 public String getModule() 103 { 104 return this.module; 105 } 106 107 /*** Set the variable in which to store the <code>SemanticModule</code>. 108 * 109 * @param var The variable name. 110 */ 111 public void setVar(String var) 112 { 113 this.var = var; 114 } 115 116 /*** Retrieve the variable in which to store the <code>SemanticModule</code>. 117 * 118 * @return The variable name. 119 */ 120 public String getVar() 121 { 122 return this.var; 123 } 124 125 /*** Retrieve the <code>SemanticModule</code>. 126 * 127 * @return The semantic module. 128 * 129 * @throws JellyTagException If an error occurs while attempting 130 * to load the semantic module. 131 */ 132 protected SemanticModule getSemanticModule() throws JellyTagException 133 { 134 SemanticsLoader loader = new SemanticsLoader(); 135 136 try 137 { 138 return loader.load( getModule() ); 139 } 140 catch (Exception e) 141 { 142 throw new JellyTagException( e ); 143 } 144 } 145 146 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 147 // org.apache.commons.jelly.Tag 148 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 149 150 /*** Perform this tag. 151 * 152 * @param output The output sink. 153 * 154 * @throws JellyTagException If an error occurs while attempting 155 * to perform this tag. 156 */ 157 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException 158 { 159 if ( this.module == null 160 || 161 this.module.trim().equals( "" ) ) 162 { 163 throw new MissingAttributeException( "module" ); 164 } 165 166 SemanticModule semanticModule = getSemanticModule(); 167 168 if ( semanticModule == null ) 169 { 170 throw new JellyTagException( "Unknown semantic module: " + this.module ); 171 } 172 173 if ( this.var != null ) 174 { 175 getContext().setVariable( this.var, 176 semanticModule ); 177 } 178 179 String tagLibName = this.module + ".SemanticsTagLibrary"; 180 181 TagLibrary tagLib = null; 182 183 try 184 185 { 186 Class tagLibClass = Class.forName( tagLibName ); 187 188 tagLib = (TagLibrary) tagLibClass.newInstance(); 189 } 190 catch (Exception e) 191 { 192 tagLib = new SemanticsTagLibrary( semanticModule ); 193 } 194 195 getContext().registerTagLibrary( semanticModule.getUri(), 196 tagLib ); 197 } 198 }

This page was automatically generated by Maven