Package org.apache.bsf

Examples of org.apache.bsf.BSFException


      if (e instanceof InvocationTargetException)
      {
        Throwable t = ((InvocationTargetException)e).getTargetException ();
        t.printStackTrace ();
      }
      throw new BSFException (BSFException.REASON_IO_ERROR,
                  e.getMessage (),
                  e);
    }
    return retval;
  }
View Full Code Here


      }
                    else
      {
                            gf=openUniqueFile(tempDir,"BSFNetRexx",".nrx");
                            if(gf==null)
                                throw new BSFException("couldn't create NetRexx scratchfile");
                           
                            // Obtain classname
                            classname=gf.className;
                           
                            // Decide whether to declare a return type
                            String returnsDecl="";
                            if(returnsObject)
                                returnsDecl="returns java.lang.Object";
                           
                            // Write the kluge header to the file.
                            // ***** By doing so we give up the ability to use Property blocks.
                            gf.fos.write(("class "+classname+";\n")
                                         .getBytes());
                            gf.fos.write(
                                         ("method BSFNetRexxEngineEntry(bsf=org.apache.bsf.util.BSFFunctions) "+
                                          " public static "+returnsDecl+";\n")
                 .getBytes());
       
                            // Edit the script to replace placeholder with the generated
                            // classname. Note that this occurs _after_ the cache was
                            // checked!
                            int startpoint,endpoint;
                            if((startpoint=script.indexOf(placeholder))>=0)
        {
                                    StringBuffer changed=new StringBuffer();
                                    for(;
                                        startpoint>=0;
                                        startpoint=script.indexOf(placeholder,startpoint))
          {
                                            changed.setLength(0);   // Reset for 2nd pass or later
                                            if(startpoint>0)
                                                changed.append(script.substring(0,startpoint));
                                            changed.append(classname);
                                            endpoint=startpoint+placeholder.length();
                                            if(endpoint<script.length())
                                                changed.append(script.substring(endpoint));
                                            script=changed.toString();
          }
        }
                           
                            BSFDeclaredBean tempBean;
                            String          className;
                           
                            for (int i = 0; i < declaredBeans.size (); i++)
        {
                                    tempBean  = (BSFDeclaredBean) declaredBeans.elementAt (i);
                                    className = StringUtils.getClassName (tempBean.type);
                                   
                                    gf.fos.write ((tempBean.name + " =" + className + "   bsf.lookupBean(\"" +
                                                   tempBean.name + "\");").getBytes());
        }
                           
                            if(returnsObject)
                                gf.fos.write("return ".getBytes());
                           
                            // Copy the input to the file.
                            // Assumes all available -- probably mistake, but same as
                            // other engines.
                            gf.fos.write(script.getBytes());
                            gf.fos.close();
                           
                            logger.debug("NetRexxEngine: wrote temp file " +
                                                   gf.file.getPath () + ", now compiling");
                           
                            // Compile through Java to .class file
                    String command=gf.file.getPath(); //classname;
                    if (logger.isDebugEnabled()) { 
                      command += " -verbose4";
                    } else {
                        command += " -noverbose";
                        command += " -noconsole";
                    }
                   
                    netrexx.lang.Rexx cmdline= new netrexx.lang.Rexx(command);
                    int retValue;
                   
                    // May not be threadsafe. Serialize access on static object:
                    synchronized(serializeCompilation)
                        {
                            // compile to a .java file
                            retValue =
                                COM.ibm.netrexx.process.NetRexxC.main(cmdline,
                                                                      new PrintWriter(System.err));
                        }

        // Check if there were errors while compiling the Rexx code.
        if (retValue == 2)
        {
          throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
                     "There were NetRexx errors.");
        }

        // Load class.
                logger.debug("NetRexxEngine: loading class "+classname);
        rexxclass=EngineUtils.loadClass (mgr, classname);

        // Stash class for reuse
        codeToClass.put(basescript,rexxclass);
                        }

      Object[] args={mgrfuncs};
      retval=callStatic(rexxclass, "BSFNetRexxEngineEntry",args);
                }
                catch (BSFException e)
                    {
                        // Just forward the exception on.
                        throw e;
                    }
                catch(Exception e)
                    {
      e.printStackTrace ();
      if (e instanceof InvocationTargetException)
      {
        Throwable t = ((InvocationTargetException)e).getTargetException ();
        t.printStackTrace ();
      }
      throw new BSFException (BSFException.REASON_IO_ERROR,
                  e.getMessage (), e);
    }
    finally
    {
      // Cleanup: delete the .nrx and .class files
View Full Code Here

        cb.addServiceMethodException("org.apache.bsf.BSFException");
    }

    public void declareBean(BSFDeclaredBean bean) throws BSFException {
        throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
                               "language " + lang +
                               " does not support declareBean(...).");
    }
View Full Code Here

        declaredBeans = null;
        classLoader = null;
    }
   
    public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
        throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
                               "language " + lang +
                               " does not support undeclareBean(...).");
    }
View Full Code Here

              return unwrap(m.__call__(pyargs));
          }

          return null;
      } catch (PyException e) {
          throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
                                  "exception from Jython:\n" + e, e);
      }
  }
View Full Code Here

         
          if (result != null && result instanceof PyJavaInstance)
              result = ((PyJavaInstance)result).__tojava__(Object.class);
          return result;
      } catch (PyException e) {
          throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
                                  "exception from Jython:\n" + e, e);
      }
  }
View Full Code Here

    Object result = interp.eval (byteify(script.toString ()));
    if (result != null && result instanceof PyJavaInstance)
    result = ((PyJavaInstance)result).__tojava__(Object.class);
    return result;
  } catch (PyException e) {
    throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
            "exception from Jython:\n" + e, e);
  }
  }
View Full Code Here

  public void exec (String source, int lineNo, int columnNo,
        Object script) throws BSFException {
  try {
    interp.exec (byteify(script.toString ()));
  } catch (PyException e) {
    throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
            "exception from Jython:\n" + e, e);
  }
  }
View Full Code Here

          interp.buffer.append(scriptStr);
          if (!(interp.runsource(interp.buffer.toString())))
              interp.resetbuffer();
      } catch (PyException e) {
          interp.resetbuffer();
          throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
                                 "exception from Jython:\n" + e, e);
      }
  }
View Full Code Here

    }
   
    public Object call (Object object, String method, Object[] args)
    throws BSFException
    {
        throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE,
        "call() is not currently supported by JavaEngine");
    }
View Full Code Here

TOP

Related Classes of org.apache.bsf.BSFException

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.