View Javadoc
1 package org.drools.tags.rule; 2 3 /* 4 $Id: ExtractionTag.java,v 1.5 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.MissingAttributeException; 51 import org.apache.commons.jelly.XMLOutput; 52 import org.drools.rule.Declaration; 53 import org.drools.rule.Extraction; 54 import org.drools.rule.Rule; 55 import org.drools.spi.Extractor; 56 57 /*** Construct an <code>Extraction</code> for a <code>Rule</code>. 58 * 59 * @see Extraction 60 * 61 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 62 * 63 * @version $Id: ExtractionTag.java,v 1.5 2003/03/25 19:47:32 tdiesler Exp $ 64 */ 65 public class ExtractionTag extends RuleTagSupport implements ExtractorReceptor 66 { 67 // ------------------------------------------------------------ 68 // Instance members 69 // ------------------------------------------------------------ 70 71 /*** Target of the extraction. */ 72 private String target; 73 74 /*** The semantic extractor. */ 75 private Extractor extractor; 76 77 /*** The variable. */ 78 private String var; 79 80 // ------------------------------------------------------------ 81 // Constructors 82 // ------------------------------------------------------------ 83 84 /*** Construct. 85 */ 86 public ExtractionTag() 87 { 88 this.target = null; 89 this.extractor = null; 90 } 91 92 // ------------------------------------------------------------ 93 // Instance methods 94 // ------------------------------------------------------------ 95 96 /*** Set the <code>Extractor</code>. 97 * 98 * @param extractor The extractor. 99 */ 100 protected void setExtractor(Extractor extractor) 101 { 102 this.extractor = extractor; 103 } 104 105 /*** Retrieve the <code>Extractor</code>. 106 * 107 * @return The extractor. 108 */ 109 public Extractor getExtractor() 110 { 111 return this.extractor; 112 } 113 114 /*** Set the target of the extraction. 115 * 116 * @param target The target variable name. 117 */ 118 public void setTarget(String target) 119 { 120 this.target = target; 121 } 122 123 /*** Retrieve the target of the extraction. 124 * 125 * @return The target variable name. 126 */ 127 public String getTarget() 128 { 129 return this.target; 130 } 131 132 /*** Set the variable in which to store the <code>Extraction</code>. 133 * 134 * @param var The variable. 135 */ 136 public void setVar(String var) 137 { 138 this.var = var; 139 } 140 141 /*** Retrieve the variable in which to store the <code>Extraction</code>. 142 * 143 * @return The variable name. 144 */ 145 public String getVar() 146 { 147 return this.var; 148 } 149 150 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 151 // org.drools.tags.rule.ExtractorReceptor 152 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 153 154 /*** Receive a <code>Extractor</code>. 155 * 156 * @param extractor The extrcactor. 157 */ 158 public void receiveExtractor(Extractor extractor) 159 { 160 setExtractor( extractor ); 161 } 162 163 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 164 // org.apache.commons.jelly.Tag 165 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 166 167 /*** Perform this tag. 168 * 169 * @param output The output sink. 170 * 171 * @throws JellyTagException If an error occurs while attempting 172 * to perform this tag. 173 */ 174 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException 175 { 176 requiredAttribute( "target", 177 this.target ); 178 179 Rule rule = getRule(); 180 181 if ( rule == null ) 182 { 183 throw new JellyTagException( "No rule available" ); 184 } 185 186 Declaration decl = rule.getDeclaration( this.target ); 187 188 if ( decl == null ) 189 { 190 throw new JellyTagException( "Unknown declaration: " + this.target ); 191 } 192 193 invokeBody( output ); 194 195 if ( this.extractor == null ) 196 { 197 throw new JellyTagException( "Extractor expected" ); 198 } 199 200 Extraction extraction = new Extraction( decl, 201 this.extractor ); 202 203 if ( this.var != null ) 204 { 205 getContext().setVariable( this.var, 206 extraction ); 207 } 208 209 getContext().setVariable( "org.drools.extraction", 210 extraction ); 211 212 rule.addExtraction( extraction ); 213 } 214 }

This page was automatically generated by Maven