1 16 package org.apache.commons.jelly.tags.core; 17 18 import org.apache.commons.jelly.JellyTagException; 19 import org.apache.commons.jelly.MissingAttributeException; 20 import org.apache.commons.jelly.TagSupport; 21 import org.apache.commons.jelly.XMLOutput; 22 import org.apache.commons.jelly.expression.Expression; 23 24 38 public class CaseTag extends TagSupport { 39 40 public CaseTag() { 41 } 42 43 public void setValue(Expression value) { 46 this.valueExpression = value; 47 } 48 49 public void setFallThru(boolean fallThru) { 50 this.fallThru = fallThru; 51 } 52 53 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { 54 if(null == this.valueExpression) { 55 throw new MissingAttributeException("value"); 56 } 57 SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class); 58 if(null == tag) { 59 throw new JellyTagException("This tag must be enclosed inside a <switch> tag" ); 60 } 61 if(tag.hasDefaultBeenEncountered()) { 62 throw new JellyTagException("<default> should be the last tag within a <switch>" ); 63 } 64 Object value = valueExpression.evaluate(context); 65 if(tag.isFallingThru() || 66 (null == tag.getValue() && null == value) || 67 (null != tag.getValue() && tag.getValue().equals(value))) { 68 tag.caseMatched(); 69 tag.setFallingThru(fallThru); 70 invokeBody(output); 71 } 72 } 73 74 private Expression valueExpression = null; 77 private boolean fallThru = false; 78 79 } 80 | Popular Tags |