geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r436863 - /geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
Date Fri, 25 Aug 2006 17:22:13 GMT
Author: gnodet
Date: Fri Aug 25 10:22:13 2006
New Revision: 436863

URL: http://svn.apache.org/viewvc?rev=436863&view=rev
Log:
XBEAN-47: Add missing docs to the generated xsd

Modified:
    geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java

Modified: geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java?rev=436863&r1=436862&r2=436863&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
Fri Aug 25 10:22:13 2006
@@ -74,6 +74,15 @@
         String localName = element.getElementName();
 
         out.println("  <xs:element name='" + localName + "'>");
+
+        if (!isEmptyString(element.getDescription())) {
+            out.println("    <xs:annotation>");
+            out.println("      <xs:documentation><![CDATA[");
+            out.println("        " + element.getDescription());
+            out.println("      ]]></xs:documentation>");
+            out.println("    </xs:annotation>");
+        }
+
         out.println("    <xs:complexType>");
 
         int complexCount = 0;
@@ -110,6 +119,18 @@
         out.println();
     }
 
+    private boolean isEmptyString(String str) {
+        if (str == null) {
+            return true;
+        }
+        for (int i = 0; i < str.length(); i++) {
+            if (!Character.isWhitespace(str.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     private void generateIDAttributeMapping(PrintWriter out, NamespaceMapping namespaceMapping,
ElementMapping element) {
         for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();)
{
             AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
@@ -121,11 +142,31 @@
     }
 
     private void generateElementMappingSimpleProperty(PrintWriter out, AttributeMapping attributeMapping)
{
-        out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + Utils.getXsdType(attributeMapping.getType()) + "'/>");
+        if (!isEmptyString(attributeMapping.getDescription())) {
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + Utils.getXsdType(attributeMapping.getType()) + "'>");
+            out.println("        <xs:annotation>");
+            out.println("          <xs:documentation><![CDATA[");
+            out.println("            " + attributeMapping.getDescription());
+            out.println("          ]]></xs:documentation>");
+            out.println("        </xs:annotation>");
+            out.println("      </xs:attribute>");
+        } else {
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='" + Utils.getXsdType(attributeMapping.getType()) + "'/>");
+        }
     }
 
     private void generateElementMappingComplexPropertyAsRef(PrintWriter out, AttributeMapping
attributeMapping) {
-        out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='xs:string'/>");
+        if (!isEmptyString(attributeMapping.getDescription())) {
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='xs:string'>");
+            out.println("        <xs:annotation>");
+            out.println("          <xs:documentation><![CDATA[");
+            out.println("            " + attributeMapping.getDescription());
+            out.println("          ]]></xs:documentation>");
+            out.println("        </xs:annotation>");
+            out.println("      </xs:attribute>");
+        } else {
+            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName()
+ "' type='xs:string'/>");
+        }
     }
 
     private void generateElementMappingComplexProperty(PrintWriter out, NamespaceMapping
namespaceMapping, AttributeMapping attributeMapping) {
@@ -140,6 +181,13 @@
         String maxOccurs = type.isCollection() ? "unbounded" : "1";
 
         out.println("        <xs:element name='" + attributeMapping.getAttributeName()
+ "' minOccurs='0' maxOccurs='1'>");
+        if (!isEmptyString(attributeMapping.getDescription())) {
+            out.println("          <xs:annotation>");
+            out.println("            <xs:documentation><![CDATA[");
+            out.println("              " + attributeMapping.getDescription());
+            out.println("            ]]></xs:documentation>");
+            out.println("          </xs:annotation>");
+        }
         out.println("          <xs:complexType>");
         if (types.isEmpty()) {
             out.println("            <xs:sequence minOccurs='0' maxOccurs='" + maxOccurs
+ "'><xs:any/></xs:sequence>");



Mime
View raw message