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/08/09 20:01:03 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl DynamicBeanTag.java BeanTag.java
jstrachan 2002/08/09 11:01:02
Modified: jelly/src/java/org/apache/commons/jelly/tags/define
InvokeBodyTag.java DefineTagSupport.java
DefineTagLibrary.java AttributeTag.java
jelly/src/java/org/apache/commons/jelly/tags/jeez
TagDefTag.java
Added: jelly/src/java/org/apache/commons/jelly/tags/define
JellyBeanTag.java BeanTag.java ScriptTag.java
TaglibTag.java TagTag.java
jelly/src/java/org/apache/commons/jelly/impl
DynamicBeanTag.java
Removed: jelly/src/java/org/apache/commons/jelly/tags/define
DefineJellyBeanTag.java DefineBeanTag.java
DefineTagTag.java DefineScriptTag.java
DefineTagLibTag.java
jelly/src/java/org/apache/commons/jelly/impl BeanTag.java
Log:
modified the class names of the define tag library so that the autogenerated tag reference is accurate and the runtime (dynamic) implementaiton tags don't appear in the reference documentation.
Also tidied up the javadoc to make the reference a little more complete for the define library
Revision Changes Path
1.11 +9 -9 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java
Index: InvokeBodyTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- InvokeBodyTag.java 9 Aug 2002 17:26:40 -0000 1.10
+++ InvokeBodyTag.java 9 Aug 2002 18:01:01 -0000 1.11
@@ -73,10 +73,10 @@
import org.apache.commons.logging.LogFactory;
/**
- * <p><code>InvokeBodyTag</code> this tag needs to find
- * the correct parent DynamicTag instance and call its
- * body.</p>
- *
+ * <invokeBody> tag is used inside a <tag> tag
+ * (i.e. the definition of a dynamic tag) to invoke the tags body when
+ * the tag is invoked.
+ *
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
1.3 +2 -2 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagSupport.java
Index: DefineTagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefineTagSupport.java 9 Aug 2002 17:26:40 -0000 1.2
+++ DefineTagSupport.java 9 Aug 2002 18:01:01 -0000 1.3
@@ -82,8 +82,8 @@
* if one is not available
*/
protected DynamicTagLibrary getTagLibrary() throws JellyException {
- DefineTagLibTag tag
- = (DefineTagLibTag) findAncestorWithClass(DefineTagLibTag.class);
+ TaglibTag tag
+ = (TaglibTag) findAncestorWithClass(TaglibTag.class);
if ( tag == null ) {
throw new JellyException( "<define:tag> must be inside <define:taglib>" );
}
1.7 +10 -10 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibrary.java
Index: DefineTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibrary.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefineTagLibrary.java 9 Aug 2002 15:48:48 -0000 1.6
+++ DefineTagLibrary.java 9 Aug 2002 18:01:01 -0000 1.7
@@ -72,13 +72,13 @@
public class DefineTagLibrary extends TagLibrary {
public DefineTagLibrary() {
- registerTag( "taglib", DefineTagLibTag.class );
- registerTag( "tag", DefineTagTag.class );
- registerTag( "bean", DefineBeanTag.class );
- registerTag( "jellybean", DefineJellyBeanTag.class );
+ registerTag( "taglib", TaglibTag.class );
+ registerTag( "tag", TagTag.class );
+ registerTag( "bean", BeanTag.class );
+ registerTag( "jellybean", JellyBeanTag.class );
registerTag( "attribute", AttributeTag.class );
registerTag( "invokeBody", InvokeBodyTag.class );
- registerTag( "script", DefineScriptTag.class );
+ registerTag( "script", ScriptTag.class );
registerTag( "invoke", InvokeTag.class );
}
}
1.3 +1 -1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/AttributeTag.java
Index: AttributeTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/AttributeTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AttributeTag.java 9 Aug 2002 17:26:40 -0000 1.2
+++ AttributeTag.java 9 Aug 2002 18:01:01 -0000 1.3
@@ -99,7 +99,7 @@
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
- DefineBeanTag tag = (DefineBeanTag) findAncestorWithClass( DefineBeanTag.class );
+ BeanTag tag = (BeanTag) findAncestorWithClass( BeanTag.class );
if ( tag == null ) {
throw new JellyException( "This tag should be nested inside a <define:bean> or <define:jellybean> tag" );
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/JellyBeanTag.java
Index: JellyBeanTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/taglibs/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java,v 1.1 2002/05/21 07:58:55 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/05/21 07:58:55 $
*
* ====================================================================
*
* 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: BeanShellExpressionFactory.java,v 1.1 2002/05/21 07:58:55 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.define;
import java.lang.reflect.Method;
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Binds a Java bean to the given named Jelly tag so that the attributes of
* the tag set the bean properties. After the body of this tag is invoked
* then the beans invoke() method will be called, if the bean has one.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class JellyBeanTag extends BeanTag {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(JellyBeanTag.class);
/** Empty parameter types for Method lookup */
private static final Class[] emptyParamTypes = {};
/** the name of the method to invoke on the bean */
private String method;
// Properties
//-------------------------------------------------------------------------
/**
* @return the method name to use, which defaults to 'run' for Runnable
* objects
*/
public String getMethod() {
if ( method == null ) {
return "run";
}
return method;
}
/**
* Sets the name of the method to invoke on the bean.
* This defaults to "run" so that Runnable objects can be
* invoked, but this property can be set to whatever is required,
* such as "execute" or "invoke"
*/
public void setMethod(String method) {
this.method = method;
}
// Implementation methods
//-------------------------------------------------------------------------
protected Method getInvokeMethod( Class theClass ) throws Exception {
Method invokeMethod =
MethodUtils.getAccessibleMethod(
theClass,
getMethod(),
emptyParamTypes);
if ( invokeMethod == null ) {
}
return invokeMethod;
}
}
1.8 +133 -160 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/BeanTag.java
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/ScriptTag.java
Index: ScriptTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/ScriptTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
* $Revision: 1.5 $
* $Date: 2002/05/17 15:18: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: ScriptTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.define;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
/**
* <script> tag is used to assign a Script object
* to a variable. The script can then be called whenever the user wishes
* maybe from inside an expression or more typically via the <invoke> tag.</p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.5 $
*/
public class ScriptTag extends TagSupport {
private String var;
public ScriptTag() {
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
if ( var == null ) {
throw new JellyException( "<define:script> must have a var attribute" );
}
context.setVariable( var, getBody() );
}
// Properties
//-------------------------------------------------------------------------
/** @return the variable name of the script to create */
public String getVar() {
return var;
}
/** Sets the variable name of the tag to create */
public void setVar(String var) {
this.var = var;
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/TaglibTag.java
Index: TaglibTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/TaglibTag.java,v 1.8 2002/08/09 17:26:40 jstrachan Exp $
* $Revision: 1.8 $
* $Date: 2002/08/09 17:26:40 $
*
* ====================================================================
*
* 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: TaglibTag.java,v 1.8 2002/08/09 17:26:40 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.define;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.DynaTag;
import org.apache.commons.jelly.TagLibrary;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.impl.DynamicTagLibrary;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
/**
* The <taglib> tag is used to define a new tag library
* using a Jelly script..</p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.8 $
*/
public class TaglibTag extends TagSupport {
/** The namespace URI */
private String uri;
/** The new tags being added */
private DynamicTagLibrary tagLibrary;
public TaglibTag() {
}
public TaglibTag(String uri) {
this.uri = uri;
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
tagLibrary = new DynamicTagLibrary( getUri() );
context.registerTagLibrary( getUri(), tagLibrary );
invokeBody(output);
tagLibrary = null;
}
// Properties
//-------------------------------------------------------------------------
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public DynamicTagLibrary getTagLibrary() {
return tagLibrary;
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/TagTag.java
Index: TagTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/TagTag.java,v 1.5 2002/06/25 19:12:28 jstrachan Exp $
* $Revision: 1.5 $
* $Date: 2002/06/25 19:12:28 $
*
* ====================================================================
*
* 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: TagTag.java,v 1.5 2002/06/25 19:12:28 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.define;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
/**
* <tag> is used to define a new tag
* using a Jelly script to implement the behaviour of the tag.
* Parameters can be passed into the new tag using normal XML attribute
* notations. Inside the body of the tag definition, the attributes can
* be accessed as normal Jelly variables.</p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.5 $
*/
public class TagTag extends DefineTagSupport {
private String name;
public TagTag() {
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
getTagLibrary().registerDynamicTag( getName(), getBody() );
}
// Properties
//-------------------------------------------------------------------------
/** @return the name of the tag to create */
public String getName() {
return name;
}
/** Sets the name of the tag to create */
public void setName(String name) {
this.name = name;
}
}
1.4 +2 -2 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/TagDefTag.java
Index: TagDefTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/TagDefTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TagDefTag.java 9 Aug 2002 17:26:41 -0000 1.3
+++ TagDefTag.java 9 Aug 2002 18:01:01 -0000 1.4
@@ -64,7 +64,7 @@
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.impl.DynamicTagLibrary;
-import org.apache.commons.jelly.tags.define.DefineTagTag;
+import org.apache.commons.jelly.tags.define.TagTag;
/**
* This tag defines a dynamic tag in Jelly script. When the tag is invoked
@@ -77,7 +77,7 @@
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
-public class TagDefTag extends DefineTagTag {
+public class TagDefTag extends TagTag {
private DynamicTagLibrary tagLibrary;
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicBeanTag.java
Index: DynamicBeanTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
* $Revision: 1.7 $
* $Date: 2002/05/17 15:18: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: DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
*/
package org.apache.commons.jelly.impl;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.ConvertingWrapDynaBean;
import org.apache.commons.collections.BeanMap;
import org.apache.commons.jelly.DynaBeanTagSupport;
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.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.expression.Expression;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This tag is bound onto a Java Bean class. When the tag is invoked a bean will be created
* using the tags attributes.
* The bean may also have an invoke method called invoke(), run(), execute() or some such method
* which will be invoked after the bean has been configured.</p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @version $Revision: 1.7 $
*/
public class DynamicBeanTag extends DynaBeanTagSupport {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(DynamicBeanTag.class);
/** Empty arguments for Method.invoke() */
private static final Object[] emptyArgs = {};
/** the bean class */
private Class beanClass;
/** the current bean instance */
private Object bean;
/** the method to invoke on the bean */
private Method method;
/**
* the tag attribute name that is used to declare the name
* of the variable to export after running this tag
*/
private String variableNameAttribute;
/** the current variable name that the bean should be exported as */
private String var;
/** the set of attribute names we've already set */
private Set setAttributesSet = new HashSet();
/** the attribute definitions */
private Map attributes;
public DynamicBeanTag(Class beanClass, Map attributes, String variableNameAttribute, Method method) {
this.beanClass = beanClass;
this.method = method;
this.attributes = attributes;
this.variableNameAttribute = variableNameAttribute;
}
public void beforeSetAttributes() throws Exception {
// create a new dynabean before the attributes are set
bean = beanClass.newInstance();
setDynaBean( new ConvertingWrapDynaBean( bean ) );
setAttributesSet.clear();
}
public void setAttribute(String name, Object value) throws Exception {
boolean isVariableName = false;
if (variableNameAttribute != null ) {
if ( variableNameAttribute.equals( name ) ) {
if (value == null) {
var = null;
}
else {
var = value.toString();
}
isVariableName = true;
}
}
if (! isVariableName) {
// #### strictly speaking we could
// know what attributes are specified at compile time
// so this dynamic set is unnecessary
setAttributesSet.add(name);
// we could maybe implement attribute specific validation here
super.setAttribute(name, value);
}
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
// lets find any attributes that are not set and
for ( Iterator iter = attributes.values().iterator(); iter.hasNext(); ) {
Attribute attribute = (Attribute) iter.next();
String name = attribute.getName();
if ( ! setAttributesSet.contains( name ) ) {
if ( attribute.isRequired() ) {
throw new MissingAttributeException(name);
}
// lets get the default value
Object value = null;
Expression expression = attribute.getDefaultValue();
if ( expression != null ) {
value = expression.evaluate(context);
}
// only set non-null values?
if ( value != null ) {
super.setAttribute(name, value);
}
}
}
invokeBody(output);
// export the bean if required
if ( var != null ) {
context.setVariable(var, bean);
}
// now, I may invoke the 'execute' method if I have one
if ( method != null ) {
try {
method.invoke( bean, emptyArgs );
}
catch (IllegalAccessException e) {
methodInvocationError(bean, method, e);
}
catch (IllegalArgumentException e) {
methodInvocationError(bean, method, e);
}
catch (InvocationTargetException e) {
// methodInvocationError(bean, method, e);
Throwable inner = e.getTargetException();
if ( inner instanceof Exception )
{
throw (Exception) inner;
}
else
{
throw new JellyException( inner );
}
}
}
}
/**
* Report the state of the bean when method invocation fails
* so that the user can determine any problems that might
* be occuring while using dynamic jelly beans.
*
* @param bean Bean on which <code>method</code was invoked
* @param method Method that was invoked
* @param e Exception throw when <code>method</code> was invoked
*/
private void methodInvocationError(Object bean, Method method, Exception e) throws Exception {
log.error("Could not invoke " + method, e);
BeanMap beanMap = new BeanMap(bean);
log.error("Bean properties:");
for (Iterator i = beanMap.keySet().iterator(); i.hasNext();) {
String property = (String) i.next();
Object value = beanMap.get(property);
log.error(property + " -> " + value);
}
log.error(beanMap);
throw e;
}
// Properties
//-------------------------------------------------------------------------
/**
* @return the bean that has just been created
*/
public Object getBean() {
return bean;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>