1 16 17 package org.apache.taglibs.jms; 18 19 import javax.jms.JMSException ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.BodyContent ; 22 23 28 public class PropertyTag extends AbstractBodyTag { 29 30 31 private String name; 32 33 34 private Object value; 35 36 37 public int doStartTag() throws JspException { 40 if ( value != null ) { 41 fireSetProperty(); 42 return SKIP_BODY; 43 } 44 return EVAL_BODY_TAG; 45 } 46 47 public int doAfterBody() throws JspException { 48 BodyContent body = getBodyContent(); 49 value = body.getString(); 50 body.clearBody(); 51 fireSetProperty(); 52 return EVAL_PAGE; 53 } 54 55 public void release() { 56 name = null; 57 value = null; 58 } 59 60 64 public void setName(String name) { 65 this.name = name; 66 } 67 68 71 public void setValue(Object value) { 72 this.value = value; 73 } 74 75 protected void fireSetProperty() throws JspException { 78 try { 79 MessageTag tag = (MessageTag) findAncestorWithClass( this, MessageTag.class ); 80 if ( tag == null ) { 81 throw new JspException ("<jms:property> tag must be within a <jms:message> tag"); 82 } 83 tag.addProperty( name, value ); 84 } 85 catch (JMSException e) { 86 throw new JspException ( "Failed to set Message header property name: " + name + " value: " + value + ". Reason: " + e, e ); 87 } 88 } 89 } 90 | Popular Tags |