ovidiu      02/04/09 17:41:56

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript
                        JavaScriptInterpreter.java
  Log:
  Setup parameters so they can be accessed as a native JavaScript array
  using cocoon.parameters.
  
  Revision  Changes    Path
  1.2       +36 -6     
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
  
  Index: JavaScriptInterpreter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaScriptInterpreter.java        2 Apr 2002 05:37:16 -0000       1.1
  +++ JavaScriptInterpreter.java        10 Apr 2002 00:41:56 -0000      1.2
  @@ -146,6 +146,18 @@
       return source;
     }
   
  +  /**
  +   * Calls a JavaScript function, passing <code>params</code> as its
  +   * arguments. In addition to this, it makes available the parameters
  +   * through the <code>cocoon.parameters</code> JavaScript array
  +   * (indexed by the parameter names).
  +   *
  +   * @param funName a <code>String</code> value
  +   * @param params a <code>List</code> value
  +   * @param environment an <code>Environment</code> value
  +   * @param ctx an <code>InvokeContext</code> value
  +   * @exception Exception if an error occurs
  +   */
     public void callFunction(String funName, List params,
                              Environment environment, InvokeContext ctx)
       throws Exception
  @@ -156,6 +168,7 @@
   
       try {
         thrScope = enterContext(environment, ctx);
  +      JSCocoon cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
   
         Object callFunction = scope.get("callFunction", thrScope);
         if (callFunction == Scriptable.NOT_FOUND)
  @@ -172,15 +185,19 @@
   
         int size = (params != null ? params.size() : 0);
         Object[] funArgs = new Object[size];
  +      NativeArray funArgsArray = new NativeArray(funArgs);
  +      NativeArray parameters = new NativeArray(size);
  +
         if (size != 0) {
           for (int i = 0; i < size; i++) {
  -          Object obj = ((Interpreter.Argument)params.get(i)).value;
  -          funArgs[i] = ScriptRuntime.toObject(cx, thrScope, obj);
  +          Interpreter.Argument arg = (Interpreter.Argument)params.get(i);
  +          funArgs[i] = ScriptRuntime.toObject(cx, thrScope, arg.value);
  +          parameters.put(arg.name, parameters, arg.value);
           }
         }
  -      NativeArray funArgsArray = new NativeArray(funArgs);
  -      Object callFunArgs[] = { fun, funArgsArray };
   
  +      cocoon.setParameters(parameters);
  +      Object callFunArgs[] = { fun, funArgsArray };
         ((Function) callFunction).call(cx, thrScope, thrScope, callFunArgs);
       }
       finally {
  @@ -188,8 +205,8 @@
       }
     }
   
  -  public void handleContinuation(String id,
  -                          Environment environment, InvokeContext ctx)
  +  public void handleContinuation(String id, List params,
  +                                 Environment environment, InvokeContext ctx)
       throws Exception
     {
       WebContinuation wk = continuationsMgr.lookupWebContinuation(id);
  @@ -217,6 +234,19 @@
                                    + "(system.js not loaded?)");
   
       Object args[] = { jswk };
  +
  +    int size = (params != null ? params.size() : 0);
  +    NativeArray parameters = new NativeArray(size);
  +
  +    if (size != 0) {
  +      for (int i = 0; i < size; i++) {
  +        Interpreter.Argument arg = (Interpreter.Argument)params.get(i);
  +        parameters.put(arg.name, parameters, arg.value);
  +      }
  +    }
  +
  +    cocoon.setParameters(parameters);
  +
       try {
         ((Function)handleContFunction).call(context, kScope, kScope, args);
       }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to