You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/05/15 09:47:51 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf ContextRegistry.java

jstrachan    02/05/15 00:47:50

  Modified:    jelly/src/test/org/apache/commons/jelly TestXMLTags.java
               jelly/src/java/org/apache/commons/jelly/tags/sql
                        DataSourceWrapper.java SetDataSourceTag.java
                        QueryTag.java DataSourceUtil.java
               jelly/src/java/org/apache/commons/jelly JellyContext.java
               jelly/src/java/org/apache/commons/jelly/tags/bsf
                        ContextRegistry.java
  Removed:     jelly/src/java/org/apache/commons/jelly Context.java
  Log:
  removed unnecessary debug messages and old Context class
  
  Revision  Changes    Path
  1.6       +1 -130    jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java
  
  Index: TestXMLTags.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestXMLTags.java	15 May 2002 06:25:49 -0000	1.5
  +++ TestXMLTags.java	15 May 2002 07:47:50 -0000	1.6
  @@ -1,130 +1 @@
  -/*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v 1.5 2002/05/15 06:25:49 jstrachan Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/05/15 06:25:49 $
  - *
  - * ====================================================================
  - *
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999-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: TestXMLTags.java,v 1.5 2002/05/15 06:25:49 jstrachan Exp $
  - */
  -package org.apache.commons.jelly;
  -
  -import java.io.InputStream;
  -import java.io.IOException;
  -import java.io.StringWriter;
  -
  -import junit.framework.Test;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
  -import junit.textui.TestRunner;
  -
  -import org.apache.commons.jelly.JellyContext;
  -import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.XMLOutput;
  -import org.apache.commons.jelly.impl.TagScript;
  -import org.apache.commons.jelly.parser.XMLParser;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
  -
  -/** Tests the parser, the engine and the XML tags
  -  *
  -  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.5 $
  -  */
  -public class TestXMLTags extends TestCase {
  -    
  -    /** The Log to which logging calls will be made. */
  -    private static final Log log = LogFactory.getLog( TestXMLTags.class );
  -
  -    public static void main( String[] args ) {
  -        TestRunner.run( suite() );
  -    }
  -    
  -    public static Test suite() {
  -        return new TestSuite(TestXMLTags.class);
  -    }
  -    
  -    public TestXMLTags(String testName) {
  -        super(testName);
  -    }
  -    
  -    public void testParse() throws Exception {
  -        InputStream in = getClass().getResourceAsStream( "example.jelly" );
  -        XMLParser parser = new XMLParser();
  -        Script script = parser.parse( in );
  -        script = script.compile();
  -
  -        log.debug( "Found: " + script );
  -        
  -        assertTrue( "Script is a TagScript", script instanceof TagScript );
  -        
  -        JellyContext context = new JellyContext();        
  -        StringWriter buffer = new StringWriter();
  -        
  -        script.run( context, XMLOutput.createXMLOutput( buffer ) );
  -        
  -        String text = buffer.toString().trim();
  -        
  -        if ( log.isDebugEnabled() ) {
  -            log.debug( "Evaluated script as..." );
  -            log.debug( text );
  -        }
  -        
  -        assertEquals( "Produces the correct output", "It works!", text );        
  -    }    
  -}
  -
  +/*
 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v 1.6 2002/05/15 07:47:50 jstrachan Exp $
 * $Revision: 1.6 $
 * $Date: 2002/05/15 07:47:50 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-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: TestXMLTags.java,v 1.6 2002/05/15 07:47:50 jstrachan Exp $
 */
package org.apache.commons.jelly;
import java.io.InputStream;
import java.io.IOException;
import java.io.StringWriter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.impl.TagScript;
import org.apache.commons.jelly.parser.XMLParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** Tests the parser, the engine and the XML tags
  *
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @version $Revision: 1.6 $
  */
public class TestXMLTags extends TestCase {

    /** The Log to which logging calls will be made. */
    private static final Log log = LogFactory.getLog(TestXMLTags.class);

    public static void main(String[] args) {
        TestRunner.run(suite());
    }

    public static Test suite() {
        return new TestSuite(TestXMLTags.class);
    }

    public TestXMLTags(String testName) {
        super(testName);
    }

    public void testParse() throws Exception {
        InputStream in = getClass().getResourceAsStream("example.jelly");
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        log.debug("Found: " + script);
        assertTrue("Script is a TagScript", script instanceof TagScript);
        JellyContext context = new JellyContext();
        StringWriter buffer = new StringWriter();
        script.run(context, XMLOutput.createXMLOutput(buffer));
        String text = buffer.toString().trim();
        if (log.isDebugEnabled()) {
            log.debug("Evaluated script as...");
            log.debug(text);
        }
        assertEquals("Produces the correct output", "It works!", text);
    }
}
  \ No newline at end of file
  
  
  
  1.2       +90 -81    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/DataSourceWrapper.java
  
  Index: DataSourceWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/DataSourceWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataSourceWrapper.java	15 May 2002 06:25:47 -0000	1.1
  +++ DataSourceWrapper.java	15 May 2002 07:47:50 -0000	1.2
  @@ -73,87 +73,96 @@
    */
   public class DataSourceWrapper implements DataSource {
   
  -	/** The Log to which logging calls will be made. */
  -	private static final Log log = LogFactory.getLog(DataSourceWrapper.class);
  +    /** The Log to which logging calls will be made. */
  +    private static final Log log = LogFactory.getLog(DataSourceWrapper.class);
   
  -	private String driverClassName;
  -	private String jdbcURL;
  -	private String userName;
  -	private String password;
  -
  -	public void setDriverClassName(String driverClassName)
  -		throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  -		log.info("Loading JDBC driver: [" + driverClassName + "]");
  -
  -		this.driverClassName = driverClassName;
  -		getClass().getClassLoader().loadClass(driverClassName).newInstance();
  -	}
  -
  -	public void setJdbcURL(String jdbcURL) {
  -		log.info("Setting url to: " + jdbcURL);
  -		this.jdbcURL = jdbcURL;
  -	}
  -
  -	public void setUserName(String userName) {
  -		this.userName = userName;
  -	}
  -
  -	public void setPassword(String password) {
  -		this.password = password;
  -	}
  -
  -	/**
  -	 * Returns a Connection using the DriverManager and all
  -	 * set properties.
  -	 */
  -	public Connection getConnection() throws SQLException {
  -		Connection conn = null;
  -		if (userName != null) {
  -			log.info("Creating connection from url: " + jdbcURL + " userName: " + userName);
  -			conn = DriverManager.getConnection(jdbcURL, userName, password);
  -		}
  -		else {
  -			log.info("Creating connection from url: " + jdbcURL);
  -			conn = DriverManager.getConnection(jdbcURL);
  -		}
  -		return conn;
  -	}
  -
  -	/**
  -	 * Always throws a SQLException. Username and password are set
  -	 * in the constructor and can not be changed.
  -	 */
  -	public Connection getConnection(String username, String password)
  -		throws SQLException {
  -		throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  -	}
  -
  -	/**
  -	 * Always throws a SQLException. Not supported.
  -	 */
  -	public int getLoginTimeout() throws SQLException {
  -		throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  -	}
  -
  -	/**
  -	 * Always throws a SQLException. Not supported.
  -	 */
  -	public PrintWriter getLogWriter() throws SQLException {
  -		throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  -	}
  -
  -	/**
  -	 * Always throws a SQLException. Not supported.
  -	 */
  -	public void setLoginTimeout(int seconds) throws SQLException {
  -		throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  -	}
  -
  -	/**
  -	 * Always throws a SQLException. Not supported.
  -	 */
  -	public synchronized void setLogWriter(PrintWriter out) throws SQLException {
  -		throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  -	}
  +    private String driverClassName;
  +    private String jdbcURL;
  +    private String userName;
  +    private String password;
  +
  +    public void setDriverClassName(String driverClassName)
  +        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  +
  +        if (log.isDebugEnabled()) {
  +            log.debug("Loading JDBC driver: [" + driverClassName + "]");
  +        }
  +
  +        this.driverClassName = driverClassName;
  +        getClass().getClassLoader().loadClass(driverClassName).newInstance();
  +    }
  +
  +    public void setJdbcURL(String jdbcURL) {
  +        this.jdbcURL = jdbcURL;
  +    }
  +
  +    public void setUserName(String userName) {
  +        this.userName = userName;
  +    }
  +
  +    public void setPassword(String password) {
  +        this.password = password;
  +    }
  +
  +    /**
  +     * Returns a Connection using the DriverManager and all
  +     * set properties.
  +     */
  +    public Connection getConnection() throws SQLException {
  +        Connection conn = null;
  +        if (userName != null) {
  +            if (log.isDebugEnabled()) {
  +                log.debug(
  +                    "Creating connection from url: " + jdbcURL + " userName: " + userName);
  +            }
  +
  +            conn = DriverManager.getConnection(jdbcURL, userName, password);
  +        }
  +        else {
  +            if (log.isDebugEnabled()) {
  +                log.debug("Creating connection from url: " + jdbcURL);
  +            }
  +
  +            conn = DriverManager.getConnection(jdbcURL);
  +        }
  +        return conn;
  +    }
  +
  +    /**
  +     * Always throws a SQLException. Username and password are set
  +     * in the constructor and can not be changed.
  +     */
  +    public Connection getConnection(String username, String password)
  +        throws SQLException {
  +        throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  +    }
  +
  +    /**
  +     * Always throws a SQLException. Not supported.
  +     */
  +    public int getLoginTimeout() throws SQLException {
  +        throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  +    }
  +
  +    /**
  +     * Always throws a SQLException. Not supported.
  +     */
  +    public PrintWriter getLogWriter() throws SQLException {
  +        throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  +    }
  +
  +    /**
  +     * Always throws a SQLException. Not supported.
  +     */
  +    public void setLoginTimeout(int seconds) throws SQLException {
  +        throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  +    }
  +
  +    /**
  +     * Always throws a SQLException. Not supported.
  +     */
  +    public synchronized void setLogWriter(PrintWriter out) throws SQLException {
  +        throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
  +    }
   
   }
  
  
  
  1.2       +0 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/SetDataSourceTag.java
  
  Index: SetDataSourceTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/SetDataSourceTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetDataSourceTag.java	15 May 2002 06:25:47 -0000	1.1
  +++ SetDataSourceTag.java	15 May 2002 07:47:50 -0000	1.2
  @@ -120,7 +120,6 @@
   	}
   
   	public void setUrl(String jdbcURL) {
  -		log.info( "Setting url to: "+ jdbcURL );
   		this.jdbcURL = jdbcURL;
   	}
   
  
  
  
  1.2       +0 -7      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/QueryTag.java
  
  Index: QueryTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/QueryTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QueryTag.java	15 May 2002 06:25:47 -0000	1.1
  +++ QueryTag.java	15 May 2002 07:47:50 -0000	1.2
  @@ -131,13 +131,6 @@
   	}
   
   	public void setDataSource(Object dataSource) {
  -		if ( dataSource != null ) {
  -			log.info( "Setting data source to: " + dataSource + " of type: " + dataSource.getClass() );
  -		}
  -		else {
  -			log.info( "Setting data source to: " + dataSource );
  -		}
  -		
   		this.rawDataSource = dataSource;
   		this.dataSourceSpecified = true;
   	}
  
  
  
  1.2       +0 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/DataSourceUtil.java
  
  Index: DataSourceUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/sql/DataSourceUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataSourceUtil.java	15 May 2002 06:25:47 -0000	1.1
  +++ DataSourceUtil.java	15 May 2002 07:47:50 -0000	1.2
  @@ -93,10 +93,6 @@
   		throws JellyException {
   		DataSource dataSource = null;
   
  -		if (log.isInfoEnabled() ) {
  -			log.info( "Attempting to deduce DataSource from: " + rawDataSource );
  -		}
  -		
   		if (rawDataSource == null) {
   			rawDataSource = pc.getVariable("org.apache.commons.jelly.sql.DataSource");
   		}
  @@ -111,7 +107,6 @@
   		* a DataSource
   		*/
   		if (rawDataSource instanceof String) {
  -			log.info( "rawDataSource is a String" );
   			try {
   				Context ctx = new InitialContext();
   				// relative to standard JNDI root for J2EE app
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JellyContext.java	15 May 2002 06:25:47 -0000	1.1
  +++ JellyContext.java	15 May 2002 07:47:50 -0000	1.2
  @@ -1 +1 @@
  -/*
 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v 1.10 2002/04/26 12:20:12 jstrachan Exp $
 * $Revision: 1.10 $
 * $Date: 2002/04/26 12:20:12 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-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: JellyContext.java,v 1.10 2002/04/26 12:20:12 jstrachan Exp $
 */

package org.apache.commons.jelly;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.jelly.parser.XMLParser;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** <p><code>JellyContext</code> represents the Jelly context.</p>
  *
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @version $Revision: 1.10 $
  */

public class JellyContext {

	/** The root URL context (where scripts are located from) */
	private URL rootContext;

	/** The current URL context (where relative scripts are located from) */
	private URL currentJellyContext;

	/** Tag libraries found so far */
	private Map taglibs = new Hashtable();

	/** synchronized access to the variables in scope */
	private Map variables = new Hashtable();

	/** The Log to which logging calls will be made. */
	private Log log = LogFactory.getLog(JellyContext.class);

	public JellyContext() {
		this.currentJellyContext = rootContext;
	}
	
	public JellyContext(URL rootContext) {
		this.rootContext = rootContext;
		this.currentJellyContext = rootContext;
	}
	
	public JellyContext(URL rootContext, URL currentJellyContext) {
		this.rootContext = rootContext;
		this.currentJellyContext = currentJellyContext;
	}
	
	public JellyContext(JellyContext parentJellyContext) {
		this.rootContext = parentJellyContext.rootContext;
		this.currentJellyContext = parentJellyContext.currentJellyContext;
		this.taglibs = parentJellyContext.taglibs;
		this.variables.put("parentScope", parentJellyContext.variables);
	}
	
	public JellyContext(JellyContext parentJellyContext, URL currentJellyContext) {
		this(parentJellyContext);
		this.currentJellyContext = currentJellyContext;
	}
	
	/** @return the value of the given variable name */
	public Object getVariable(String name) {
		return variables.get(name);
	}
	
	/** Sets the value of the given variable name */
	public void setVariable(String name, Object value) {
		if (value == null) {
			variables.remove(name);
		}
		else {
			variables.put(name, value);
		}
	}
	
	/** Removes the given variable */
	public void removeVariable(String name) {
		variables.remove(name);
	}
	
	/** 
	 * @return an Iterator over the current variable names in this
	 * context 
	 */
	public Iterator getVariableNames() {
		return variables.keySet().iterator();
	}
	
	/**
	 * @return the Map of variables in this scope
	 */
	public Map getVariables() {
		return variables;
	}
	
	/**
	 * Sets the Map of variables to use
	 */
	
	public void setVariables(Map variables) {
		this.variables = variables;
	}
	
	/**
	 * A factory method to create a new child context of the
	 * current context.
	 */
	public JellyContext newJellyContext(Map newVariables) {
		// XXXX: should allow this new context to
		// XXXX: inherit parent contexts? 
		// XXXX: Or at least publish the parent scope
		// XXXX: as a Map in this new variable scope?
		newVariables.put("parentScope", variables);
		JellyContext answer = createChildContext();
		answer.setVariables(newVariables);
		return answer;
	}
	
	/** Registers the given tag library against the given namespace URI.
	 * This should be called before the parser is used.
	 */
	public void registerTagLibrary(String namespaceURI, TagLibrary taglib) {
		log.info("Registering tag library to: " + namespaceURI + " taglib: " + taglib);
		taglibs.put(namespaceURI, taglib);
	}
	
	/** Registers the given tag library class name against the given namespace URI.
	 * The class will be loaded via the given ClassLoader
	 * This should be called before the parser is used.
	 */
	public void registerTagLibrary(
		String namespaceURI,
		String className,
		ClassLoader classLoader) {
		try {
			Class theClass = classLoader.loadClass(className);
			Object object = theClass.newInstance();
			if (object instanceof TagLibrary) {
				registerTagLibrary(namespaceURI, (TagLibrary) object);
			}
			else {
				log.error(
					"The tag library object mapped to: "
						+ namespaceURI
						+ " is not a TagLibrary. Object = "
						+ object);
			}
		}
		catch (ClassNotFoundException e) {
			log.error("Could not find the class: " + className, e);
		}
		catch (Exception e) {
			log.error(
				"Could not instantiate instance of class: " + className + ". Reason: " + e,
				e);
		}
	}
	
	/** 
	 * @return the TagLibrary for the given namespace URI or null if one could not be found
	 */
	public TagLibrary getTagLibrary(String namespaceURI) {
		return (TagLibrary) taglibs.get(namespaceURI);
	}

	/** 
	 * Attempts to parse the script from the given uri using the 
	 * {#link getResource()} method then returns the compiled script.
	 */
	public Script compileScript(String uri) throws Exception {
		XMLParser parser = new XMLParser();
		parser.setJellyContext(this);
		InputStream in = getResourceAsStream(uri);
		if (in == null) {
			throw new JellyException("Could not find Jelly script: " + uri);
		}
		Script script = parser.parse(in);
		return script.compile();
	}

	/** 
	 * Attempts to parse the script from the given URL using the 
	 * {#link getResource()} method then returns the compiled script.
	 */
	public Script compileScript(URL url) throws Exception {
		XMLParser parser = new XMLParser();
		parser.setJellyContext(this);
		Script script = parser.parse(url.toString());
		return script.compile();
	}

	/** 
	 * Attempts to parse the script from the given uri using the 
	 * JellyContext.getResource() API then compiles it and runs it.
	 */
	public void runScript(String uri, XMLOutput output) throws Exception {
		URL url = getResource(uri);
		if (url == null) {
			throw new JellyException("Could not find Jelly script: " + url);
		}
		Script script = compileScript(url);
		URL newJellyContextURL = getJellyContextURL(url);
		JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
		script.run(newJellyContext, output);
	}

	/**
	 * Returns a URL for the given resource from the specified path.
	 * If the uri starts with "/" then the path is taken as relative to 
	 * the current context root. If the uri is a well formed URL then it
	 * is used. Otherwise the uri is interpreted as relative to the current
	 * context (the location of the current script).
	 */
	public URL getResource(String uri) throws MalformedURLException {
		if (uri.startsWith("/")) {
			// append this uri to the context root
			return createRelativeURL(rootContext, uri.substring(1));
		}
		else {
			try {
				return new URL(uri);
			}
			catch (MalformedURLException e) {
				// lets try find a relative resource
				try {
					return createRelativeURL(currentJellyContext, uri);
				}
				catch (MalformedURLException e2) {
					throw e;
				}
			}
		}
	}

	/**
	 * Attempts to open an InputStream to the given resource at the specified path.
	 * If the uri starts with "/" then the path is taken as relative to 
	 * the current context root. If the uri is a well formed URL then it
	 * is used. Otherwise the uri is interpreted as relative to the current
	 * context (the location of the current script).
	 *
	 * @return null if this resource could not be loaded, otherwise the resources 
	 *  input stream is returned.
	 */
	public InputStream getResourceAsStream(String uri) {
		try {
			URL url = getResource(uri);
			return url.openStream();
		}
		catch (Exception e) {
			if (log.isTraceEnabled()) {
				log.trace(
					"Caught exception attempting to open: " + uri + ". Exception: " + e,
					e);
			}
			return null;
		}
	}

	// Implementation methods
	//-------------------------------------------------------------------------                

	/**
	 * @return a new relative URL from the given root and with the addition of the
	 * extra relative URI
	 *
	 * @param rootURL is the root context from which the relative URI will be applied
	 * @param relativeURI is the relative URI (without a leading "/")
	 * @throws MalformedURLException if the URL is invalid.
	 */
	protected URL createRelativeURL(URL rootURL, String relativeURI)
		throws MalformedURLException {
		String urlText = null;
		if (rootURL == null) {
			String userDir = System.getProperty("user.dir");
			urlText = "file://" + userDir + relativeURI;
		}
		else {
			urlText = rootURL.toString() + relativeURI;
		}
		log.info("Attempting to open url: " + urlText);
		return new URL(urlText);
	}

	/** 
	 * Strips off the name of a script to create a new context URL
	 */
	protected URL getJellyContextURL(URL url) throws MalformedURLException {
		String text = url.toString();
		int idx = text.lastIndexOf('/');
		text = text.substring(0, idx + 1);
		return new URL(text);
	}
	
	/**
	 * Factory method to create a new child of this context
	 */
	protected JellyContext createChildContext() {
		return new JellyContext(this);
	}
}
  \ No newline at end of file
  +/*
 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v 1.10 2002/04/26 12:20:12 jstrachan Exp $
 * $Revision: 1.10 $
 * $Date: 2002/04/26 12:20:12 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-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: JellyContext.java,v 1.10 2002/04/26 12:20:12 jstrachan Exp $
 */
package org.apache.commons.jelly;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.jelly.parser.XMLParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** <p><code>JellyContext</code> represents the Jelly context.</p>
  *
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @version $Revision: 1.10 $
  */
public class JellyContext {

    /** The root URL context (where scripts are located from) */
    private URL rootContext;

    /** The current URL context (where relative scripts are located from) */
    private URL currentJellyContext;

    /** Tag libraries found so far */
    private Map taglibs = new Hashtable();

    /** synchronized access to the variables in scope */
    private Map variables = new Hashtable();

    /** The Log to which logging calls will be made. */
    private Log log = LogFactory.getLog(JellyContext.class);


    public JellyContext() {
        this.currentJellyContext = rootContext;
    }

    public JellyContext(URL rootContext) {
        this.rootContext = rootContext;
        this.currentJellyContext = rootContext;
    }

    public JellyContext(URL rootContext, URL currentJellyContext) {
        this.rootContext = rootContext;
        this.currentJellyContext = currentJellyContext;
    }

    public JellyContext(JellyContext parentJellyContext) {
        this.rootContext = parentJellyContext.rootContext;
        this.currentJellyContext = parentJellyContext.currentJellyContext;
        this.taglibs = parentJellyContext.taglibs;
        this.variables.put("parentScope", parentJellyContext.variables);
    }

    public JellyContext(JellyContext parentJellyContext, URL currentJellyContext) {
        this(parentJellyContext);
        this.currentJellyContext = currentJellyContext;
    }

    /** @return the value of the given variable name */
    public Object getVariable(String name) {
        return variables.get(name);
    }

    /** Sets the value of the given variable name */
    public void setVariable(String name, Object value) {
        if (value == null) {
            variables.remove(name);
        }
        else {
            variables.put(name, value);
        }
    }

    /** Removes the given variable */
    public void removeVariable(String name) {
        variables.remove(name);
    }

    /** 
     * @return an Iterator over the current variable names in this
     * context 
     */
    public Iterator getVariableNames() {
        return variables.keySet().iterator();
    }

    /**
     * @return the Map of variables in this scope
     */
    public Map getVariables() {
        return variables;
    }

    /**
     * Sets the Map of variables to use
     */

    public void setVariables(Map variables) {
        this.variables = variables;
    }

    /**
     * A factory method to create a new child context of the
     * current context.
     */
    public JellyContext newJellyContext(Map newVariables) {
        // XXXX: should allow this new context to
        // XXXX: inherit parent contexts? 
        // XXXX: Or at least publish the parent scope
        // XXXX: as a Map in this new variable scope?
        newVariables.put("parentScope", variables);
        JellyContext answer = createChildContext();
        answer.setVariables(newVariables);
        return answer;
    }

    /** Registers the given tag library against the given namespace URI.
     * This should be called before the parser is used.
     */
    public void registerTagLibrary(String namespaceURI, TagLibrary taglib) {
        if (log.isDebugEnabled()) {
            log.debug("Registering tag library to: " + namespaceURI + " taglib: " + taglib);
        }
        taglibs.put(namespaceURI, taglib);
    }

    /** Registers the given tag library class name against the given namespace URI.
     * The class will be loaded via the given ClassLoader
     * This should be called before the parser is used.
     */
    public void registerTagLibrary(
        String namespaceURI,
        String className,
        ClassLoader classLoader) {
        try {
            Class theClass = classLoader.loadClass(className);
            Object object = theClass.newInstance();
            if (object instanceof TagLibrary) {
                registerTagLibrary(namespaceURI, (TagLibrary) object);
            }
            else {
                log.error(
                    "The tag library object mapped to: "
                        + namespaceURI
                        + " is not a TagLibrary. Object = "
                        + object);
            }
        }
        catch (ClassNotFoundException e) {
            log.error("Could not find the class: " + className, e);
        }
        catch (Exception e) {
            log.error(
                "Could not instantiate instance of class: " + className + ". Reason: " + e,
                e);
        }
    }

    /** 
     * @return the TagLibrary for the given namespace URI or null if one could not be found
     */
    public TagLibrary getTagLibrary(String namespaceURI) {
        return (TagLibrary) taglibs.get(namespaceURI);
    }

    /** 
     * Attempts to parse the script from the given uri using the 
     * {#link getResource()} method then returns the compiled script.
     */
    public Script compileScript(String uri) throws Exception {
        XMLParser parser = new XMLParser();
        parser.setJellyContext(this);
        InputStream in = getResourceAsStream(uri);
        if (in == null) {
            throw new JellyException("Could not find Jelly script: " + uri);
        }
        Script script = parser.parse(in);
        return script.compile();
    }

    /** 
     * Attempts to parse the script from the given URL using the 
     * {#link getResource()} method then returns the compiled script.
     */
    public Script compileScript(URL url) throws Exception {
        XMLParser parser = new XMLParser();
        parser.setJellyContext(this);
        Script script = parser.parse(url.toString());
        return script.compile();
    }

    /** 
     * Attempts to parse the script from the given uri using the 
     * JellyContext.getResource() API then compiles it and runs it.
     */
    public void runScript(String uri, XMLOutput output) throws Exception {
        URL url = getResource(uri);
        if (url == null) {
            throw new JellyException("Could not find Jelly script: " + url);
        }
        Script script = compileScript(url);
        URL newJellyContextURL = getJellyContextURL(url);
        JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
        script.run(newJellyContext, output);
    }

    /**
     * Returns a URL for the given resource from the specified path.
     * If the uri starts with "/" then the path is taken as relative to 
     * the current context root. If the uri is a well formed URL then it
     * is used. Otherwise the uri is interpreted as relative to the current
     * context (the location of the current script).
     */
    public URL getResource(String uri) throws MalformedURLException {
        if (uri.startsWith("/")) {
            // append this uri to the context root
            return createRelativeURL(rootContext, uri.substring(1));
        }
        else {
            try {
                return new URL(uri);
            }
            catch (MalformedURLException e) {
                // lets try find a relative resource
                try {
                    return createRelativeURL(currentJellyContext, uri);
                }
                catch (MalformedURLException e2) {
                    throw e;
                }
            }
        }
    }

    /**
     * Attempts to open an InputStream to the given resource at the specified path.
     * If the uri starts with "/" then the path is taken as relative to 
     * the current context root. If the uri is a well formed URL then it
     * is used. Otherwise the uri is interpreted as relative to the current
     * context (the location of the current script).
     *
     * @return null if this resource could not be loaded, otherwise the resources 
     *  input stream is returned.
     */
    public InputStream getResourceAsStream(String uri) {
        try {
            URL url = getResource(uri);
            return url.openStream();
        }
        catch (Exception e) {
            if (log.isTraceEnabled()) {
                log.trace(
                    "Caught exception attempting to open: " + uri + ". Exception: " + e,
                    e);
            }
            return null;
        }
    }

    // Implementation methods
    //-------------------------------------------------------------------------                
    /**
     * @return a new relative URL from the given root and with the addition of the
     * extra relative URI
     *
     * @param rootURL is the root context from which the relative URI will be applied
     * @param relativeURI is the relative URI (without a leading "/")
     * @throws MalformedURLException if the URL is invalid.
     */
    protected URL createRelativeURL(URL rootURL, String relativeURI)
        throws MalformedURLException {
        String urlText = null;
        if (rootURL == null) {
            String userDir = System.getProperty("user.dir");
            urlText = "file://" + userDir + relativeURI;
        }
        else {
            urlText = rootURL.toString() + relativeURI;
        }
        log.info("Attempting to open url: " + urlText);
        return new URL(urlText);
    }

    /** 
     * Strips off the name of a script to create a new context URL
     */
    protected URL getJellyContextURL(URL url) throws MalformedURLException {
        String text = url.toString();
        int idx = text.lastIndexOf('/');
        text = text.substring(0, idx + 1);
        return new URL(text);
    }

    /**
     * Factory method to create a new child of this context
     */
    protected JellyContext createChildContext() {
        return new JellyContext(this);
    }
}
  \ No newline at end of file
  
  
  
  1.2       +1 -110    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java
  
  Index: ContextRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContextRegistry.java	7 Mar 2002 02:46:04 -0000	1.1
  +++ ContextRegistry.java	15 May 2002 07:47:50 -0000	1.2
  @@ -1,110 +1 @@
  -/*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/03/07 02:46:04 $
  - *
  - * ====================================================================
  - *
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999-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: ContextRegistry.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
  - */
  -package org.apache.commons.jelly.tags.bsf;
  -
  -import com.ibm.bsf.util.ObjectRegistry;
  -
  -import org.apache.commons.jelly.Context;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
  -
  -/** A BSF ObjectRegistry which uses the Context to find and
  -  * register objects
  -  *
  -  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  -  */
  -public class ContextRegistry extends ObjectRegistry {
  -
  -    /** The Log to which logging calls will be made. */
  -    private static final Log log = LogFactory.getLog( ContextRegistry.class );
  -
  -    /** The context */
  -    private Context context;
  -    
  -    public ContextRegistry() {
  -    }
  -
  -    public Context getContext() {
  -        return context;
  -    }
  -    
  -    public void setContext(Context context) {
  -        this.context = context;
  -    }
  -    
  -    // ObjectRegistry interface
  -    //------------------------------------------------------------------------- 
  -    public Object lookup(String name) {
  -        return context.getVariable( name );
  -    }
  -    
  -    public void register(String name, Object value) {
  -        context.setVariable( name, value );
  -    }
  -    
  -    public void unregister(String name) {
  -        context.removeVariable( name );
  -    }        
  -}
  +/*
 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java,v 1.2 2002/05/15 07:47:50 jstrachan Exp $
 * $Revision: 1.2 $
 * $Date: 2002/05/15 07:47:50 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-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: ContextRegistry.java,v 1.2 2002/05/15 07:47:50 jstrachan Exp $
 */
package org.apache.commons.jelly.tags.bsf;

import com.ibm.bsf.util.ObjectRegistry;

import org.apache.commons.jelly.JellyContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** A BSF ObjectRegistry which uses the Context to find and
  * register objects
  *
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @version $Revision: 1.2 $
  */
public class ContextRegistry extends ObjectRegistry {

    /** The Log to which logging calls will be made. */
    private static final Log log = LogFactory.getLog(ContextRegistry.class);

    /** The context */
    private JellyContext context;

    public ContextRegistry() {
    }

    public JellyContext getContext() {
        return context;
    }

    public void setContext(JellyContext context) {
        this.context = context;
    }

    // ObjectRegistry interface
    //------------------------------------------------------------------------- 
    public Object lookup(String name) {
        return context.getVariable(name);
    }

    public void register(String name, Object value) {
        context.setVariable(name, value);
    }

    public void unregister(String name) {
        context.removeVariable(name);
    }
}
  \ No newline at end of file
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>