Examples of Interpreter


Examples of bsh.Interpreter

    }

    int iDominId = 0;
    int iRetVal;

    Interpreter oInterpreter = new Interpreter();

    oInterpreter.set ("DomainNm", sDomainNm);
    oInterpreter.set ("DefaultConnection", oConn);
    oInterpreter.set ("AlternativeConnection", oConn);

    if (DebugFile.trace) DebugFile.writeln("Interpreter.eval(getResourceAsString(scripts/domain_create.js,"+sEncoding);

    oInterpreter.eval(getResourceAsString("scripts/domain_create.js", sEncoding));

    Object obj = oInterpreter.get("ErrorCode");

    Integer oCodError = (Integer) oInterpreter.get("ErrorCode");

    if (oCodError.intValue()!=0) {
      sErrMsg = (String) oInterpreter.get("ErrorMessage");
      iErrors++;
      if (null!=oStrLog) oStrLog.append("EvalError: " + sErrMsg + "\n");
      if (DebugFile.trace) {
        DebugFile.writeln("SQLException "+sErrMsg);
        DebugFile.decIdent();
      }
      throw new SQLException(sErrMsg);
    } // fi ()

    obj = oInterpreter.get("ReturnValue");

    if ( null != obj ) {
      iDominId = ( (Integer) obj).intValue();

      Statement oStmt = oConn.createStatement();
      if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE k_workareas SET nm_workarea='" + sDomainNm.toLowerCase() + "_default' WHERE id_domain=" + String.valueOf(iDominId) + " AND nm_workarea='model_default')");
      oStmt.executeUpdate("UPDATE k_workareas SET nm_workarea='" + sDomainNm.toLowerCase() + "_default' WHERE id_domain=" + String.valueOf(iDominId) + " AND nm_workarea='model_default'");
      oStmt.close();

      if (null!=oStrLog) oStrLog.append("New Domain " + oInterpreter.get("ReturnValue") + " created successfully\n");
      iRetVal = iDominId;
    }
    else {
      if (null!=oStrLog) oStrLog.append( oInterpreter.get("ErrorMessage") + ": Domain not created.");
      iRetVal = 0;
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
View Full Code Here

Examples of bsh.Interpreter

    String sErrMsg = null;
    String sRetVal = null;
  Integer oCodError = new Integer(0);
 
    Interpreter oInterpreter = new Interpreter();
    try {
      oInterpreter.set ("UserId", sUserId);
      oInterpreter.set ("DefaultConnection", new JDCConnection(oConn,null));
      if (DebugFile.trace) DebugFile.writeln("Interpreter.eval(getResourceAsString(scripts/user_categories_create.js,"+sEncoding);
      oInterpreter.eval(getResourceAsString("scripts/user_categories_create.js", sEncoding));
      Object obj = oInterpreter.get("ErrorCode");
      oCodError = (Integer) oInterpreter.get("ErrorCode");
      if (oCodError.intValue()==0) {
        sErrMsg = (String) oInterpreter.get("ErrorMessage");
        sRetVal = (String) oInterpreter.get("ReturnValue");
      }
    } catch (EvalError ee) {
      if (DebugFile.trace) {
        DebugFile.writeln("EvalError at user_categories_create.js "+ee.getMessage());
        DebugFile.decIdent();
View Full Code Here

Examples of bsh.Interpreter

  public void trigger (JDCConnection oConn, Map oParameters, Properties oEnvironment) throws Exception {
 
  String sScriptCode = getResourceAsString("scripts/"+getEventId()+".js", "UTF-8");

  if (null!=sScriptCode) {
      Interpreter oInterpreter = new Interpreter();

      oInterpreter.set ("Parameters", oParameters);
      oInterpreter.set ("EnvironmentProperties", oEnvironment);
      oInterpreter.eval(sScriptCode);

      Object obj = oInterpreter.get("ErrorCode");

      Integer oCodError = (Integer) oInterpreter.get("ErrorCode");

      if (oCodError.compareTo(new Integer (0))!=0) {
        throw new Exception((String) oInterpreter.get("ErrorMessage"));
      }
  } // fi
  } // trigger
View Full Code Here

Examples of bsh.Interpreter

    * @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

Examples of bsh.Interpreter

   * @param prereq
   * @return true if ???
   */
  public boolean checkPrerequisites(String prereq) {
    try {
      Interpreter i = new Interpreter(); // Construct an interpreter
      StringTokenizer st1 = new StringTokenizer(prereq, "&|()~");
      StringTokenizer itemAndValue;
      String aToken = "";
      while (st1.hasMoreTokens()) {
        aToken = st1.nextToken();
        // if theres no value in quotes to check against..
        if (aToken.indexOf("=") == -1 && aToken.indexOf("<>") == -1) {
          // get boolean status
          if (!doesItemExist(aToken)) {
            // System.out.println("item does not exist"+ aToken);
            return true;// identifer does not exist, so junk.
          }
          // item exists in prerequisites table. Has it been completed
          // or passed -grab the answer and declare the var for the interpreter
          i.set(aToken.replaceAll("-", "_"), checkStatus(aToken));
        } else {
          itemAndValue = new StringTokenizer(aToken, "=<>");
          String anToken = itemAndValue.nextToken();
          if (!doesItemExist(anToken)) { return true; // identifer does not
          // exist, so junk..
          }
          // item exists in prerequisites table. Has it been
          // completed or passed -grab the answer and declare
          // the var for the interpreter...
          i.set(anToken.replaceAll("-", "_"), getStatus(anToken));
        }
      }
      // System.out.println("0. "+prereq);
      prereq = prereq.replaceAll("-", "_");
      prereq = prereq.replaceAll("&", "&&");
      prereq = prereq.replaceAll("\\|", "||");
      prereq = prereq.replaceAll("~", "!");
      prereq = prereq.replaceAll("<>\\\"", "@");
      prereq = prereq.replaceAll("=\\\"", "^");
      prereq = prereq.replaceAll("\\\"", "\")");
      prereq = prereq.replaceAll("\\^", "=\\\"");
      prereq = prereq.replaceAll("=", ".equals(");
      // System.out.println("1. "+prereq);
      if (prereq.indexOf("@") != -1) {
        Vector v = new Vector();
        StringBuilder sb = new StringBuilder();
        sb.append(prereq);
        boolean notSymbFound = false;
        // go backwards char at a time. if you find &}"|& then insert a
        // !)
        for (int j = sb.length() - 1; j > -1; j--) {
          if (sb.charAt(j) == '@') {
            notSymbFound = true;
          }
          if (notSymbFound) {
            if (sb.charAt(j) == '|' || sb.charAt(j) == '&' || sb.charAt(j) == '"' || sb.charAt(j) == '}' || sb.charAt(j) == ')') {
              notSymbFound = false;
              v.add(j + 1 + "");
            }
          }
        }
        Iterator it = v.iterator();
        while (it.hasNext()) {
          sb.insert(Integer.parseInt(it.next().toString()), '!');
        }
        if (notSymbFound) {
          // the ! must be at the beginning
          prereq = "!" + sb.toString();
        } else {
          prereq = sb.toString();
        }
      }
      prereq = prereq.replaceAll("@", ".equals(\"");
      Object result = i.eval(prereq);
      String a = result.toString();
      boolean retVal = Boolean.valueOf(a).booleanValue();
      if (Tracing.isDebugEnabled(PrerequisiteManager.class)){
        Tracing.logDebug("eval: " + prereq + " result was: " + retVal,PrerequisiteManager.class);
      }
View Full Code Here

Examples of bsh.Interpreter

        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

Examples of bsh.Interpreter

        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

Examples of bsh.Interpreter

    return result;
  }
 
  private static Interpreter getInterpreter() {
    if(null == s_interpreter) {
      s_interpreter= new Interpreter();
    }
   
    return s_interpreter;
  }
View Full Code Here

Examples of bsh.Interpreter

  }
 
  private boolean includeMethodFromExpression(ITestNGMethod tm,  boolean isTestMethod) {
    boolean result = false;

    Interpreter interpreter= getInterpreter();
    try {
      Map<String, String> groups = new HashMap<String, String>();
      for (String group : tm.getGroups()) {
        groups.put(group, group);
      }
      setContext(interpreter, tm.getMethod(), groups, tm);
      Object evalResult = interpreter.eval(m_expression);
      result = ((Boolean) evalResult).booleanValue();
    }
    catch (EvalError evalError) {
      Utils.log("bsh.Interpreter", 2, "Cannot evaluate expression:" + m_expression + ":" + evalError.getMessage());
    }
View Full Code Here

Examples of bsh.Interpreter

     */
    private String script;

    public void execute() throws MojoExecutionException
    {
        Interpreter terp = new Interpreter();

        try
        {
            getLog().info( "Executing in java version: " + System.getProperty( "java.version" ) );
           
            Object result = terp.eval( script );

            getLog().info( "Result of script evaluation was: " + result + "\nLoaded from: " + result.getClass().getClassLoader() );
        }
        catch ( EvalError e )
        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.