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