You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/08 06:40:22 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean Manager.java MyContainerTag.java
dion 2004/09/07 21:40:22
Modified: jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean
BeanTagLibrary.java BeandefTag.java
jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean
Manager.java MyContainerTag.java
Log:
detab
Revision Changes Path
1.7 +17 -17 jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTagLibrary.java
Index: BeanTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTagLibrary.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BeanTagLibrary.java 25 Feb 2004 01:31:53 -0000 1.6
+++ BeanTagLibrary.java 8 Sep 2004 04:40:22 -0000 1.7
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,10 +37,10 @@
/** Synchronized map of tag names to bean classes */
private Map beanTypes = new Hashtable();
-
+
/** Synchronized map of tag names to invoke methods */
private Map invokeMethods = new Hashtable();
-
+
public BeanTagLibrary() {
registerTagFactory(
"beandef",
@@ -58,7 +58,7 @@
public void registerBean(String name, Class type) {
beanTypes.put(name, type);
}
-
+
/**
* Allows tags to register new bean types with an associated method
*/
@@ -71,37 +71,37 @@
invokeMethods.remove(name);
}
}
-
+
/**
* Allows tags to register new bean types with an associated method
*/
public void registerBean(String name, Class type, String methodName) {
Method method = MethodUtils.getAccessibleMethod(
- type, methodName, BeandefTag.EMPTY_ARGUMENT_TYPES
+ type, methodName, BeandefTag.EMPTY_ARGUMENT_TYPES
);
registerBean(name, type, method);
}
-
+
// TagLibrary interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public TagScript createTagScript(
final String name, final Attributes attributes
) throws JellyException {
- // check for standard tags first
+ // check for standard tags first
TagScript answer = super.createTagScript(name, attributes);
if (answer != null) {
return answer;
}
-
+
// lets try a dynamic tag
return new TagScript( createTagFactory(name, attributes) );
}
// Implementation methods
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
- /**
+ /**
* Factory method to create a TagFactory for a given tag attribute and attributes
*/
protected TagFactory createTagFactory(String name, Attributes attributes) throws JellyException {
@@ -120,11 +120,11 @@
Method invokeMethod = (Method) invokeMethods.get(name);
return new BeanTag(beanType, name, invokeMethod);
}
-
+
// its a property tag
return new BeanPropertyTag(name);
}
-
+
protected Class getBeanType(String name, Attributes attributes) {
return (Class) beanTypes.get(name);
}
1.7 +58 -58 jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java
Index: BeandefTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BeandefTag.java 25 Feb 2004 01:31:53 -0000 1.6
+++ BeandefTag.java 8 Sep 2004 04:40:22 -0000 1.7
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,10 +29,10 @@
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..
- *
+ *
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
@@ -43,90 +43,90 @@
/** An empty Map as I think Collections.EMPTY_MAP is only JDK 1.3 onwards */
private static final Map EMPTY_MAP = new HashMap();
-
+
protected static final Class[] EMPTY_ARGUMENT_TYPES = {};
/** the name of the tag to create */
private String name;
-
+
/** the Java class name to use for the tag */
private String className;
- /** the name of the invoke method */
- private String methodName;
-
+ /** the name of the invoke method */
+ private String methodName;
+
/** the ClassLoader used to load beans */
private ClassLoader classLoader;
-
+
/** the library in which to define this new bean tag */
private BeanTagLibrary library;
-
+
public BeandefTag(BeanTagLibrary library) {
this.library = library;
}
-
+
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
invokeBody(output);
-
- if (name == null) {
- throw new MissingAttributeException("name");
- }
- if (className == null) {
- throw new MissingAttributeException("className");
- }
-
- Class theClass = null;
- try {
- ClassLoader classLoader = getClassLoader();
- theClass = classLoader.loadClass(className);
- }
- catch (ClassNotFoundException e) {
- try {
- theClass = getClass().getClassLoader().loadClass(className);
- }
+
+ if (name == null) {
+ throw new MissingAttributeException("name");
+ }
+ if (className == null) {
+ throw new MissingAttributeException("className");
+ }
+
+ Class theClass = null;
+ try {
+ ClassLoader classLoader = getClassLoader();
+ theClass = classLoader.loadClass(className);
+ }
+ catch (ClassNotFoundException e) {
+ try {
+ theClass = getClass().getClassLoader().loadClass(className);
+ }
catch (ClassNotFoundException e2) {
- try {
- theClass = Class.forName(className);
- }
+ try {
+ theClass = Class.forName(className);
+ }
catch (ClassNotFoundException e3) {
log.error( "Could not load class: " + className + " exception: " + e, e );
- throw new JellyTagException(
- "Could not find class: "
- + className
- + " using ClassLoader: "
- + classLoader);
- }
- }
- }
-
- Method invokeMethod = getInvokeMethod(theClass);
-
+ throw new JellyTagException(
+ "Could not find class: "
+ + className
+ + " using ClassLoader: "
+ + classLoader);
+ }
+ }
+ }
+
+ Method invokeMethod = getInvokeMethod(theClass);
+
// @todo should we allow the variable name to be specified?
library.registerBean(name, theClass, invokeMethod);
- }
+ }
+
-
// Properties
- //-------------------------------------------------------------------------
-
- /**
+ //-------------------------------------------------------------------------
+
+ /**
* Sets the name of the tag to create
*/
public void setName(String name) {
this.name = name;
}
-
- /**
+
+ /**
* Sets the Java class name to use for the tag
*/
public void setClassName(String className) {
this.className = className;
}
-
+
/**
- * Sets the ClassLoader to use to load the class.
+ * Sets the ClassLoader to use to load the class.
* If no value is set then the current threads context class
* loader is used.
*/
@@ -137,7 +137,7 @@
/**
* @return the ClassLoader to use to load classes
* or will use the thread context loader if none is specified.
- */
+ */
public ClassLoader getClassLoader() {
if ( classLoader == null ) {
ClassLoader answer = Thread.currentThread().getContextClassLoader();
@@ -163,9 +163,9 @@
public void setMethodName(String methodName) {
this.methodName = methodName;
}
-
+
// Implementation methods
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
protected Method getInvokeMethod(Class theClass) {
if (methodName != null) {
// lets lookup the method name
1.4 +20 -20 jakarta-commons/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Manager.java
Index: Manager.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Manager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Manager.java 25 Feb 2004 01:31:50 -0000 1.3
+++ Manager.java 8 Sep 2004 04:40:22 -0000 1.4
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-/**
+/**
* A sample bean that we can construct via Jelly tags
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
@@ -33,37 +33,37 @@
private static final Log log = LogFactory.getLog(Manager.class);
private List customers = new ArrayList();
-
+
boolean invoked = false;
-
+
public Manager() {
}
-
+
public String toString() {
return super.toString() + "[customers=" + customers + "]";
}
- /**
- * The invoke method which is called when the bean is constructed
- */
- public void run() {
- invoked = true;
-
- log.info("Invoked the run() method with customers: " + customers);
- }
+ /**
+ * The invoke method which is called when the bean is constructed
+ */
+ public void run() {
+ invoked = true;
+
+ log.info("Invoked the run() method with customers: " + customers);
+ }
+
-
public List getCustomers() {
return customers;
}
-
+
public void addCustomer(Customer customer) {
customers.add(customer);
}
-
+
public void removeCustomer(Customer customer) {
customers.remove(customer);
- }
+ }
/**
* @return boolean
1.4 +10 -10 jakarta-commons/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/MyContainerTag.java
Index: MyContainerTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/MyContainerTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MyContainerTag.java 25 Feb 2004 01:31:50 -0000 1.3
+++ MyContainerTag.java 8 Sep 2004 04:40:22 -0000 1.4
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,19 +25,19 @@
/**
* A simple tag which demonstrates how to process beans generically.
- *
+ *
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
public class MyContainerTag extends TagSupport implements CollectionTag {
-
+
private List list = new ArrayList();
private String var;
-
+
public MyContainerTag() {
}
- // Tag interface
+ // Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws JellyTagException {
invokeBody(output);
@@ -45,13 +45,13 @@
list = new ArrayList();
}
- // CollectionTag interface
+ // CollectionTag interface
//-------------------------------------------------------------------------
public void addItem(Object value) {
list.add(value);
}
- // Properties
+ // Properties
//-------------------------------------------------------------------------
/**
* @return String
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org