commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl DynaTagScript.java StaticTag.java TagScript.java BeanTagScript.java StaticTagScript.java
Date Thu, 27 Jun 2002 14:09:15 GMT
jstrachan    2002/06/27 07:09:15

  Modified:    jelly/src/java/org/apache/commons/jelly/impl
                        DynaTagScript.java StaticTag.java TagScript.java
                        BeanTagScript.java StaticTagScript.java
  Log:
  patched the Script implementations to capture line and column number information better.
Now exceptions thrown while setting tag attributes will have location information attached
  
  Revision  Changes    Path
  1.9       +27 -19    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DynaTagScript.java	25 Jun 2002 17:10:07 -0000	1.8
  +++ DynaTagScript.java	27 Jun 2002 14:09:15 -0000	1.9
  @@ -66,6 +66,7 @@
   
   import org.apache.commons.jelly.CompilableTag;
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.DynaTag;
  @@ -109,21 +110,28 @@
   
       /** Evaluates the body of a tag */
       public void run(JellyContext context, XMLOutput output) throws Exception {
  -
  -        tag.setContext(context);
  +        try {
  +            tag.setContext(context);
  +            
  +            DynaTag dynaTag = (DynaTag) tag;
  +    
  +            // ### probably compiling this to 2 arrays might be quicker and smaller
  +            for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  +                Map.Entry entry = (Map.Entry) iter.next();
  +                String name = (String) entry.getKey();
  +                Expression expression = (Expression) entry.getValue();
  +    
  +                Object value = expression.evaluate(context);
  +                dynaTag.setAttribute(name, value);
  +            }
           
  -        DynaTag dynaTag = (DynaTag) tag;
  -
  -        // ### probably compiling this to 2 arrays might be quicker and smaller
  -        for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  -            Map.Entry entry = (Map.Entry) iter.next();
  -            String name = (String) entry.getKey();
  -            Expression expression = (Expression) entry.getValue();
  -
  -            Object value = expression.evaluate(context);
  -            dynaTag.setAttribute(name, value);
  +            tag.doTag(output);
  +        } 
  +        catch (JellyException e) {
  +            handleException(e);
  +        }
  +        catch (Exception e) {
  +            handleException(e);
           }
  -        
  -        runTag(output);
       }
   }
  
  
  
  1.9       +6 -6      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StaticTag.java	26 Jun 2002 09:24:36 -0000	1.8
  +++ StaticTag.java	27 Jun 2002 14:09:15 -0000	1.9
  @@ -107,7 +107,7 @@
       //-------------------------------------------------------------------------       
            
       public void doTag(XMLOutput output) throws Exception {
           output.startElement(uri, localName, qname, attributes);
  -        invokeBody(  output);
  +        invokeBody(output);
           output.endElement(uri, localName, qname);
       }
       
  
  
  
  1.13      +30 -27    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TagScript.java	25 Jun 2002 17:11:41 -0000	1.12
  +++ TagScript.java	27 Jun 2002 14:09:15 -0000	1.13
  @@ -197,28 +197,8 @@
       // Implementation methods
       //-------------------------------------------------------------------------      
       
  -    /**
  -     * Evaluates the tag, catching any exceptions and rethrowing them in
  -     * a wrapped exception which includes the line and column numbers
  -     */
  -    protected void runTag(XMLOutput output) throws Exception {
  -		try {
  -			tag.doTag(output);
  -		} 
  -        catch (JellyException e) {
  -			if (e.getLineNumber() == -1) {
  -				e.setColumnNumber(columnNumber);
  -				e.setLineNumber(lineNumber);
  -			}
  -			throw e;
  -		}
  -        catch (Exception e) {
  -            log.error( "Caught exception: " + e, e );
  -            throw new JellyException(e, columnNumber, lineNumber);            
  -        }
  -    }
  -    
  -    /** Converts the given value to the required type. 
  +    /** 
  +     * Converts the given value to the required type. 
        *
        * @param value is the value to be converted. This will not be null
        * @param requiredType the type that the value should be converted to
  @@ -232,5 +212,28 @@
               return ConvertUtils.convert((String) value, requiredType);
           }
           return value;
  +    }
  +    
  +    /**
  +     * A helper method to handle this non-Jelly exception.
  +     * This method will rethrow the exception, wrapped in a JellyException
  +     * while adding line number information etc.
  +     */
  +    protected void handleException(Exception e) throws Exception {
  +        log.error( "Caught exception: " + e, e );
  +        throw new JellyException(e, columnNumber, lineNumber);            
  +    }
  +    
  +    /**
  +     * A helper method to handle this Jelly exception.
  +     * This method adorns the JellyException with location information
  +     * such as adding line number information etc.
  +     */
  +    protected void handleException(JellyException e) throws Exception {
  +        if (e.getLineNumber() == -1) {
  +            e.setColumnNumber(columnNumber);
  +            e.setLineNumber(lineNumber);
  +        }
  +        throw e;
       }
   }
  
  
  
  1.11      +19 -8     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java
  
  Index: BeanTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BeanTagScript.java	21 Jun 2002 02:57:17 -0000	1.10
  +++ BeanTagScript.java	27 Jun 2002 14:09:15 -0000	1.11
  @@ -180,7 +180,10 @@
           for ( Iterator iter = attributes.keySet().iterator(); iter.hasNext(); ) {
               String name = (String) iter.next();
               if ( ! attributeSet.contains( name ) ) {
  -                throw new JellyException( "This tag does not understand the attribute '"
+ name + "'" );
  +                throw new JellyException( 
  +                    "This tag does not understand the attribute '" + name + "'", 
  +                    getColumnNumber(), getLineNumber()  
  +                );
               }
           }
           return this;
  @@ -223,11 +226,19 @@
                   throw new JellyException( 
                       "Cannot call method: " + method.getName() + " on tag of type: " 
                       + tag.getClass().getName() + " with value: " + value + " of type: "

  -                    + valueTypeName + ". Exception: " + e, e 
  +                    + valueTypeName + ". Exception: " + e, getColumnNumber(), getLineNumber()
                   );
               }
           }
           
  -        runTag(output);
  +        try {
  +            tag.doTag(output);
  +        } 
  +        catch (JellyException e) {
  +            handleException(e);
  +        }
  +        catch (Exception e) {
  +            handleException(e);
  +        }
       }
   }
  
  
  
  1.2       +22 -14    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java
  
  Index: StaticTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StaticTagScript.java	25 Jun 2002 19:12:29 -0000	1.1
  +++ StaticTagScript.java	27 Jun 2002 14:09:15 -0000	1.2
  @@ -66,6 +66,7 @@
   
   import org.apache.commons.jelly.CompilableTag;
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.DynaTag;
  @@ -105,28 +106,35 @@
       //-------------------------------------------------------------------------       
        
       /** Evaluates the body of a tag */
       public void run(JellyContext context, XMLOutput output) throws Exception {
  -
           if ( firstRun ) {
               firstRun = false;
               
               // lets see if we have a dynamic tag
               tag = findDynamicTag(context, (StaticTag) tag);
           }
  -        tag.setContext(context);
  +        try {        
  +            tag.setContext(context);
  +            
  +            DynaTag dynaTag = (DynaTag) tag;
  +    
  +            // ### probably compiling this to 2 arrays might be quicker and smaller
  +            for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  +                Map.Entry entry = (Map.Entry) iter.next();
  +                String name = (String) entry.getKey();
  +                Expression expression = (Expression) entry.getValue();
  +    
  +                Object value = expression.evaluate(context);
  +                dynaTag.setAttribute(name, value);
  +            }
           
  -        DynaTag dynaTag = (DynaTag) tag;
  -
  -        // ### probably compiling this to 2 arrays might be quicker and smaller
  -        for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  -            Map.Entry entry = (Map.Entry) iter.next();
  -            String name = (String) entry.getKey();
  -            Expression expression = (Expression) entry.getValue();
  -
  -            Object value = expression.evaluate(context);
  -            dynaTag.setAttribute(name, value);
  +            tag.doTag(output);
  +        } 
  +        catch (JellyException e) {
  +            handleException(e);
  +        }
  +        catch (Exception e) {
  +            handleException(e);
           }
  -        
  -        runTag(output);
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message