1 16 17 package org.apache.taglibs.jms; 18 19 import javax.jms.Destination ; 20 import javax.jms.JMSException ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.tagext.BodyContent ; 23 24 import org.apache.commons.messenger.Messenger; 25 26 31 public class DestinationTag extends AbstractBodyTag { 32 33 34 private String var; 35 36 37 private String name; 38 39 public int doStartTag() throws JspException { 42 if ( name != null ) { 43 exportDestination(); 44 return SKIP_BODY; 45 } 46 return EVAL_BODY_TAG; 47 } 48 49 public int doAfterBody() throws JspException { 50 BodyContent body = getBodyContent(); 51 name = body.getString(); 52 body.clearBody(); 53 exportDestination(); 54 return EVAL_PAGE; 55 } 56 57 public void release() { 58 name = null; 59 var = null; 60 } 61 62 65 67 public void setName(String name) { 68 this.name = name; 69 } 70 71 73 public void setVar(String var) { 74 this.var = var; 75 } 76 77 protected void exportDestination() throws JspException { 80 try { 81 ConnectionContext messengerTag = (ConnectionContext) findAncestorWithClass( this, ConnectionContext.class ); 82 if ( messengerTag == null ) { 83 throw new JspException ("<jms:destination> tag must be within a <jms:connection> or <jms:send> or <jms:receive> tag"); 84 } 85 Messenger messenger = messengerTag.getConnection(); 86 Destination destination = messenger.getDestination( name ); 87 if ( var != null ) { 88 pageContext.setAttribute( var, destination ); 89 } 90 else { 91 MessageOperationTag tag = (MessageOperationTag) findAncestorWithClass( this, MessageOperationTag.class ); 92 if ( tag == null ) { 93 throw new JspException ("<jms:destination> tag must be within a <jms:send> or <jms:receive> tag or the 'var' attribute should be specified"); 94 } 95 tag.setDestination( destination ); 96 } 97 } 98 catch (JMSException e) { 99 throw new JspException ( "Failed to create the Destination for: " + name ); 100 } 101 } 102 } 103 | Popular Tags |