
// Copyright (c) 1999, 2000 Oracle Corporation
package oracle.jbo.html.jsp.datatags;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import oracle.jdeveloper.html.*;
import oracle.jbo.*;
import java.io.*;
import oracle.jbo.html.jsp.*;
/**
 * A Class class.
 * <P>
 * @author Juan Oropeza
 */
public class ExecuteSQLTag extends BodyTagSupport {

   String sAppName;
   
  /**
   * Constructor
   */
  public ExecuteSQLTag() {
  }

  public void setAppid(String sAppName)
  {
    this.sAppName = sAppName;
  }

   /**
   * doEndTag
   * @return int
   * @exception javax.servlet.jsp.JspException
   */
   public int doEndTag() throws JspException
   {
      try
      {
         if(this.bodyContent != null)
         {
              StringWriter strout = new StringWriter();

              bodyContent.writeOut(strout);

              String sQuery = strout.toString();

              // get appmodule instance
              ApplicationModule am = JSPApplicationRegistry
                .getInstance()
                .getAppModuleFromContexts(sAppName, pageContext.getSession(), pageContext);

              if(am == null)
              {
                   throw new RuntimeException("Unable to get Application Module instance[" + sAppName + "]");
              }

              am.getTransaction().executeCommand(sQuery);
         }
      }
      catch(Exception ex)
      {
         ex.printStackTrace(System.err);
         throw new JspException(ex.getMessage());
      }
      return Tag.EVAL_PAGE;
   }

  /**
   * doStartTag
   * @return int
   * @exception javax.servlet.jsp.JspException
   */
  public int doStartTag() throws JspException {

    return BodyTag.EVAL_BODY_TAG;
  }

  /**
     * release() called after doEndTag() to reset state
     */
  public void release()
  {
    super.release();

    sAppName = null;
  }
}

 