commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules DigesterLoaderTest.java
Date Thu, 27 Mar 2003 18:54:46 GMT
rdonkin     2003/03/27 10:54:45

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterRuleParser.java digester-rules.dtd
               digester/src/test/org/apache/commons/digester/xmlrules
                        DigesterLoaderTest.java
  Log:
  Added support for call-param from stack to xml rules.. Enhancement requested as bug  #16413.
  
  Revision  Changes    Path
  1.13      +23 -1     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
  
  Index: DigesterRuleParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DigesterRuleParser.java	15 Mar 2003 18:38:54 -0000	1.12
  +++ DigesterRuleParser.java	27 Mar 2003 18:54:45 -0000	1.13
  @@ -556,7 +556,29 @@
               // create callparamrule
               int paramIndex = Integer.parseInt(attributes.getValue("paramnumber"));
               String attributeName = attributes.getValue("attrname");
  -            Rule callParamRule = new CallParamRule( paramIndex, attributeName );
  +            String fromStack = attributes.getValue("from-stack");
  +            Rule callParamRule = null;
  +            if (attributeName == null) {
  +                if (fromStack == null) {
  +                
  +                    callParamRule = new CallParamRule( paramIndex );
  +                
  +                } else {
  +
  +                    callParamRule = new CallParamRule( paramIndex, Boolean.valueOf(fromStack).booleanValue());
  +                    
  +                }
  +            } else {
  +                if (fromStack == null) {
  +                    
  +                    callParamRule = new CallParamRule( paramIndex, attributeName );
  +                    
  +                    
  +                } else {
  +                    // specifying both from-stack and attribute name is not allowed
  +                    throw new RuntimeException("Attributes from-stack and attrname cannot
both be present.");
  +                }
  +            }
               return callParamRule;
           }
       }
  
  
  
  1.8       +8 -3      jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd
  
  Index: digester-rules.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- digester-rules.dtd	15 Mar 2003 18:38:54 -0000	1.7
  +++ digester-rules.dtd	27 Mar 2003 18:54:45 -0000	1.8
  @@ -80,12 +80,17 @@
       paramcount CDATA #IMPLIED
       paramtypes CDATA #IMPLIED>
   
  -<!-- CallParamRule -->
  +<!-- 
  +    CallParamRule 
  +    attrname - set param from attribute value (cannot be combined with from-stack)
  +    from-stack - set param from stack (cannot be combined with attrname)
  +    -->
   <!ELEMENT call-param-rule EMPTY>
   <!ATTLIST call-param-rule
       pattern  CDATA #IMPLIED
       paramnumber CDATA #REQUIRED
  -    attrname CDATA #IMPLIED>
  +    attrname CDATA #IMPLIED
  +    from-stack CDATA #IMPLIED>
   
   <!-- 
       FactoryCreateRule 
  
  
  
  1.12      +20 -0     jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.java
  
  Index: DigesterLoaderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DigesterLoaderTest.java	15 Mar 2003 18:36:15 -0000	1.11
  +++ DigesterLoaderTest.java	27 Mar 2003 18:54:45 -0000	1.12
  @@ -296,4 +296,24 @@
           }        
       }
   
  +    public void testCallParamRule() throws Exception {
  +    
  +        URL rules = ClassLoader.getSystemResource
  +            ("org/apache/commons/digester/xmlrules/test-call-param-rules.xml");
  +        
  +        String xml = "<?xml version='1.0' ?>"
  +                     + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
  +        
  +        CallParamTestObject testObject = new CallParamTestObject();
  +        
  +        DigesterLoader.load(
  +                                    rules, 
  +                                    getClass().getClassLoader(), 
  +                                    new StringReader(xml),
  +                                    testObject);        
  +                                                                        
  +        assertEquals("Incorrect left value", "long", testObject.getLeft());
  +        assertEquals("Incorrect middle value", "short", testObject.getMiddle());
  +        assertEquals("Incorrect right value", "", testObject.getRight());
  +    }
   }
  
  
  

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


Mime
View raw message