Package bsh

Examples of bsh.Interpreter


   {
      URL url = Thread.currentThread().getContextClassLoader().getResource(scriptName);
      if (url == null)
         throw new IllegalArgumentException("Resource not found: " + scriptName);

      interpreter = new Interpreter ();
      //System.out.println(Thread.currentThread().getContextClassLoader());
      interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
      //interpreter.eval (new java.io.InputStreamReader (url.openStream()), new NameSpace (this.rootContextName), this.rootContextName);
      interpreter.eval (new java.io.InputStreamReader (url.openStream()));
      //interpreter.source (url.getFile(), new bsh.NameSpace(this.rootContextName));
View Full Code Here


    public Object getComponentInstance(PicoContainer pico)
            throws PicoInitializationException, PicoIntrospectionException {

        if (instance == null) {
            try {
                Interpreter i = new Interpreter();
                i.set("adapter", this);
                i.set("picoContainer", pico);
                i.set("componentKey", getComponentKey());
                i.set("componentImplementation", getComponentImplementation());
                i.set("parameters", parameters != null ? Arrays.asList(parameters) : Collections.EMPTY_LIST);
                i.eval("import " + getComponentImplementation().getName() + ";");

                String scriptPath = "/" + getComponentImplementation().getName().replace('.', '/') + ".bsh";

                // Inside IDEA, this relies on the compilation output path being the same directory as the source path.
                // kludge - copy ScriptableDemoBean.bsh to the same location in the test output compile class path.
                // the same problem exists for maven, but some custom jelly script will be able to fix that.
                URL scriptURL = getComponentImplementation().getResource(scriptPath);
                if (scriptURL == null) {
                    throw new BeanShellScriptInitializationException("Couldn't load script at path " + scriptPath);
                }
                Reader sourceReader = new InputStreamReader(scriptURL.openStream());
                i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());

                instance = i.get("instance");
                if (instance == null) {
                    throw new BeanShellScriptInitializationException("The 'instance' variable was not instantiated");
                }
            } catch (EvalError e) {
                throw new BeanShellScriptInitializationException(e);
View Full Code Here

    public BeanShellContainerBuilder(URL script, ClassLoader classLoader) {
        super(script, classLoader);
    }
   
    protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) {
        Interpreter i = new Interpreter();
        try {
            i.set("parent", parentContainer);
            i.set("assemblyScope", assemblyScope);
            i.eval(getScriptReader(), i.getNameSpace(), "nanocontainer.bsh");
            return (PicoContainer) i.get("pico");
        } catch (EvalError e) {
            throw new NanoContainerMarkupException(e);
        } catch (IOException e) {
            throw new NanoContainerMarkupException(e);
        }
View Full Code Here

    * @param stream the stream
    * @throws Exception for any error
    */
   protected void loadScript (InputStream stream) throws Exception
   {
      Interpreter interpreter = new Interpreter ();
      interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
      interpreter.eval (new java.io.InputStreamReader (stream));

      scriptService = (ScriptService)interpreter.getInterface(ScriptService.class);

      // We now load the script preferences
      //
      String[] depends = null;
      try
      {
         depends = scriptService.dependsOn();
      }
      catch (Exception e)
      {
         log.trace("dependsOn", e);
      }
      if (depends != null)
      {
         dependsServices = new ObjectName[depends.length];
         for (int i=0; i<depends.length; i++)
            dependsServices[i] = new ObjectName (depends[i]);
      }

      String myName = null;
      try
      {
         myName = scriptService.objectName ();
      }
      catch (Exception e)
      {
         log.trace("objectName", e);
      }
      if (myName != null)
         this.preferedObjectName = new ObjectName (myName);

      Class[] intfs = null;
      try
      {
         intfs = scriptService.getInterfaces ();
         if (intfs != null)
            log.debug("getInterfaces=" + Arrays.asList(intfs));
      }
      catch (Exception e)
      {
         log.trace("getInterfaces", e);
      }
      if (intfs != null)
      {
         for (int i=0; i<intfs.length; i++)
         {
            Object iface = interpreter.getInterface(intfs[i]);
            supportedInterfaces.put (intfs[i], iface);
         }
      }

      this.mbeanInfo = generateMBeanInfo (intfs);
View Full Code Here

  {
    super();
   
    this.bshScript = bshScript;

    interpreter = new Interpreter();
   
    interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());

    try
    {
View Full Code Here

    public void resetBshInterpreter(Map<String, Object> context) {
        context.remove("bshInterpreter");
    }

    public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError {
        Interpreter bsh = (Interpreter) context.get("bshInterpreter");
        if (bsh == null) {
            bsh = BshUtil.makeInterpreter(context);
            context.put("bshInterpreter", bsh);
        }
        return bsh;
View Full Code Here

     */
    public String getStyleAltRowStyle(Map<String, Object> context) {
        String styles = "";
        try {
            // use the same Interpreter (ie with the same context setup) for all evals
            Interpreter bsh = this.getBshInterpreter(context);
            for (AltRowStyle altRowStyle : this.altRowStyles) {
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen));
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    if (boolVal.booleanValue()) {
                        styles += altRowStyle.style;
View Full Code Here

        public boolean shouldUse(Map<String, Object> context) {
            boolean shouldUse = true;
            String useWhen = this.getUseWhen(context);
            if (UtilValidate.isNotEmpty(useWhen)) {
                try {
                    Interpreter bsh = (Interpreter) context.get("bshInterpreter");
                    if (bsh == null) {
                        bsh = BshUtil.makeInterpreter(context);
                        context.put("bshInterpreter", bsh);
                    }

                    Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen));

                    // retVal should be a Boolean, if not something weird is up...
                    if (retVal instanceof Boolean) {
                        Boolean boolVal = (Boolean) retVal;
                        shouldUse = boolVal.booleanValue();
View Full Code Here

        String useWhenStr = this.getUseWhen(context);
        if (UtilValidate.isEmpty(useWhenStr)) {
            return true;
        } else {
            try {
                Interpreter bsh = this.modelForm.getBshInterpreter(context);
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

    public String getBoundaryCommentName() {
        return menuLocation + "#" + name;
    }

    public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError {
        Interpreter bsh = (Interpreter) context.get("bshInterpreter");
        if (bsh == null) {
            bsh = BshUtil.makeInterpreter(context);
            context.put("bshInterpreter", bsh);
        }
        return bsh;
View Full Code Here

TOP

Related Classes of bsh.Interpreter

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.