View Javadoc
1 package org.drools.tags.rule; 2 3 /* 4 $Id: RuleTagSupport.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.MissingAttributeException; 51 import org.apache.commons.jelly.TagSupport; 52 import org.drools.rule.Declaration; 53 import org.drools.rule.Rule; 54 import org.drools.rule.RuleSet; 55 56 /*** Support for rule tags. 57 * 58 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 59 * 60 * @version $Id: RuleTagSupport.java,v 1.7 2003/03/25 19:47:32 tdiesler Exp $ 61 */ 62 public abstract class RuleTagSupport extends TagSupport 63 { 64 // ------------------------------------------------------------ 65 // Constructors 66 // ------------------------------------------------------------ 67 68 /*** Construct. 69 */ 70 protected RuleTagSupport() 71 { 72 super( true ); 73 } 74 75 // ------------------------------------------------------------ 76 // Instance methods 77 // ------------------------------------------------------------ 78 79 /*** Retrieve the current <code>RuleSet</code>. 80 * 81 * @return The current rule-set or <code>null</code> if 82 * no rule-set is in scope. 83 */ 84 protected RuleSet getRuleSet() 85 { 86 RuleSetTag ruleSetTag = (RuleSetTag) findAncestorWithClass( RuleSetTag.class ); 87 88 if ( ruleSetTag == null ) 89 { 90 return null; 91 } 92 93 return ruleSetTag.getRuleSet(); 94 } 95 96 /*** Retrieve the current <code>Rule<code>. 97 * 98 * @return The current rule. 99 */ 100 protected Rule getRule() 101 { 102 RuleTag ruleTag = (RuleTag) findAncestorWithClass( RuleTag.class ); 103 104 if ( ruleTag == null ) 105 { 106 return null; 107 } 108 109 return ruleTag.getRule(); 110 } 111 112 /*** Retrieve the array of available <code>Declaration</code>s. 113 * 114 * @return The array of declarations. 115 * 116 * @throws JellyTagException If no declarations are currently 117 * available in scope. 118 */ 119 public Declaration[] getAvailableDeclarations() throws JellyTagException 120 { 121 Rule rule = getRule(); 122 123 if ( rule == null ) 124 { 125 throw new JellyTagException( "No rule available" ); 126 } 127 128 return rule.getDeclarationsArray(); 129 } 130 131 /*** Check required attribute. 132 * 133 * @param name Attribute name. 134 * @param value Attribute value. 135 * 136 * @throws MissingAttributeException If the value is either <code>null</code> 137 * or contains only whitespace. 138 */ 139 protected void requiredAttribute(String name, 140 String value) throws MissingAttributeException 141 { 142 if ( value == null 143 || 144 value.trim().equals( "" ) ) 145 { 146 throw new MissingAttributeException( name ); 147 } 148 } 149 }

This page was automatically generated by Maven