[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl StaticTag.java Dyna
From: jstrachan () apache ! org
Date: 2002-09-30 17:38:16
[Download RAW message or body]
jstrachan 2002/09/30 10:38:16
Modified: jelly/src/java/org/apache/commons/jelly MapTagSupport.java
DynaTag.java DynaBeanTagSupport.java
jelly/src/java/org/apache/commons/jelly/impl StaticTag.java
DynaTagScript.java DynamicTag.java
Added: jelly/src/java/org/apache/commons/jelly DynaTagSupport.java
Log:
Minor patch so that DynaTag objects can declare the types of their dynamic \
properties to facilitate better expression type coercion.
For example a DynaTag might have an attribute which is of type Expression which the \
DynaTag wishes to evaluate however it wishes without it just being turned into an \
Object. So this method allows DynaTag objects to return, for example, that an \
attribute is of type Expression.class allowing them to coerce the Expression \
themselves.
Revision Changes Path
1.4 +6 -6 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/MapTagSupport.java
Index: MapTagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/MapTagSupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MapTagSupport.java 17 May 2002 15:18:12 -0000 1.3
+++ MapTagSupport.java 30 Sep 2002 17:38:16 -0000 1.4
@@ -77,7 +77,7 @@
* @version $Revision$
*/
-public abstract class MapTagSupport extends TagSupport implements DynaTag {
+public abstract class MapTagSupport extends DynaTagSupport {
private Map map;
1.5 +12 -6 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaTag.java
Index: DynaTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynaTag.java 25 Jun 2002 17:59:32 -0000 1.4
+++ DynaTag.java 30 Sep 2002 17:38:16 -0000 1.5
@@ -81,7 +81,13 @@
/** Sets an attribute value of this tag before the tag is invoked
*/
-
public void setAttribute(String name, Object value) throws Exception;
+ /**
+ * @return the type of the given attribute. By default just return
+ * Object.class if this is not known.
+ * If this method returns Expression.class then the expression will not
+ * be evaluated and just passed in as the attribute value.
+ */
+ public Class getAttributeType(String name) throws Exception;
}
1.5 +14 -1 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaBeanTagSupport.java
Index: DynaBeanTagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaBeanTagSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynaBeanTagSupport.java 25 Jun 2002 17:59:50 -0000 1.4
+++ DynaBeanTagSupport.java 30 Sep 2002 17:38:16 -0000 1.5
@@ -63,6 +63,7 @@
package org.apache.commons.jelly;
import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaProperty;
/**
* <p><code>DynaBeanTag</code> is a DynaTag implementation which uses a DynaBean
@@ -74,7 +75,7 @@
* @version $Revision$
*/
-public abstract class DynaBeanTagSupport extends TagSupport implements DynaTag {
+public abstract class DynaBeanTagSupport extends DynaTagSupport {
/** the DynaBean which is used to store the attributes of this tag */
private DynaBean dynaBean;
@@ -98,6 +99,18 @@
getDynaBean().set(name, value);
}
+ /**
+ * @return the type of the given attribute. By default just return
+ * Object.class if this is not known.
+ */
+ public Class getAttributeType(String name) throws Exception {
+ DynaProperty property = \
getDynaBean().getDynaClass().getDynaProperty(name); + if (property != null) {
+ return property.getType();
+ }
+ return Object.class;
+ }
+
/**
* @return the DynaBean which is used to store the
* attributes of this tag
1.1 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaTagSupport.java
Index: DynaTagSupport.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaTagSupport.java,v \
1.3 2002/05/17 15:18:12 jstrachan Exp $
* $Revision: 1.3 $
* $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: DynaTagSupport.java,v 1.3 2002/05/17 15:18:12 jstrachan Exp $
*/
package org.apache.commons.jelly;
/**
* <p><code>DynaTagSupport</code> is an abstract base class
* for any DynaTag implementation to derive from.
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.3 $
*/
public abstract class DynaTagSupport extends TagSupport implements DynaTag {
/**
* @return the type of the given attribute. By default just return
* Object.class if this is not known.
*/
public Class getAttributeType(String name) throws Exception {
return Object.class;
}
}
1.11 +7 -7 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTag.java
Index: StaticTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTag.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- StaticTag.java 15 Jul 2002 11:22:27 -0000 1.10
+++ StaticTag.java 30 Sep 2002 17:38:16 -0000 1.11
@@ -63,7 +63,7 @@
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.DynaTag;
-import org.apache.commons.jelly.TagSupport;
+import org.apache.commons.jelly.DynaTagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.xml.sax.Attributes;
@@ -77,7 +77,7 @@
* @version $Revision$
*/
-public class StaticTag extends TagSupport implements DynaTag {
+public class StaticTag extends DynaTagSupport {
/** The namespace URI */
private String uri;
1.13 +24 -7 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java
Index: DynaTagScript.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DynaTagScript.java 13 Aug 2002 08:04:38 -0000 1.12
+++ DynaTagScript.java 30 Sep 2002 17:38:16 -0000 1.13
@@ -120,8 +120,15 @@
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
Expression expression = (Expression) entry.getValue();
-
- Object value = expression.evaluate(context);
+
+ Class type = dynaTag.getAttributeType(name);
+ Object value = null;
+ if (type != null && type.isAssignableFrom(Expression.class) && \
!type.isAssignableFrom(Object.class)) { + value = expression;
+ }
+ else {
+ value = expression.evaluate(context);
+ }
dynaTag.setAttribute(name, value);
}
}
@@ -133,6 +140,16 @@
String name = (String) entry.getKey();
Expression expression = (Expression) entry.getValue();
+/*
+ * @todo should implement this
+ Object value = null;
+ if (type.isAssignableFrom(Expression.class) && \
!type.isAssignableFrom(Object.class)) { + value = expression;
+ }
+ else {
+ value = expression.evaluate(context);
+ }
+*/
Object value = expression.evaluate(context);
dynaBean.set(name, value);
}
1.2 +2 -2 \
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTag.java \
Index: DynamicTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynamicTag.java 9 Aug 2002 17:26:40 -0000 1.1
+++ DynamicTag.java 30 Sep 2002 17:38:16 -0000 1.2
@@ -66,8 +66,8 @@
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.DynaTag;
+import org.apache.commons.jelly.DynaTagSupport;
import org.apache.commons.jelly.Script;
-import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.logging.Log;
@@ -82,7 +82,7 @@
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
-public class DynamicTag extends TagSupport implements DynaTag {
+public class DynamicTag extends DynaTagSupport {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(DynamicTag.class);
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic