commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r157354 - in jakarta/commons/proper/betwixt/trunk/src: java/org/apache/commons/betwixt/digester/ElementRule.java test/org/apache/commons/betwixt/SimpleClass.betwixt test/org/apache/commons/betwixt/TestClassProperty.java
Date Sun, 13 Mar 2005 22:17:37 GMT
Author: rdonkin
Date: Sun Mar 13 14:17:35 2005
New Revision: 157354

URL: http://svn.apache.org/viewcvs?view=rev&rev=157354
Log:
Added ability to specify class properties in the dot betwixt file. Contributed by Christoph
Gaffga. Issue #33887.

Added:
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestClassProperty.java
Modified:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/SimpleClass.betwixt

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java?view=diff&r1=157353&r2=157354
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java
Sun Mar 13 14:17:35 2005
@@ -258,12 +258,7 @@
         }
         
         // choose response from property type
-        
-        // TODO: ignore class property ??
-        if ( Class.class.equals( type ) && "class".equals( propertyDescriptor.getName()
) ) {
-            log.trace( "Ignoring class property" );
-            return;
-        }
+
         if ( getXMLIntrospector().isPrimitiveType( type ) ) {
             elementDescriptor.setTextExpression( new MethodExpression( readMethod ) );
             

Modified: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/SimpleClass.betwixt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/SimpleClass.betwixt?view=diff&r1=157353&r2=157354
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/SimpleClass.betwixt
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/SimpleClass.betwixt
Sun Mar 13 14:17:35 2005
@@ -18,5 +18,6 @@
     <element name="test-class">
         <attribute name="test-prop-1" property="testPropertyOne"/>
         <attribute name="test-prop-2" property="testPropertyTwo"/>
+        <element name="class" property="class"/>
     </element>
 </info>

Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestClassProperty.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestClassProperty.java?view=auto&rev=157354
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestClassProperty.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestClassProperty.java
Sun Mar 13 14:17:35 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.betwixt;
+
+import java.io.StringWriter;
+import java.util.Locale;
+
+import org.apache.commons.betwixt.io.BeanWriter;
+import org.apache.commons.betwixt.strategy.PropertySuppressionStrategy;
+
+/**
+ * This test is the result of a problem I had with outputting a bean's class
+ * property as XML. I had a request for that feature quite a while ago and the
+ * {@link #org.apache.commons.betwixt.strategy.PropertySupressionStretegy}was
+ * added to made this possible. It worked quite well, until I used beans
+ * described in dot-betwixt files that also output the class property like the
+ * following:
+ * 
+ * <pre>
+ *   &lt;info primitiveTypes="element"&gt;
+ *     &lt;element name="test-class"&gt;
+ *       &lt;attribute name="test-prop-1" property="testPropertyOne"/&gt;
+ *       &lt;attribute name="test-prop-2" property="testPropertyTwo"/&gt;
+ *       &lt;element name="class" property="class"/&gt;
+ *     &lt;/element&gt;
+ *   &lt;/info&gt;
+ * </pre>
+ * 
+ * So it worked without dot-betwixt files, but the seconds test
+ * {@link #testHasClassElementWithDotBetwixtFile()}would fail. There was a
+ * small block in {@link org.apache.commons.betwixt.digester.ElementRule}that
+ * was marked with ToDo, without that block it works.
+ * 
+ * @author Christoph Gaffga, cgaffga@triplemind.com
+ */
+public class TestClassProperty extends AbstractTestCase {
+
+    public TestClassProperty(String testName) {
+        super(testName);
+    }
+
+    public void testHasClassElementWithoutDotBetwixtFile() throws Exception {
+        // configure bean writer with counting suppression strategy...
+        StringWriter buffer = new StringWriter();
+        BeanWriter beanWriter = new BeanWriter(buffer);
+        beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(
+                new PropertySuppressionStrategy() {
+
+                    public boolean suppressProperty(Class clazz, Class propertyType,
+                            String propertyName) {
+                        return false;
+                    }
+                });
+
+        // test with class without dot-betwixt file...
+        Object bean = new Locale("de"); // just a bean with some properties
+        beanWriter.write(bean);
+
+        // was the class element written?..
+        assertTrue(buffer.toString().indexOf("<class>" + bean.getClass().getName()
+ "</class>") > 0);  
+    }
+
+    public void testHasClassElementWithDotBetwixtFile() throws Exception {
+        // configure bean writer with counting suppression strategy...
+        StringWriter buffer = new StringWriter();
+        BeanWriter beanWriter = new BeanWriter(buffer);
+        beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(
+                new PropertySuppressionStrategy() {
+
+                    public boolean suppressProperty(Class clazz, Class propertyType,
+                            String propertyName) {
+                        return false;
+                    }
+                });
+
+        // test with class without dot-betwixt file...
+        Object bean = new SimpleClass();
+        beanWriter.write(bean);
+
+        // was the class element written?..
+        assertTrue(buffer.toString().indexOf("<class>" + bean.getClass().getName()
+ "</class>") > 0);
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
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