1 10 package org.mmbase.bridge.jsp.taglib.edit; 11 12 import javax.servlet.jsp.JspTagException ; 13 14 import java.io.IOException ; 15 16 import org.mmbase.bridge.Cloud; 17 import org.mmbase.bridge.Transaction; 18 19 import org.mmbase.bridge.jsp.taglib.CloudReferrerTag; 20 import org.mmbase.bridge.jsp.taglib.CloudProvider; 21 import org.mmbase.bridge.jsp.taglib.util.Attribute; 22 23 import org.mmbase.util.logging.Logger; 24 import org.mmbase.util.logging.Logging; 25 26 33 34 public class TransactionTag extends CloudReferrerTag implements CloudProvider { 35 36 private static final Logger log = Logging.getLoggerInstance(TransactionTag.class); 37 protected Transaction transaction; 38 protected Attribute commit = Attribute.NULL; 39 protected Attribute name = Attribute.NULL; 40 protected String jspvar = null; 41 42 public void setCommitonclose(String c) throws JspTagException { 43 commit = getAttribute(c); 44 } 45 46 52 public Cloud getCloudVar() throws JspTagException { 53 return transaction; 54 } 55 56 public void setName(String s) throws JspTagException { 57 name = getAttribute(s); 58 } 59 60 public void setJspvar(String jv) { 61 jspvar = jv; 62 } 63 64 protected String getName() throws JspTagException { 65 return (String ) name.getValue(this); 66 } 67 68 71 public int doStartTag() throws JspTagException { 72 if (log.isDebugEnabled()) { 73 log.debug("value of commit: " + commit); 74 } 75 transaction = null; 76 if (getId() != null) { log.debug("looking up transaction in context"); 78 try { 79 Object o = getObject(getId()); 80 if (o instanceof Transaction) { 81 transaction = (Transaction) getObject(getId()); 82 } else { 83 throw new JspTagException ("The object with id " + getId() + " is not a transaction, but " + (o == null ? "NULL" : "a " + o.getClass())); 84 } 85 if (log.isDebugEnabled()) { 86 log.debug("found " + transaction); 87 } 88 } catch (JspTagException e) { } 89 } 90 if (transaction == null) { String n = getName(); 92 if (name == null) { 93 throw new JspTagException ("Did not find transaction in context, and no name for transaction supplied"); 94 } 95 transaction = findCloudProvider().getCloudVar().getTransaction(n); 96 if (getId() != null) { log.debug("putting transaction in context"); 98 getContextProvider().getContextContainer().register(getId(), transaction); 99 } 100 } 101 if (jspvar != null) { 102 pageContext.setAttribute(jspvar, transaction); 103 } 104 return EVAL_BODY; 105 } 106 107 protected boolean getDefaultCommit() { 108 return true; 109 } 110 111 public int doEndTag() throws JspTagException { 112 if (commit.getBoolean(this, getDefaultCommit())) { 113 transaction.commit(); 114 if (getId() != null) { 115 getContextProvider().getContextContainer().unRegister(getId()); 116 } 117 } 118 transaction = null; 119 return super.doEndTag(); 120 } 121 public int doAfterBody() throws JspTagException { 122 if (bodyContent != null) { 123 try { 124 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 125 } catch (IOException ioe){ 126 throw new JspTagException (ioe.toString()); 127 } 128 } 129 return SKIP_BODY; 130 } 131 132 } 133 134 | Popular Tags |