Package org.apache.bsf

Examples of org.apache.bsf.BSFException


            if(javaclass != null) {
                classname=javaclass.getName();
            } else {
                gf = openUniqueFile(tempDir, "BSFJava",".java");
                if( gf == null) {
                    throw new BSFException("couldn't create JavaEngine scratchfile");
                }
                // Obtain classname
                classname = gf.className;
               
                // Write the kluge header to the file.
                gf.fos.write(("import java.lang.*;"+
                        "import java.util.*;"+
                        "public class "+classname+" {\n" +
                "  static public Object BSFJavaEngineEntry(org.apache.bsf.BSFManager bsf) {\n")
                .getBytes());
               
                // Edit the script to replace placeholder with the generated
                // classname. Note that this occurs _after_ the cache was checked!
                int startpoint = script.indexOf(placeholder);
                int endpoint;
                if(startpoint >= 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();
                    }
                }
               
                // MJD - debug
//              BSFDeclaredBean tempBean;
//              String          className;
//             
//              for (int i = 0; i < declaredBeans.size (); i++) {
//              tempBean  = (BSFDeclaredBean) declaredBeans.elementAt (i);
//              className = StringUtils.getClassName (tempBean.bean.getClass ());
//             
//              gf.fos.write ((className + " " +
//              tempBean.name + " = (" + className +
//              ")bsf.lookupBean(\"" +
//              tempBean.name + "\");").getBytes ());
//              }
                // MJD - debug
               
                // Copy the input to the file.
                // Assumes all available -- probably mistake, but same as other engines.
                gf.fos.write(script.getBytes());
                // Close the method and class
                gf.fos.write(("\n  }\n}\n").getBytes());
                gf.fos.close();
               
                // Compile through Java to .class file
                // May not be threadsafe. Serialize access on static object:
                synchronized(serializeCompilation) {
                    JavaUtils.JDKcompile(gf.file.getPath(), classPath);
                }
               
                // Load class.
                javaclass = EngineUtils.loadClass(mgr, classname);
               
                // Stash class for reuse
                codeToClass.put(basescript, javaclass);
            }
           
            Object[] callArgs = {mgr};     
            retval = internalCall(this,"BSFJavaEngineEntry",callArgs);
        }
       
       
        catch(Exception e) {
            e.printStackTrace ();
            throw new BSFException (BSFException.REASON_IO_ERROR, e.getMessage ());
        } finally {
            // Cleanup: delete the .java and .class files
           
//          if(gf!=null && gf.file!=null && gf.file.exists())
//          gf.file.delete();  // .java file
View Full Code Here


                Method m = MethodUtils.getMethod(javaclass, method, argtypes);
                retval = m.invoke(null, args);
            }
        }
        catch(Exception e) {
            throw new BSFException (BSFException.REASON_IO_ERROR, e.getMessage ());
        }
        return retval;
    }
View Full Code Here

            // corrected the situation by aborting the loop and
            // a long stacktrace would end up on the user's console
            throw (Error) t;
        }
        else {
            throw new BSFException(BSFException.REASON_OTHER_ERROR,
                                   "JavaScript Error: " + message,
                                   target);
        }
    }
View Full Code Here

        try {
            ReflectionUtils.addEventListener (bean, eventSetName, ep);
        } catch (Exception e) {
            e.printStackTrace ();
            throw new BSFException (BSFException.REASON_OTHER_ERROR,
                                    "ouch while adding event listener: "
                                    + e, e);
        }
    }
View Full Code Here

        try {
            ReflectionUtils.addEventListener (bean, eventSetName, ep);
        } catch (Exception e) {
            e.printStackTrace ();
            throw new BSFException (BSFException.REASON_OTHER_ERROR,
                                    "ouch while adding event listener: "
                                    + e, e);
        }
    }
View Full Code Here

        } catch (Exception e) {
            // something went wrong while invoking method
            Throwable t = (e instanceof InvocationTargetException) ?
                          ((InvocationTargetException)e).getTargetException () :
                          null;
            throw new BSFException (BSFException.REASON_OTHER_ERROR,
                                    "method invocation failed: " + e +
                                    ((t==null) ? "" :
                                     (" target exception: " + t)), t);
        }
    }
View Full Code Here

                    // throw the previous exception
                    throw me;
                }
            }
        } catch (Exception e) {
            throw new BSFException (BSFException.REASON_OTHER_ERROR,
                                    e.getMessage (), e);
        }
    }
View Full Code Here

                if (bsfCL == null)
                    bsfCL = new BSFClassLoader ();
                bsfCL.setTempDir (mgr.getTempDir ());
                return bsfCL.loadClass (name);
            } catch (ClassNotFoundException e2) {
                throw new BSFException (BSFException.REASON_OTHER_ERROR,
                        "unable to load class '" + name + "':" + e, e);
            }
        }
    }
View Full Code Here

                jExpr = ScriptFactory.createScript((String) expr);
            }
            return jExpr.execute(jc);
        } catch (Exception e) {
            // TODO Better messages
            throw new BSFException(e.getMessage());
        }
    }
View Full Code Here

            } else {
                jExpr = ScriptFactory.createScript((String) script);
            }
            jExpr.execute(jc);
        } catch (Exception e) {
            throw new BSFException(e.getMessage());
        }
    }
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.