Package de.iritgo.aktera.clients

Examples of de.iritgo.aktera.clients.ResponseElementDynaBean


      re = (ResponseElement) i.next();

      internationalize(re, messages);

      /* Now make a dynabean for the given element */
      ResponseElementDynaBean reAsBean = new ResponseElementDynaBean(re);

      wreq.setAttribute(re.getName(), reAsBean);

      if (re instanceof Input)
      {
        inputs.add(reAsBean);
      }
      else if (re instanceof Output)
      {
        // HACK: For the moment, if re is output file, write to stream
        // here, as not being written otherwise
        final String outputType = (String) re.getAttribute("type");

        if ((outputType != null) && outputType.equals("binary"))
        {
          // Binary data, so dump to output stream now....
          log.debug("File Data is available");

          final BinaryWrapper data = (BinaryWrapper) ((Output) re).getContent();

          //          hres.setContentLength(new
          //          Integer(((Long)re.getAttribute("ContentLength")).toString()).intValue());
          final long dataSize = data.getSize();

          if ((dataSize > 0) && (dataSize < Integer.MAX_VALUE))
          {
            // Have a valid content length.
            hres.setContentLength((int) data.getSize());
          }

          hres.setContentType(data.getContentType());
          hres.setHeader("Content-Disposition", (String) re.getAttribute("Content-Disposition"));

          //          String encodings = hreq.getHeader ("Accept-Encoding");
          BufferedOutputStream buffOut = null;

          try
          {
            // BUG #844574:Writing using GZip compression is very
            // slow
            // HACK: Disable GZip compression until speed/threading
            // issues are worked out.
            //            if (encodings != null && encodings.indexOf ("gzip") != -1)
            //            {
            //              log.info ("Writing data using GZip compression");
            //
            //              final OutputStream out = hres.getOutputStream ();
            //
            //              buffOut = new BufferedOutputStream(
            //                  new GZIPOutputStream(out), BUFFER_SIZE);
            //              hres.setHeader ("Content-Encoding", "gzip");
            //            }
            //            else
            //            {
            log.info("Writing data with no compression");

            OutputStream out = hres.getOutputStream();

            buffOut = new BufferedOutputStream(out, BUFFER_SIZE);
            //            }
            data.writeTo(buffOut);
            log.trace("Wrote Buffer.");
          }
          catch (IOException e)
          {
            e.printStackTrace();
            log.error("Exception during file read/write:", e);
            throw new ClientException("Exception during file read/write", e);
          }
          finally
          {
            // Flush all streams, and close input streams
            try
            {
              data.close();
            }
            catch (IOException e1)
            {
              e1.printStackTrace();
            }

            try
            {
              buffOut.flush();
            }
            catch (IOException e2)
            {
              e2.printStackTrace();
            }

            // Do NOT close the Output stream here, as the
            // underlying output stream is/should be closed later.
          }
        }
        else
        {
          outputs.add(reAsBean);
        }
      }
      else if (re instanceof Command)
      {
        commands.add(reAsBean);
      }
    }

    wreq.setAttribute("inputs", inputs);
    wreq.setAttribute("outputs", outputs);
    wreq.setAttribute("commands", commands);

    int inputCount = 0;
    DynaProperty[] dps = new DynaProperty[inputs.size()];
    ResponseElementDynaBean oneInput = null;

    for (Iterator ii = inputs.iterator(); ii.hasNext();)
    {
      oneInput = (ResponseElementDynaBean) ii.next();

      Object defValue = oneInput.get("defaultValue");
      DynaProperty dp = null;

      if (defValue != null)
      {
        dp = new DynaProperty((String) oneInput.get("name"), oneInput.get("defaultValue").getClass());
      }
      else
      {
        try
        {
          dp = new DynaProperty((String) oneInput.get("name"), Class.forName("java.lang.String"));
        }
        catch (ClassNotFoundException e)
        {
          throw new ClientException("Cannot create String dynaproperty", e);
        }
      }

      dps[inputCount++] = dp;
    }

    BasicDynaClass bd;

    try
    {
      bd = new BasicDynaClass(modelName, Class.forName("org.apache.commons.beanutils.BasicDynaBean"), dps);

      BasicDynaBean newForm = (BasicDynaBean) bd.newInstance();

      // Now populate the newForm's properties
      for (Iterator i2 = inputs.iterator(); i2.hasNext();)
      {
        oneInput = (ResponseElementDynaBean) i2.next();
        newForm.set((String) oneInput.get("name"), oneInput.get("defaultValue"));
      }

      wreq.setAttribute("default", newForm);
    }
    catch (ClassNotFoundException e)
View Full Code Here


    Object o = TagUtils.getInstance().lookup(pageContext, name, property, null);

    if (o instanceof ResponseElementDynaBean)
    {
      ResponseElementDynaBean bean = (ResponseElementDynaBean) o;
      String type = (String) bean.get("type");

      if (! type.equals("command"))
      {
        throw new JspException("Element '" + name + "/" + property + "' was not a command, it was a '" + type
                + "'");
      }

      commandName = (String) bean.get("name");
      commandModel = (String) bean.get("model");
      commandBean = (String) bean.get("bean");
      commandLabel = (String) bean.get("label");
      cp = (Map) bean.get("parameters");
    }
    else if (o instanceof Command)
    {
      Command c = (Command) o;
View Full Code Here

    for (Iterator i = allElements; i.hasNext();)
    {
      re = (ResponseElement) i.next();
      internationalize(re, messages);

      ResponseElementDynaBean reAsBean = new ResponseElementDynaBean(re);

      request.setAttribute(re.getName(), reAsBean);

      if (re instanceof Input)
      {
        inputs.add(reAsBean);
      }
      else if (re instanceof Output)
      {
        // HACK: For the moment, if re is output file, write to stream
        // here, as not being written otherwise
        final String outputType = (String) re.getAttribute("type");

        if ((outputType != null) && outputType.equals("binary"))
        {
          // Binary data, so dump to output stream now....
          log.debug("File Data is available");

          final BinaryWrapper data = (BinaryWrapper) ((Output) re).getContent();

          // hres.setContentLength(new
          // Integer(((Long)re.getAttribute("ContentLength")).toString()).intValue());
          final long dataSize = data.getSize();

          if ((dataSize > 0) && (dataSize < Integer.MAX_VALUE))
          {
            // Have a valid content length.
            response.setContentLength((int) data.getSize());
          }

          response.setContentType(data.getContentType());
          response.setHeader("Content-Disposition", (String) re.getAttribute("Content-Disposition"));

          // String encodings = hreq.getHeader ("Accept-Encoding");
          BufferedOutputStream buffOut = null;

          try
          {
            log.info("Writing data with no compression");

            OutputStream out = response.getOutputStream();

            buffOut = new BufferedOutputStream(out, BUFFER_SIZE);
            data.writeTo(buffOut);
            log.trace("Wrote Buffer.");
          }
          catch (IOException e)
          {
            e.printStackTrace();
            log.error("Exception during file read/write:", e);
            throw new ClientException("Exception during file read/write", e);
          }
          finally
          {
            try
            {
              data.close();
            }
            catch (IOException e1)
            {
              e1.printStackTrace();
            }

            try
            {
              buffOut.flush();
            }
            catch (IOException e2)
            {
              e2.printStackTrace();
            }
          }
        }
        else
        {
          outputs.add(reAsBean);
        }
      }
      else if (re instanceof Command)
      {
        commands.add(reAsBean);
      }
    }

    request.setAttribute("inputs", inputs);
    request.setAttribute("outputs", outputs);
    request.setAttribute("commands", commands);

    int inputCount = 0;
    DynaProperty[] dps = new DynaProperty[inputs.size()];
    ResponseElementDynaBean oneInput = null;

    for (Iterator ii = inputs.iterator(); ii.hasNext();)
    {
      oneInput = (ResponseElementDynaBean) ii.next();

      Object defValue = oneInput.get("defaultValue");
      DynaProperty dp = null;

      if (defValue != null)
      {
        dp = new DynaProperty((String) oneInput.get("name"), oneInput.get("defaultValue").getClass());
      }
      else
      {
        try
        {
          dp = new DynaProperty((String) oneInput.get("name"), Class.forName("java.lang.String"));
        }
        catch (ClassNotFoundException e)
        {
          throw new ClientException("Cannot create String dynaproperty", e);
        }
      }

      dps[inputCount++] = dp;
    }

    BasicDynaClass bd;

    try
    {
      bd = new BasicDynaClass(beanName, Class.forName("org.apache.commons.beanutils.BasicDynaBean"), dps);

      BasicDynaBean newForm = (BasicDynaBean) bd.newInstance();

      for (Iterator i2 = inputs.iterator(); i2.hasNext();)
      {
        oneInput = (ResponseElementDynaBean) i2.next();
        newForm.set((String) oneInput.get("name"), oneInput.get("defaultValue"));
      }

      request.setAttribute("default", newForm);
    }
    catch (ClassNotFoundException e)
View Full Code Here

      {
        ResponseElement element = (ResponseElement) i.next();

        if (element instanceof Output)
        {
          ResponseElementDynaBean elementAsBean = new ResponseElementDynaBean(element);

          pageContext.setAttribute(element.getName(), elementAsBean, getScope(scope));
        }
      }
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.clients.ResponseElementDynaBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.