commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc DEXET <Marc.De...@dsi.cnrs.fr>
Subject [jelly] proposition for catchTag
Date Wed, 03 Nov 2004 11:28:52 GMT
Maybe it's rather for dev list.
It's just a proposition to extends catchTag to filter in and out some
exception.

Index: CatchTag.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags
/core/CatchTag.java,v
retrieving revision 1.7
diff -u -r1.7 CatchTag.java
--- CatchTag.java 9 Sep 2004 12:27:53 -0000 1.7
+++ CatchTag.java 3 Nov 2004 11:13:34 -0000
@@ -15,7 +15,11 @@
  */
 package org.apache.commons.jelly.tags.core;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.commons.jelly.JellyTagException;
+import org.apache.commons.jelly.MissingAttributeException;
 import org.apache.commons.jelly.TagSupport;
 import org.apache.commons.jelly.XMLOutput;
 
@@ -30,25 +34,91 @@
 public class CatchTag extends TagSupport {
 
     private String var;
+    
+ private String exceptionList;
+ 
+ private Set exceptionSet;
+ 
+    
 
     public CatchTag() {
     }
 
     // Tag interface
 
//-------------------------------------------------------------------------
-    public void doTag(XMLOutput output) throws JellyTagException {
-        if (var != null) {
-            context.removeVariable(var);
-        }
-        try {
-            invokeBody(output);
-        }
-        catch (Throwable t) {
-            if (var != null) {
-                context.setVariable(var, t);
-            }
-        }
-    }
+ public void doTag(XMLOutput output) throws MissingAttributeException,
+ JellyTagException {
+
+  if ( exceptionList != null && exceptionSet == null ) {
+   try {
+    buildExceptionSet();
+   } catch (ClassNotFoundException e) {
+    throw new JellyTagException(e);
+   }
+  }
+  if (var != null) {
+      context.removeVariable(var);
+  }
+  try {
+      invokeBody(output);
+  }
+  catch (Throwable t) {
+   
+   if ( exceptionSet != null ) {
+    Class clazz = t.getClass();
+    if ( ! exceptionSet.contains(clazz)) {
+     throw new JellyTagException(t);
+    }
+   }
+      if (var != null) {
+          context.setVariable(var, t);
+      }
+  }  
+
+ }
+ 
+ /**
+  * @throws ClassNotFoundException
+  * 
+  */
+ private void buildExceptionSet() throws ClassNotFoundException {
+  
+  String[] strings = exceptionList.split(";");
+  if ( exceptionSet == null ) {
+   int size = ( strings.length > 0) ? strings.length : 1 ;
+   exceptionSet = new HashSet(size);
+  }
+  for ( int i = 0; i < strings.length; i ++) {
+   Class clazz = Class.forName(strings[i]);
+   exceptionSet.add(clazz);
+  }
+  
+ }
+
+ /**
+  * @return Returns the exceptionList.
+  */
+ public String getExceptionList() {
+  return exceptionList;
+ }
+ /**
+  * @param exceptionList The exceptionList to set.
+  */
+ public void setExceptionList(String exceptionList) {
+  this.exceptionList = exceptionList;
+ }
+ /**
+  * @return Returns the exceptionSet.
+  */
+ public Set getExceptionSet() {
+  return exceptionSet;
+ }
+ /**
+  * @param exceptionSet The exceptionSet to set.
+  */
+ public void setExceptionSet(Set exceptionSet) {
+  this.exceptionSet = exceptionSet;
+ } 
 
     // Properties
 
//-------------------------------------------------------------------------


-- 
Marc DeXeT
BEST - DSI Meudon
01.45.07.51.56
marc.dexet@dsi.cnrs.fr

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message