geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r812229 - in /geronimo/xbean/trunk/xbean-spring/src: main/java/org/apache/xbean/spring/generator/ test/java/org/apache/xbean/spring/generator/
Date Mon, 07 Sep 2009 17:16:44 GMT
Author: djencks
Date: Mon Sep  7 17:16:43 2009
New Revision: 812229

URL: http://svn.apache.org/viewvc?rev=812229&view=rev
Log:
XBEAN-136 use property editor when applicable, patch from Gary Tully

Modified:
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/WikiDocumentationGenerator.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java?rev=812229&r1=812228&r2=812229&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
Mon Sep  7 17:16:43 2009
@@ -136,7 +136,7 @@
             out.println("  <tr><th>Attribute</th><th>Type</th><th>Description</th>");
             for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();)
{
                 AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
-                Type type = attributeMapping.getType();
+                Type type = attributeMapping.getPropertyEditor() != null ?  Type.newSimpleType(String.class.getName())
: attributeMapping.getType();
                 if (namespaceMapping.isSimpleType(type)) {
                     out.println("  <tr><td>" + attributeMapping.getAttributeName()
+ "</td><td>" + Utils.getXsdType(type)
                             + "</td><td>" + attributeMapping.getDescription()
+ "</td></tr>");

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/WikiDocumentationGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/WikiDocumentationGenerator.java?rev=812229&r1=812228&r2=812229&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/WikiDocumentationGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/WikiDocumentationGenerator.java
Mon Sep  7 17:16:43 2009
@@ -182,7 +182,7 @@
 
             for ( Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();
) {
                 AttributeMapping attribute = (AttributeMapping) iterator.next();
-                Type type = attribute.getType();
+                Type type = attribute.getPropertyEditor() != null ? Type.newSimpleType(String.class.getName()):
attribute.getType();
                 out.println("    | " + attribute.getAttributeName() + " | "+getTypeLink(type,
refercencedTypes)+" | {html}"+attribute.getDescription()+"{html} |");	
 	          }
         }

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java?rev=812229&r1=812228&r2=812229&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
Mon Sep  7 17:16:43 2009
@@ -48,7 +48,7 @@
         }
     }
 
-    private void generateSchema(PrintWriter out, NamespaceMapping namespaceMapping) {
+    public void generateSchema(PrintWriter out, NamespaceMapping namespaceMapping) {
         out.println("<?xml version='1.0'?>");
         out.println("<!-- NOTE: this file is autogenerated by Apache XBean -->");
         out.println();
@@ -142,8 +142,11 @@
     }
 
     private void generateElementMappingSimpleProperty(PrintWriter out, AttributeMapping attributeMapping)
{
+    	// types with property editors need to be xs:string in the schema to validate
+    	String type = attributeMapping.getPropertyEditor() != null ? 
+    			Utils.getXsdType(Type.newSimpleType(String.class.getName())) : Utils.getXsdType(attributeMapping.getType());
         if (!isEmptyString(attributeMapping.getDescription())) {
-            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + Utils.getXsdType(attributeMapping.getType()) + "'>");
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + type + "'>");
             out.println("        <xs:annotation>");
             out.println("          <xs:documentation><![CDATA[");
             out.println("            " + attributeMapping.getDescription());
@@ -151,7 +154,7 @@
             out.println("        </xs:annotation>");
             out.println("      </xs:attribute>");
         } else {
-            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + Utils.getXsdType(attributeMapping.getType()) + "'/>");
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + type + "'/>");
         }
     }
 
@@ -210,4 +213,5 @@
     public void setLog(LogFacade log) {
         this.log = log;
     }
+
 }

Modified: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/CheeseService.java?rev=812229&r1=812228&r2=812229&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
Mon Sep  7 17:16:43 2009
@@ -28,6 +28,8 @@
     private String id;
     private String name;
 
+    private long volume;
+    
     public CheeseService(String id, String name) {
         this.id = id;
         this.name = name;
@@ -40,4 +42,15 @@
     public String getName() {
         return name;
     }
+    
+    public long getVolumeWithPropertyEditor() {
+    	return volume;
+    }
+    
+    /**
+    * @org.apache.xbean.Property propertyEditor="org.apache.xbean.spring.example.MilliLittersPropertyEditor"
+    */
+    public void setVolumeWithPropertyEditor(long volume) {
+    	this.volume = volume;
+    }
 }

Modified: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java?rev=812229&r1=812228&r2=812229&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
Mon Sep  7 17:16:43 2009
@@ -19,12 +19,14 @@
 import java.beans.PropertyEditorManager;
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import junit.framework.TestCase;
 import org.apache.xbean.spring.example.BeerService;
@@ -61,6 +63,29 @@
         Map flatCollections = recipeService.getFlatCollections();
         assertNotNull(flatCollections);
         assertEquals(1, flatCollections.size());
+        
+        ElementMapping cheese = defaultNamespace.getElement("cheese");
+        assertNotNull(cheese);
+        AttributeMapping volume = cheese.getAttribute("volumeWithPropertyEditor");
+        assertNotNull(volume);
+        assertNotNull(volume.getPropertyEditor());
+        assertEquals(volume.getType().getName(), "long");
+        
+        // validate xsd has string for attribute VolumeWithPropertyEditor
+        final AtomicBoolean gotExpected = new AtomicBoolean(false);
+        XsdGenerator generator = new XsdGenerator(null);
+        generator.generateSchema(new PrintWriter("dummy") {
+
+			@Override
+			public void println(String x) {
+				if (x.indexOf("volumeWithPropertyEditor") != -1) {
+					if (x.indexOf("xs:string") != -1) {
+						gotExpected.set(true);
+					}
+				}
+			}}, defaultNamespace);
+        
+        assertTrue("xsd with string got genereated", gotExpected.get());
     }
 
     public void testQdoxExcludeClass() throws Exception{



Mime
View raw message