You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/11/28 01:22:24 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core BaseJellyTest.java TestNewTag.java testNewTag.jelly TestSwitchTag.java
rwaldhoff 2002/11/27 16:22:24
Modified: jelly project.xml
jelly/src/java/org/apache/commons/jelly/tags/core
CoreTagLibrary.java NewTag.java UseBeanTag.java
jelly/src/test/org/apache/commons/jelly/bean Customer.java
jelly/src/test/org/apache/commons/jelly/core
TestSwitchTag.java
Added: jelly/src/java/org/apache/commons/jelly/tags/core
ArgTag.java ArgTagParent.java
BaseClassLoaderTag.java
jelly/src/test/org/apache/commons/jelly/core
BaseJellyTest.java TestNewTag.java testNewTag.jelly
Log:
* allow <new> to invoke constructors with arguments, as specified by <arg> tags
* allow <new> and <useBean> as <arg>s, in addition to basic <arg>
* extract BaseJellyTest and BaseClassLoaderTag classes
* add tests for <new> and <arg>
* NB: this makes jelly depend upon "nightly" versions of commons-beanutils dated 2002-11-27 or later, the maven repository needs to be updated to support this (about to send a note to commons-dev regarding that)
Revision Changes Path
1.94 +12 -1 jakarta-commons-sandbox/jelly/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.xml,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- project.xml 27 Nov 2002 16:46:10 -0000 1.93
+++ project.xml 28 Nov 2002 00:22:23 -0000 1.94
@@ -222,7 +222,18 @@
<dependency>
<id>commons-beanutils</id>
- <version>1.4-dev</version>
+ <!--
+ Jelly now depends on a version of beanutils that includes ConstructorUtils
+ (e.g., nightly builds from
+ http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-beanutils/
+ dated 2002-11-27 or later)
+
+ I've been doing this "manually" as:
+ <version>nightly</version>
+ and "manually" adding this file to my local repository,
+ but someone should update the maven repo SNAPSHOT
+ -->
+ <version>SNAPSHOT</version>
</dependency>
<dependency>
1.23 +6 -5 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
Index: CoreTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- CoreTagLibrary.java 30 Oct 2002 19:16:20 -0000 1.22
+++ CoreTagLibrary.java 28 Nov 2002 00:22:23 -0000 1.23
@@ -107,6 +107,7 @@
registerTag("break", BreakTag.class);
registerTag("expr", ExprTag.class);
registerTag("new", NewTag.class);
+ registerTag("arg", ArgTag.class);
registerTag("setProperties", SetPropertiesTag.class);
registerTag("useBean", UseBeanTag.class);
registerTag("useList", UseListTag.class);
1.3 +33 -74 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/NewTag.java
Index: NewTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/NewTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NewTag.java 30 Oct 2002 19:16:21 -0000 1.2
+++ NewTag.java 28 Nov 2002 00:22:23 -0000 1.3
@@ -61,9 +61,11 @@
*/
package org.apache.commons.jelly.tags.core;
-import org.apache.commons.jelly.JellyContext;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.jelly.MissingAttributeException;
-import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
/** A tag which creates a new object of the given type
@@ -71,7 +73,7 @@
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
-public class NewTag extends TagSupport {
+public class NewTag extends BaseClassLoaderTag implements ArgTagParent {
/** the variable exported */
private String var;
@@ -79,21 +81,9 @@
/** the class name of the object to instantiate */
private String className;
- /**
- * The class loader to use for instantiating application objects.
- * If not specified, the context class loader, or the class loader
- * used to load XMLParser itself, is used, based on the value of the
- * <code>useContextClassLoader</code> variable.
- */
- protected ClassLoader classLoader = null;
-
- /**
- * Do we want to use the Context ClassLoader when loading classes
- * for instantiating new objects? Default is <code>false</code>.
- */
- protected boolean useContextClassLoader = false;
-
-
+ private List paramTypes = new ArrayList();
+ private List paramValues = new ArrayList();
+
public NewTag() {
}
@@ -107,72 +97,41 @@
this.className = className;
}
- /**
- * Return the class loader to be used for instantiating application objects
- * when required. This is determined based upon the following rules:
- * <ul>
- * <li>The class loader set by <code>setClassLoader()</code>, if any</li>
- * <li>The thread context class loader, if it exists and the
- * <code>useContextClassLoader</code> property is set to true</li>
- * <li>The class loader used to load the XMLParser class itself.
- * </ul>
- */
- public ClassLoader getClassLoader() {
- if (this.classLoader != null) {
- return (this.classLoader);
- }
- if (this.useContextClassLoader) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (classLoader != null) {
- return (classLoader);
- }
- }
- return (this.getClass().getClassLoader());
- }
-
- /**
- * Set the class loader to be used for instantiating application objects
- * when required.
- *
- * @param classLoader The new class loader to use, or <code>null</code>
- * to revert to the standard rules
- */
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
+ public void addArgument(Class type, Object value) {
+ paramTypes.add(type);
+ paramValues.add(value);
}
-
- /**
- * Return the boolean as to whether the context classloader should be used.
- */
- public boolean getUseContextClassLoader() {
- return useContextClassLoader;
- }
-
- /**
- * Determine whether to use the Context ClassLoader (the one found by
- * calling <code>Thread.currentThread().getContextClassLoader()</code>)
- * to resolve/load classes. If not
- * using Context ClassLoader, then the class-loading defaults to
- * using the calling-class' ClassLoader.
- *
- * @param boolean determines whether to use JellyContext ClassLoader.
- */
- public void setUseContextClassLoader(boolean use) {
- useContextClassLoader = use;
- }
-
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
+ ArgTag parentArg = null;
if ( var == null ) {
- throw new MissingAttributeException( "var" );
+ parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class));
+ if(null == parentArg) {
+ throw new MissingAttributeException( "var" );
+ }
}
if ( className == null ) {
throw new MissingAttributeException( "className" );
}
+ invokeBody(output);
+
Class theClass = getClassLoader().loadClass( className );
- Object object = theClass.newInstance();
- context.setVariable(var, object);
+ Object object = null;
+ if(paramTypes.size() == 0) {
+ object = theClass.newInstance();
+ } else {
+ Object[] values = paramValues.toArray();
+ Class[] types = (Class[])(paramTypes.toArray(new Class[paramTypes.size()]));
+ object = ConstructorUtils.invokeConstructor(theClass,values,types);
+ paramTypes.clear();
+ paramValues.clear();
+ }
+ if(null != var) {
+ context.setVariable(var, object);
+ } else {
+ parentArg.setValueObject(object);
+ }
}
}
1.6 +5 -0 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java
Index: UseBeanTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UseBeanTag.java 30 Oct 2002 19:16:21 -0000 1.5
+++ UseBeanTag.java 28 Nov 2002 00:22:23 -0000 1.6
@@ -199,6 +199,11 @@
protected void processBean(String var, Object bean) throws Exception {
if (var != null) {
context.setVariable(var, bean);
+ } else {
+ ArgTag parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class));
+ if(null != parentArg) {
+ parentArg.setValueObject(bean);
+ }
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ArgTag.java
Index: ArgTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ArgTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/11/28 00:22:23 $
*
* ====================================================================
*
* 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: ArgTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
*/
package org.apache.commons.jelly.tags.core;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.expression.Expression;
/** An argument to a {@link NewTag} or {@link InvokeTag}.
* This tag MUST be enclosed within an {@link ArgTagParent}
* implementation.
*
* @author Rodney Waldhoff
* @version $Revision: 1.1 $
*/
public class ArgTag extends BaseClassLoaderTag {
/** The name of the parameter type, if any. */
private String typeString;
/** An {@link Expression} describing the parameter value. */
private Expression valueExpression;
/** The parameter value as {@link #setValueObject set} by some child tag (if any). */
private Object valueObject;
public ArgTag() {
}
/** The name of the parameter type, if any. */
public void setType(String type) {
this.typeString = type;
}
/** The parameter value. */
public void setValue(Expression value) {
this.valueExpression= value;
}
/** (used by child tags) */
public void setValueObject(Object object) {
this.valueObject = object;
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
invokeBody(output);
if(null != valueObject && null != valueExpression) {
throw new JellyException("Either the value parameter or a value-setting child element can be provided, but not both.");
}
Class klass = null;
Object value = valueObject;
if(null == value && null != valueExpression) {
value = valueExpression.evaluate(context);
}
if("boolean".equals(typeString)) {
klass = Boolean.TYPE;
assertNotNull(value);
if(!(value instanceof Boolean) && null != valueExpression) {
value = new Boolean(valueExpression.evaluateAsBoolean(context));
}
assertInstanceOf(Boolean.class,value);
} else if("byte".equals(typeString)) {
klass = Byte.TYPE;
assertNotNull(value);
if(!(value instanceof Byte) && null != valueExpression) {
value = new Byte(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Byte.class,value);
} else if("short".equals(typeString)) {
klass = Short.TYPE;
assertNotNull(value);
if(!(value instanceof Short) && null != valueExpression) {
value = new Short(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Short.class,value);
} else if("int".equals(typeString)) {
klass = Integer.TYPE;
assertNotNull(value);
if(!(value instanceof Integer) && null != valueExpression) {
value = new Integer(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Integer.class,value);
} else if("char".equals(typeString)) {
klass = Character.TYPE;
assertNotNull(value);
if(!(value instanceof Character) && null != valueExpression) {
value = new Character(valueExpression.evaluateAsString(context).charAt(0));
}
assertInstanceOf(Character.class,value);
} else if("float".equals(typeString)) {
klass = Float.TYPE;
assertNotNull(value);
if(!(value instanceof Float) && null != valueExpression) {
value = new Float(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Float.class,value);
} else if("long".equals(typeString)) {
klass = Long.TYPE;
assertNotNull(value);
if(!(value instanceof Long) && null != valueExpression) {
value = new Long(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Long.class,value);
} else if("double".equals(typeString)) {
klass = Double.TYPE;
assertNotNull(value);
if(!(value instanceof Double) && null != valueExpression) {
value = new Double(valueExpression.evaluateAsString(context));
}
assertInstanceOf(Double.class,value);
} else if(null != typeString) {
klass = getClassLoader().loadClass(typeString);
assertInstanceOf(klass,value);
} else if(null == value) {
klass = Object.class;
} else {
klass = value.getClass();
}
ArgTagParent parent = (ArgTagParent)findAncestorWithClass(ArgTagParent.class);
if(null == parent) {
throw new JellyException("This tag must be enclosed inside an ArgTagParent implementation (for example, <new> or <invoke>)" );
} else {
parent.addArgument(klass,value);
}
}
private void assertNotNull(Object value) throws JellyException {
if(null == value) {
throw new JellyException("A " + typeString + " instance cannot be null.");
}
}
private void assertInstanceOf(Class klass, Object value) throws JellyException {
if(null != klass && null != value && (!klass.isInstance(value))) {
if(null != valueExpression) {
throw new JellyException("Can't create a " + typeString + " instance from the expression " + valueExpression);
} else {
throw new JellyException("Can't create a " + typeString + " instance from the object " + valueObject);
}
}
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ArgTagParent.java
Index: ArgTagParent.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ArgTagParent.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/11/28 00:22:23 $
*
* ====================================================================
*
* 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: ArgTagParent.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
*/
package org.apache.commons.jelly.tags.core;
/** Interface for classes that support {@link ArgTag} children.
* @author Rodney Waldhoff
* @version $Revision: 1.1 $
*/
public interface ArgTagParent {
public void addArgument(Class type, Object value);
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/BaseClassLoaderTag.java
Index: BaseClassLoaderTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/BaseClassLoaderTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/11/28 00:22:23 $
*
* ====================================================================
*
* 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: BaseClassLoaderTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
*/
package org.apache.commons.jelly.tags.core;
import org.apache.commons.jelly.TagSupport;
/** Abstract base tag providing {@link ClassLoader} support.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author Rodney Waldhoff
* @version $Revision: 1.1 $
*/
public abstract class BaseClassLoaderTag extends TagSupport {
/**
* The class loader to use for instantiating application objects.
* If not specified, the context class loader, or the class loader
* used to load XMLParser itself, is used, based on the value of the
* <code>useContextClassLoader</code> variable.
*/
protected ClassLoader classLoader = null;
/**
* Do we want to use the Context ClassLoader when loading classes
* for instantiating new objects? Default is <code>false</code>.
*/
protected boolean useContextClassLoader = false;
/**
* Return the class loader to be used for instantiating application objects
* when required. This is determined based upon the following rules:
* <ul>
* <li>The class loader set by <code>setClassLoader()</code>, if any</li>
* <li>The thread context class loader, if it exists and the
* <code>useContextClassLoader</code> property is set to true</li>
* <li>The class loader used to load the XMLParser class itself.
* </ul>
*/
public ClassLoader getClassLoader() {
if (this.classLoader != null) {
return (this.classLoader);
}
if (this.useContextClassLoader) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
return (classLoader);
}
}
return (this.getClass().getClassLoader());
}
/**
* Set the class loader to be used for instantiating application objects
* when required.
*
* @param classLoader The new class loader to use, or <code>null</code>
* to revert to the standard rules
*/
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
/**
* Return the boolean as to whether the context classloader should be used.
*/
public boolean getUseContextClassLoader() {
return useContextClassLoader;
}
/**
* Determine whether to use the Context ClassLoader (the one found by
* calling <code>Thread.currentThread().getContextClassLoader()</code>)
* to resolve/load classes. If not
* using Context ClassLoader, then the class-loading defaults to
* using the calling-class' ClassLoader.
*
* @param boolean determines whether to use JellyContext ClassLoader.
*/
public void setUseContextClassLoader(boolean use) {
useContextClassLoader = use;
}
}
1.3 +27 -0 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/bean/Customer.java
Index: Customer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/bean/Customer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Customer.java 30 Oct 2002 19:16:28 -0000 1.2
+++ Customer.java 28 Nov 2002 00:22:23 -0000 1.3
@@ -62,6 +62,7 @@
package org.apache.commons.jelly.bean;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -87,6 +88,32 @@
public Customer() {
}
+ public Customer(String name) {
+ setName(name);
+ }
+
+ public Customer(String name, String city) {
+ setName(name);
+ setCity(city);
+ }
+
+ public Customer(String name, String city, Order anOrder) {
+ setName(name);
+ setCity(city);
+ addOrder(anOrder);
+ }
+
+ public Customer(Customer cust) {
+ setName(cust.getName());
+ setCity(cust.getCity());
+ setLocation(cust.getLocation());
+ List list = cust.getOrders();
+ if(null != list) {
+ for(Iterator iter = list.iterator();iter.hasNext();) {
+ addOrder((Order)iter.next());
+ }
+ }
+ }
public String toString() {
return super.toString() + "[name=" + name + ";city=" + city + "]";
1.5 +59 -85 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java
Index: TestSwitchTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestSwitchTag.java 30 Oct 2002 19:16:25 -0000 1.4
+++ TestSwitchTag.java 28 Nov 2002 00:22:23 -0000 1.5
@@ -61,23 +61,17 @@
*/
package org.apache.commons.jelly.core;
-import java.net.URL;
-
-import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.apache.commons.jelly.Jelly;
-import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.Script;
-import org.apache.commons.jelly.XMLOutput;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
-public class TestSwitchTag extends TestCase {
+public class TestSwitchTag extends BaseJellyTest {
public TestSwitchTag(String name) {
super(name);
@@ -89,102 +83,86 @@
public void setUp() throws Exception {
super.setUp();
- jelly = new Jelly();
- context = new JellyContext();
- xmlOutput = XMLOutput.createDummyXMLOutput();
}
- private void setUpScript(String scriptname) throws Exception {
- URL url = this.getClass().getResource(scriptname);
- if(null == url) {
- throw new Exception(
- "Could not find Jelly script: " + scriptname
- + " in package of class: " + getClass().getName()
- );
- }
- jelly.setUrl(url);
-
- String exturl = url.toExternalForm();
- int lastSlash = exturl.lastIndexOf("/");
- String extBase = exturl.substring(0,lastSlash+1);
- URL baseurl = new URL(extBase);
- context.setCurrentURL(baseurl);
- }
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
public void testSimpleSwitch() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("switch.on.a","two");
- script.run(context,xmlOutput);
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("switch.on.a","two");
+ script.run(getJellyContext(),getXMLOutput());
assertNull("should not have 'a.one' variable set",
- context.getVariable("a.one"));
+ getJellyContext().getVariable("a.one"));
assertTrue("should have set 'a.two' variable to 'true'",
- context.getVariable("a.two").equals("true"));
+ getJellyContext().getVariable("a.two").equals("true"));
assertNull("should not have 'a.three' variable set",
- context.getVariable("a.three"));
+ getJellyContext().getVariable("a.three"));
assertNull("should not have 'a.null' variable set",
- context.getVariable("a.null"));
+ getJellyContext().getVariable("a.null"));
assertNull("should not have 'a.default' variable set",
- context.getVariable("a.default"));
+ getJellyContext().getVariable("a.default"));
}
public void testFallThru() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("switch.on.a","one");
- script.run(context,xmlOutput);
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("switch.on.a","one");
+ script.run(getJellyContext(),getXMLOutput());
assertTrue("should have set 'a.one' variable to 'true'",
- context.getVariable("a.one").equals("true"));
+ getJellyContext().getVariable("a.one").equals("true"));
assertTrue("should have set 'a.two' variable to 'true'",
- context.getVariable("a.two").equals("true"));
+ getJellyContext().getVariable("a.two").equals("true"));
assertNull("should not have 'a.three' variable set",
- context.getVariable("a.three"));
+ getJellyContext().getVariable("a.three"));
assertNull("should not have 'a.null' variable set",
- context.getVariable("a.null"));
+ getJellyContext().getVariable("a.null"));
assertNull("should not have 'a.default' variable set",
- context.getVariable("a.default"));
+ getJellyContext().getVariable("a.default"));
}
public void testDefault() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("switch.on.a","negative one");
- script.run(context,xmlOutput);
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("switch.on.a","negative one");
+ script.run(getJellyContext(),getXMLOutput());
assertNull("should not have 'a.one' variable set",
- context.getVariable("a.one"));
+ getJellyContext().getVariable("a.one"));
assertNull("should not have 'a.two' variable set",
- context.getVariable("a.two"));
+ getJellyContext().getVariable("a.two"));
assertNull("should not have 'a.three' variable set",
- context.getVariable("a.three"));
+ getJellyContext().getVariable("a.three"));
assertNull("should not have 'a.null' variable set",
- context.getVariable("a.null"));
+ getJellyContext().getVariable("a.null"));
assertTrue("should have set 'a.default' variable to 'true'",
- context.getVariable("a.default").equals("true"));
+ getJellyContext().getVariable("a.default").equals("true"));
}
public void testNullCase() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("switch.on.a",null);
- script.run(context,xmlOutput);
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("switch.on.a",null);
+ script.run(getJellyContext(),getXMLOutput());
assertNull("should not have 'a.one' variable set",
- context.getVariable("a.one"));
+ getJellyContext().getVariable("a.one"));
assertNull("should not have 'a.two' variable set",
- context.getVariable("a.two"));
+ getJellyContext().getVariable("a.two"));
assertNull("should not have 'a.three' variable set",
- context.getVariable("a.three"));
+ getJellyContext().getVariable("a.three"));
assertTrue("should have set 'a.null' variable to 'true'",
- context.getVariable("a.null").equals("true"));
+ getJellyContext().getVariable("a.null").equals("true"));
assertNull("should not have 'a.default' variable set",
- context.getVariable("a.default"));
+ getJellyContext().getVariable("a.default"));
}
public void testSwitchWithoutOn() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("switch.without.on",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("switch.without.on",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected MissingAttributeException");
} catch(MissingAttributeException e) {
// expected
@@ -193,10 +171,10 @@
public void testCaseWithoutSwitch() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("case.without.switch",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("case.without.switch",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected JellyException");
} catch(JellyException e) {
// expected
@@ -205,10 +183,10 @@
public void testDefaultWithoutSwitch() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("default.without.switch",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("default.without.switch",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected JellyException");
} catch(JellyException e) {
// expected
@@ -217,10 +195,10 @@
public void testCaseWithoutValue() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("case.without.value",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("case.without.value",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected MissingAttributeException");
} catch(MissingAttributeException e) {
// expected
@@ -229,10 +207,10 @@
public void testMultipleDefaults() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("multiple.defaults",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("multiple.defaults",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected JellyException");
} catch(JellyException e) {
// expected
@@ -241,18 +219,14 @@
public void testCaseAfterDefault() throws Exception {
setUpScript("testSwitchTag.jelly");
- Script script = jelly.compileScript();
- context.setVariable("case.after.default",new Boolean(true));
+ Script script = getJelly().compileScript();
+ getJellyContext().setVariable("case.after.default",new Boolean(true));
try {
- script.run(context,xmlOutput);
+ script.run(getJellyContext(),getXMLOutput());
fail("Expected JellyException");
} catch(JellyException e) {
// expected
}
}
-
- private Jelly jelly = null;
- private JellyContext context = null;
- private XMLOutput xmlOutput = null;
}
1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/BaseJellyTest.java
Index: BaseJellyTest.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/BaseJellyTest.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/11/28 00:22:23 $
*
* ====================================================================
*
* 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: BaseJellyTest.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
*/
package org.apache.commons.jelly.core;
import java.net.URL;
import junit.framework.TestCase;
import org.apache.commons.jelly.Jelly;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.XMLOutput;
/**
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/11/28 00:22:23 $
*/
public abstract class BaseJellyTest extends TestCase {
public BaseJellyTest(String name) {
super(name);
}
public void setUp() throws Exception {
super.setUp();
jelly = new Jelly();
context = new JellyContext();
xmlOutput = XMLOutput.createDummyXMLOutput();
}
protected void setUpScript(String scriptname) throws Exception {
URL url = this.getClass().getResource(scriptname);
if(null == url) {
throw new Exception(
"Could not find Jelly script: " + scriptname
+ " in package of class: " + getClass().getName()
);
}
jelly.setUrl(url);
String exturl = url.toExternalForm();
int lastSlash = exturl.lastIndexOf("/");
String extBase = exturl.substring(0,lastSlash+1);
URL baseurl = new URL(extBase);
context.setCurrentURL(baseurl);
}
protected Jelly getJelly() {
return jelly;
}
protected JellyContext getJellyContext() {
return context;
}
protected XMLOutput getXMLOutput() {
return xmlOutput;
}
private Jelly jelly = null;
private JellyContext context = null;
private XMLOutput xmlOutput = null;
}
1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestNewTag.java
Index: TestNewTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestNewTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/11/28 00:22:23 $
*
* ====================================================================
*
* 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: TestNewTag.java,v 1.1 2002/11/28 00:22:23 rwaldhoff Exp $
*/
package org.apache.commons.jelly.core;
import java.util.Date;
import junit.framework.TestSuite;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.bean.Customer;
/**
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/11/28 00:22:23 $
*/
public class TestNewTag extends BaseJellyTest {
public TestNewTag(String name) {
super(name);
}
public static TestSuite suite() throws Exception {
return new TestSuite(TestNewTag.class);
}
public void setUp() throws Exception {
super.setUp();
}
public void tearDown() throws Exception {
super.tearDown();
}
public void testSimpleNew() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.simpleNew",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNull(customer.getName());
}
public void testNewThenOverwrite() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newThenOverwrite",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Date);
}
public void testNewWithLiteralArg() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithLiteralArg",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNotNull(customer.getName());
assertEquals("Jane Doe",customer.getName());
}
public void testNewWithTwoArgs() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithTwoArgs",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNotNull(customer.getName());
assertEquals("Jane Doe",customer.getName());
assertNotNull(customer.getCity());
assertEquals("Chicago",customer.getCity());
}
public void testNewWithExpressionArg() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithExpressionArg",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNotNull(customer.getName());
assertEquals("Jane Doe",customer.getName());
}
public void testNewWithNullArg() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithNullArg",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNull(customer.getName());
}
public void testNewWithNewArg() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithNewArg",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
{
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertNotNull(customer.getName());
assertEquals("",customer.getName());
}
{
assertNotNull(getJellyContext().getVariable("bar"));
assertTrue(getJellyContext().getVariable("bar") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("bar"));
assertEquals("Jane Doe",customer.getName());
assertEquals("Chicago",customer.getCity());
assertNotNull(customer.getOrders());
assertEquals(1,customer.getOrders().size());
assertNotNull(customer.getOrders().get(0));
}
{
assertNotNull(getJellyContext().getVariable("qux"));
assertTrue(getJellyContext().getVariable("qux") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("qux"));
assertEquals("Jane Doe",customer.getName());
assertEquals("Chicago",customer.getCity());
assertNotNull(customer.getOrders());
assertEquals(1,customer.getOrders().size());
assertNotNull(customer.getOrders().get(0));
}
}
public void testNewWithUseBeanArg() throws Exception {
setUpScript("testNewTag.jelly");
Script script = getJelly().compileScript();
getJellyContext().setVariable("test.newWithUseBeanArg",Boolean.TRUE);
script.run(getJellyContext(),getXMLOutput());
assertNotNull(getJellyContext().getVariable("foo"));
assertTrue(getJellyContext().getVariable("foo") instanceof Customer);
Customer customer = (Customer)(getJellyContext().getVariable("foo"));
assertEquals("Jane Doe",customer.getName());
assertEquals("Chicago",customer.getCity());
assertEquals("Location",customer.getLocation());
}
}
1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/testNewTag.jelly
Index: testNewTag.jelly
===================================================================
<j:jelly xmlns:j="jelly:core">
<j:if test="${test.simpleNew}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer"/>
</j:if>
<j:if test="${test.newThenOverwrite}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer"/>
<j:new var="foo" className="java.util.Date"/>
</j:if>
<j:if test="${test.newWithLiteralArg}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg value="Jane Doe"/>
</j:new>
</j:if>
<j:if test="${test.newWithTwoArgs}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg value="Jane Doe"/>
<j:arg value="Chicago"/>
</j:new>
</j:if>
<j:if test="${test.newWithExpressionArg}">
<j:set var="namearg" value="Jane Doe"/>
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg value="${namearg}"/>
</j:new>
</j:if>
<j:if test="${test.newWithNullArg}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg type="java.lang.String"/>
</j:new>
</j:if>
<j:if test="${test.newWithNewArg}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg type="java.lang.String">
<j:new className="java.lang.String"/>
</j:arg>
</j:new>
<j:new var="bar" className="org.apache.commons.jelly.bean.Customer">
<j:arg value="Jane Doe"/>
<j:arg value="Chicago"/>
<j:arg><j:new className="org.apache.commons.jelly.bean.Order"/></j:arg>
</j:new>
<j:new var="qux" className="org.apache.commons.jelly.bean.Customer">
<j:arg>
<j:new className="org.apache.commons.jelly.bean.Customer">
<j:arg value="Jane Doe"/>
<j:arg value="Chicago"/>
<j:arg><j:new className="org.apache.commons.jelly.bean.Order"/></j:arg>
</j:new>
</j:arg>
</j:new>
</j:if>
<j:if test="${test.newWithUseBeanArg}">
<j:new var="foo" className="org.apache.commons.jelly.bean.Customer">
<j:arg>
<j:useBean class="org.apache.commons.jelly.bean.Customer" name="Jane Doe" city="Chicago" location="Location"/>
</j:arg>
</j:new>
</j:if>
</j:jelly>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>