commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pete Kazmier" <...@apache.org>
Subject [Jelly][PATCH] BSF Script Patch
Date Wed, 05 Mar 2003 00:47:05 GMT
Index: jelly-tags/bsf/project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/project.xml,v
retrieving revision 1.4
diff -u -r1.4 project.xml
--- jelly-tags/bsf/project.xml	27 Jan 2003 05:24:17 -0000	1.4
+++ jelly-tags/bsf/project.xml	5 Mar 2003 00:25:08 -0000
@@ -30,7 +30,7 @@
 
     <dependency>
       <id>bsf</id>
-      <version>2.2</version>
+      <version>2.3-rc1</version>
       <url>http://jakarta.apache.org/bsf</url>
     </dependency>
     <!-- END for compilation -->
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java,v
retrieving revision 1.1
diff -u -r1.1 BSFExpression.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java	8 Jan 2003
05:02:48 -0000	1.1
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java	5 Mar 2003
00:25:08 -0000
@@ -61,8 +61,8 @@
  */
 package org.apache.commons.jelly.tags.bsf;
 
-import com.ibm.bsf.BSFEngine;
-import com.ibm.bsf.BSFManager;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFManager;
 
 import java.util.Iterator;
 
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java,v
retrieving revision 1.2
diff -u -r1.2 BSFExpressionFactory.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java	24
Jan 2003 07:40:58 -0000	1.2
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java	5
Mar 2003 00:25:08 -0000
@@ -67,9 +67,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import com.ibm.bsf.BSFEngine;
-import com.ibm.bsf.BSFException;
-import com.ibm.bsf.BSFManager;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
 
 /** Represents a factory of BSF expressions
   *
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java,v
retrieving revision 1.2
diff -u -r1.2 BSFTagLibrary.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java	20 Feb 2003
18:56:16 -0000	1.2
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java	5 Mar 2003
00:25:09 -0000
@@ -68,8 +68,8 @@
 import org.apache.commons.jelly.tags.core.CoreTagLibrary;
 import org.xml.sax.Attributes;
 
-import com.ibm.bsf.BSFEngine;
-import com.ibm.bsf.BSFException;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
 
 
 /** Describes the Taglib. This class could be generated by XDoclet
@@ -83,14 +83,14 @@
     
     public BSFTagLibrary() {
         registerTagFactory(
-			"script", 
-			new TagFactory() {
+            "script", 
+            new TagFactory() {
                 public Tag createTag(String name, Attributes attributes)
                     throws JellyException {
                     return createScriptTag(name, attributes);
                 }
-			}
-		);	
+            }
+            );	
     }
 
     public void setLanguage(String language) {
@@ -115,7 +115,8 @@
      */
     protected Tag createScriptTag(String name, Attributes attributes) throws JellyException
{
         try {
-            return new ScriptTag( expressionFactory.getBSFEngine() );
+            return new ScriptTag( expressionFactory.getBSFEngine(),
+                                  expressionFactory.getBSFManager());
         }
         catch (BSFException e) {
             throw new JellyException("Failed to create BSFEngine: " + e, e);
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java,v
retrieving revision 1.1
diff -u -r1.1 JellyContextRegistry.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java	8
Jan 2003 05:02:48 -0000	1.1
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java	5
Mar 2003 00:25:09 -0000
@@ -61,7 +61,7 @@
  */
 package org.apache.commons.jelly.tags.bsf;
 
-import com.ibm.bsf.util.ObjectRegistry;
+import org.apache.bsf.util.ObjectRegistry;
 
 import org.apache.commons.jelly.JellyContext;
 import org.apache.commons.logging.Log;
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java,v
retrieving revision 1.1
diff -u -r1.1 PNutsTagLibrary.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java	8 Jan 2003
05:02:47 -0000	1.1
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java	5 Mar 2003
00:25:09 -0000
@@ -61,7 +61,7 @@
  */
 package org.apache.commons.jelly.tags.bsf;
 
-import com.ibm.bsf.BSFManager;
+import org.apache.bsf.BSFManager;
 
 /** Describes the Taglib. This class could be generated by XDoclet
   *
Index: jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java,v
retrieving revision 1.1
diff -u -r1.1 ScriptTag.java
--- jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java	20 Feb 2003 18:56:16
-0000	1.1
+++ jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java	5 Mar 2003 00:25:09
-0000
@@ -61,6 +61,8 @@
  */
 package org.apache.commons.jelly.tags.bsf;
 
+import java.util.Iterator;
+
 import org.apache.commons.jelly.JellyTagException;
 import org.apache.commons.jelly.LocationAware;
 import org.apache.commons.jelly.MissingAttributeException;
@@ -69,8 +71,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import com.ibm.bsf.BSFEngine;
-import com.ibm.bsf.BSFException;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFManager;
+import org.apache.bsf.BSFException;
 
 /** 
  * A tag which evaluates its body using the current scripting language
@@ -84,13 +87,15 @@
     private static final Log log = LogFactory.getLog(ScriptTag.class.getName() + ".evaluating");
 	
     private BSFEngine engine;
+    private BSFManager manager;
     private String elementName;
     private String fileName;
     private int columnNumber;
     private int lineNumber;
     
-    public ScriptTag(BSFEngine engine) {
+    public ScriptTag(BSFEngine engine, BSFManager manager) {
         this.engine = engine;
+        this.manager = manager;
     }
 
     // Tag interface
@@ -98,15 +103,28 @@
     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
         String text = getBodyText();
 
-		log.debug(text);        
-        
-        try {
-            engine.eval(fileName, lineNumber, columnNumber, text);
-        }
-        catch (BSFException e) {
-            throw new JellyTagException("Error occurred with script: " + e, e);
+        log.debug(text);        
+
+        // XXXX: unfortunately we must sychronize evaluations
+        // so that we can swizzle in the context.
+        // maybe we could create an expression from a context
+        // (and so create a BSFManager for a context)
+        synchronized (getRegistry()) {
+            getRegistry().setJellyContext(context);
+
+            try {            
+                // XXXX: hack - there must be a better way!!!
+                for ( Iterator iter = context.getVariableNames(); iter.hasNext(); ) {
+                    String name = (String) iter.next();
+                    Object value = context.getVariable( name );
+                    manager.declareBean( name, value, value.getClass() );
+                }
+                engine.exec(fileName, lineNumber, columnNumber, text);
+            }
+            catch (BSFException e) {
+                throw new JellyTagException("Error occurred with script: " + e, e);
+            }
         }
-        
     }
     
     // Properties
@@ -186,4 +204,8 @@
         this.lineNumber = lineNumber;
     }
 
+    private JellyContextRegistry getRegistry()
+    {
+        return (JellyContextRegistry) this.manager.getObjectRegistry();
+    }    
 }
Index: src/java/org/apache/commons/jelly/jelly.properties
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
retrieving revision 1.36
diff -u -r1.36 jelly.properties
--- src/java/org/apache/commons/jelly/jelly.properties	26 Feb 2003 09:41:37 -0000	1.36
+++ src/java/org/apache/commons/jelly/jelly.properties	5 Mar 2003 00:25:14 -0000
@@ -20,6 +20,7 @@
 jetty       = org.apache.commons.jelly.tags.jetty.JettyTagLibrary
 jms         = org.apache.commons.jelly.tags.jms.JMSTagLibrary
 jpython     = org.apache.commons.jelly.tags.bsf.JPythonTagLibrary
+jython      = org.apache.commons.jelly.tags.bsf.JythonTagLibrary
 jsl         = org.apache.commons.jelly.tags.jsl.JSLTagLibrary
 junit 	    = org.apache.commons.jelly.tags.junit.JUnitTagLibrary
 log         = org.apache.commons.jelly.tags.log.LogTagLibrary


/*
 * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JPythonTagLibrary.java,v
1.1 2003/01/08 05:02:48 dion Exp $
 * $Revision: 1.1 $
 * $Date: 2003/01/08 05:02:48 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 * 
 * $Id: JPythonTagLibrary.java,v 1.1 2003/01/08 05:02:48 dion Exp $
 */
package org.apache.commons.jelly.tags.bsf;

/** Describes the Taglib. This class could be generated by XDoclet
  *
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @version $Revision: 1.1 $
  */
public class JythonTagLibrary extends BSFTagLibrary {

    public JythonTagLibrary() {
        setLanguage( "jython" );
    }
}


Mime
View raw message