commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r425938 - in /jakarta/commons/sandbox/js2j/trunk: ./ src/main/java/org/apache/commons/js2j/
Date Thu, 27 Jul 2006 03:08:27 GMT
Author: mrdon
Date: Wed Jul 26 20:08:26 2006
New Revision: 425938

URL: http://svn.apache.org/viewvc?rev=425938&view=rev
Log:
Added main class to run shell, restored dynabean wrapper (optional)
cleaned up warnings

Added:
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/Main.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableDynaBean.java
      - copied, changed from r421489, struts/sandbox/trunk/flow/src/java/org/apache/struts/flow/sugar/ScriptableDynaBean.java
Removed:
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/package.html
Modified:
    jakarta/commons/sandbox/js2j/trunk/pom.xml
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/CollectionExtensions.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ExtensionFunction.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/FileExtensions.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/InputStreamExtensions.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/JavaObjectWrapper.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ListExtensions.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableList.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableMap.java
    jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/SugarWrapFactory.java

Modified: jakarta/commons/sandbox/js2j/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/pom.xml?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/pom.xml (original)
+++ jakarta/commons/sandbox/js2j/trunk/pom.xml Wed Jul 26 20:08:26 2006
@@ -83,31 +83,16 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+       <groupId>commons-beanutils</groupId>
+       <artifactId>commons-beanutils</artifactId>
+       <version>1.7.0</version>
+       <optional>true</optional>
+    </dependency>
   </dependencies>
 
   <build>
-    <sourceDirectory>src/main/java</sourceDirectory>
-    <testSourceDirectory>src/test/java</testSourceDirectory>
-    <resources>
-      <resource>
-        <directory>.</directory>
-        <targetPath>META-INF</targetPath>
-        <includes>
-          <include>NOTICE.txt</include>
-          <include>LICENSE.txt</include>
-        </includes>
-      </resource>
-    </resources>
-    <testResources>
-      <testResource>
-        <directory>src/test/java</directory>
-        <includes>
-          <include>**/*.xml</include>
-          <include>**/*.gif</include>
-        </includes>
-      </testResource>
-    </testResources>
-    <plugins>
+   <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
@@ -119,6 +104,21 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>org.apache.commons.js2j.Main</mainClass>
+            </manifest>  
+            <manifestEntries>
+              <mode>development</mode>
+              <url>${pom.url}</url>
+            </manifestEntries>
+          </archive>
+        </configuration>
       </plugin>
     </plugins>
   </build>

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/CollectionExtensions.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/CollectionExtensions.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/CollectionExtensions.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/CollectionExtensions.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,13 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
-import java.util.*;
-import java.io.Serializable;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Scriptable;
 
 /**
  * Adds various function extensions to java.util.List implementations.

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ExtensionFunction.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ExtensionFunction.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ExtensionFunction.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ExtensionFunction.java
Wed Jul 26 20:08:26 2006
@@ -15,9 +15,10 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
-import java.util.*;
-import java.io.Serializable;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
 
 /**
  *  Base class for function extensions.  A function extension is a function

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/FileExtensions.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/FileExtensions.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/FileExtensions.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/FileExtensions.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,17 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
 
-import java.io.*;
-import java.util.*;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Scriptable;
 
 /**
  * Adds various functions to java.io.File
@@ -126,7 +133,7 @@
                 
                 Object[] lines = new Object[list.size()];
                 for (int x=0; x<lines.length; x++) {
-                    lines[x] = cx.javaToJS(list.get(x), scope);
+                    lines[x] = Context.javaToJS(list.get(x), scope);
                 }
                 return cx.newArray(scope, lines);
             }

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/InputStreamExtensions.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/InputStreamExtensions.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/InputStreamExtensions.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/InputStreamExtensions.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,13 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 
-import java.io.*;
-import java.util.*;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
 
 /**
  * Adds various functions to java.io.InputStream

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/JavaObjectWrapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/JavaObjectWrapper.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/JavaObjectWrapper.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/JavaObjectWrapper.java
Wed Jul 26 20:08:26 2006
@@ -15,11 +15,15 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
-
-import java.util.*;
 import java.io.Serializable;
-import java.lang.reflect.*;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.NativeJavaObject;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Wrapper;
 
 /**
  * Adds support for extended functions to wrapped Java objects.

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ListExtensions.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ListExtensions.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ListExtensions.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ListExtensions.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,13 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
-import java.util.*;
-import java.io.Serializable;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Scriptable;
 
 /**
  * Adds various function extensions to java.util.List implementations.

Added: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/Main.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/Main.java?rev=425938&view=auto
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/Main.java (added)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/Main.java Wed
Jul 26 20:08:26 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 1006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.js2j;
+
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ContextFactory.Listener;
+
+/**
+ * Main class for shell and script execution.  Basically delegates to the Rhino
+ * shell, injecting the SugarWrapFactory first.
+ */
+public class Main {
+
+    public static void main(String[] args) {
+        org.mozilla.javascript.tools.shell.Main.shellContextFactory.addListener(new SugarListener());
+        org.mozilla.javascript.tools.shell.Main.main(args);
+    }
+
+    static class SugarListener implements Listener {
+
+        public void contextCreated(Context cx) {
+            cx.setWrapFactory(new SugarWrapFactory());
+        }
+
+        public void contextReleased(Context cx) {
+        }
+    }
+}

Copied: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableDynaBean.java
(from r421489, struts/sandbox/trunk/flow/src/java/org/apache/struts/flow/sugar/ScriptableDynaBean.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableDynaBean.java?p2=jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableDynaBean.java&p1=struts/sandbox/trunk/flow/src/java/org/apache/struts/flow/sugar/ScriptableDynaBean.java&r1=421489&r2=425938&rev=425938&view=diff
==============================================================================
--- struts/sandbox/trunk/flow/src/java/org/apache/struts/flow/sugar/ScriptableDynaBean.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableDynaBean.java
Wed Jul 26 20:08:26 2006
@@ -13,17 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.struts.flow.sugar;
+package org.apache.commons.js2j;
 
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaProperty;
 import org.mozilla.javascript.NativeJavaObject;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.Wrapper;
-import org.apache.commons.beanutils.DynaBean;
-import org.apache.commons.beanutils.DynaProperty;
-
-import java.io.Serializable;
-
-import java.util.Map;
 
 /**
  * Wrap a DynaBean for JavaScript.  Currently only supports named,

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableList.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableList.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableList.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,12 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
-
-import java.util.*;
 import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.Wrapper;
 
 /**  Wrap a java.util.List for JavaScript.  */
 public class ScriptableList extends JavaObjectWrapper implements Scriptable, Wrapper, Serializable
{
@@ -27,13 +29,11 @@
 
 
     public ScriptableList() {
-        this.list = list;
     }
 
 
     public ScriptableList(List list) {
         this.list = list;
-        this.javaObject = javaObject;
     }
 
 

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableMap.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableMap.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableMap.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/ScriptableMap.java
Wed Jul 26 20:08:26 2006
@@ -15,12 +15,12 @@
  */
 package org.apache.commons.js2j;
 
+import java.io.Serializable;
+import java.util.Map;
+
 import org.mozilla.javascript.NativeJavaObject;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.Wrapper;
-
-import java.util.Map;
-import java.io.Serializable;
 
 /**
  * Wrap a java.util.Map for JavaScript.

Modified: jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/SugarWrapFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/SugarWrapFactory.java?rev=425938&r1=425937&r2=425938&view=diff
==============================================================================
--- jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/SugarWrapFactory.java
(original)
+++ jakarta/commons/sandbox/js2j/trunk/src/main/java/org/apache/commons/js2j/SugarWrapFactory.java
Wed Jul 26 20:08:26 2006
@@ -15,10 +15,19 @@
  */
 package org.apache.commons.js2j;
 
-import org.mozilla.javascript.*;
-import java.io.*;
-import java.util.*;
-import java.lang.reflect.*;
+import java.io.FileReader;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ImporterTopLevel;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.WrapFactory;
 
 /**
  * Wraps Java objects by adding support for function extensions, which are
@@ -28,6 +37,7 @@
     
     private List functionRegistry = new ArrayList();
     private Map functionMappings = new HashMap();
+    private Class dynabeanClass;
     
     public SugarWrapFactory() {
         super();
@@ -37,6 +47,12 @@
         addExtensionFunctions(ListExtensions.class);
         addExtensionFunctions(FileExtensions.class);
         addExtensionFunctions(InputStreamExtensions.class);
+        
+        try {
+            dynabeanClass = Class.forName("org.apache.commons.beanutils.DynaBean");
+        } catch (ClassNotFoundException e) {
+            // Dynabeans not detected
+        }
     }
     
     public void addExtensionFunction(Class cls, String name, Method func) {
@@ -87,6 +103,8 @@
             wrap = new ScriptableMap(scope, javaObject, staticType, map);
         } else if (javaObject instanceof List) {
             wrap = new ScriptableList(scope, javaObject, staticType, map);
+        } else if (dynabeanClass != null && dynabeanClass.isAssignableFrom(javaObject.getClass()))
{
+            new ScriptableDynaBean(scope, javaObject, staticType, map);
         } else {
             wrap = new JavaObjectWrapper(scope, javaObject, staticType, map);
         }
@@ -137,7 +155,7 @@
             Object result = cx.evaluateReader(scope, reader, args[0], 1, null);
         
             // Convert the result to a string and print it.
-            System.err.println(cx.toString(result));
+            System.err.println(Context.toString(result));
         } finally {
             // Exit from the context.
             Context.exit();



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message