cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r606220 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/xmlschema/ rt/javascript/src/main/java/org/apache/cxf/javascript/ rt/javascript/src/main/java/org/apache/cxf/javascript/types/ rt/javascript/src/test/java/...
Date Fri, 21 Dec 2007 15:39:12 GMT
Author: bimargulies
Date: Fri Dec 21 07:39:11 2007
New Revision: 606220

URL: http://svn.apache.org/viewvc?rev=606220&view=rev
Log:
Add some code to write out comments about enums.

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java?rev=606220&r1=606219&r2=606220&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
Fri Dec 21 07:39:11 2007
@@ -19,12 +19,20 @@
 
 package org.apache.cxf.common.xmlschema;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
+import org.apache.ws.commons.schema.XmlSchemaFacet;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
 
 /**
  * Some functions that avoid problems with Commons XML Schema.  
@@ -98,5 +106,46 @@
         element.setRefName(name);
         // cxf conventionally keeps something in the name slot.
         setNameFromQName(element, name);
+    }
+    
+    /**
+     * Return true if a simple type is a straightforward XML Schema representation of an
enumeration.
+     * If we discover schemas that are 'enum-like' with more complex structures, we might
+     * make this deal with them.
+     * @param type Simple type, possible an enumeration.
+     * @return true for an enumeration.
+     */
+    public static boolean isEumeration(XmlSchemaSimpleType type) {
+        XmlSchemaSimpleTypeContent content = type.getContent();
+        if (!(content instanceof XmlSchemaSimpleTypeRestriction)) {
+            return false;
+        }
+        XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
+        XmlSchemaObjectCollection facets = restriction.getFacets();
+        for (int x = 0; x < facets.getCount(); x++) {
+            XmlSchemaFacet facet = (XmlSchemaFacet) facets.getItem(x);
+            if (!(facet instanceof XmlSchemaEnumerationFacet)) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    /**
+     * Retrieve the string values for an enumeration.
+     * @param type
+     * @return
+     */
+    public static List<String> enumeratorValues(XmlSchemaSimpleType type) {
+        XmlSchemaSimpleTypeContent content = type.getContent();
+        XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
+        XmlSchemaObjectCollection facets = restriction.getFacets();
+        List<String> values = new ArrayList<String>(); 
+        for (int x = 0; x < facets.getCount(); x++) {
+            XmlSchemaFacet facet = (XmlSchemaFacet) facets.getItem(x);
+            XmlSchemaEnumerationFacet enumFacet = (XmlSchemaEnumerationFacet) facet;
+            values.add(enumFacet.getValue().toString());
+        }
+        return values;
     }
 }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java?rev=606220&r1=606219&r2=606220&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
Fri Dec 21 07:39:11 2007
@@ -269,6 +269,4 @@
         }
         return null;
     }
-        
-
 }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=606220&r1=606219&r2=606220&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
Fri Dec 21 07:39:11 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.javascript.types;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
@@ -28,6 +29,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
 import org.apache.cxf.javascript.ElementInfo;
 import org.apache.cxf.javascript.JavascriptUtils;
 import org.apache.cxf.javascript.NameManager;
@@ -103,6 +105,17 @@
                 } catch (UnsupportedConstruct usc) {
                     LOG.warning(usc.toString());
                     continue; // it could be empty, but the style checker would complain.
+                }
+            } else if (xmlSchemaObject instanceof XmlSchemaSimpleType) {
+                XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) xmlSchemaObject;
+                if (XmlSchemaTools.isEumeration(simpleType)) {
+                    List<String> values = XmlSchemaTools.enumeratorValues(simpleType);
+                    code.append("//\n");
+                    code.append("// Simple type (enumeration) " + simpleType.getQName() +
"\n");
+                    code.append("//\n");
+                    for (String value : values) {
+                        code.append("// - " + value + "\n");
+                    }
                 }
             }
         }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java?rev=606220&r1=606219&r2=606220&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java
Fri Dec 21 07:39:11 2007
@@ -22,13 +22,11 @@
 import java.util.Arrays;
 
 import javax.xml.bind.annotation.XmlElement;
-//import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 /**
  * Bean with a selection of elements suitable for testing the JavaScript client.
  */
-//@XmlRootElement(namespace = "uri:org.apache.cxf.javascript.testns")
 @XmlType(namespace = "uri:org.apache.cxf.javascript.testns")
 public class TestBean1 {
     
@@ -58,8 +56,13 @@
     public TestBean2 beanTwoItem;
     @XmlElement(required = false)
     public TestBean2 beanTwoNotRequiredItem;
+    public AnEnum enumeration;
     //CHECKSTYLE:ON
     
+    public AnEnum getEnumeration() {
+        return enumeration;
+    }
+    
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof TestBean1)) {
@@ -71,7 +74,8 @@
             && longItem == other.longItem
             && optionalIntItem == other.optionalIntItem
             && doubleItem == other.doubleItem
-            && beanTwoItem.equals(other.beanTwoItem);
+            && beanTwoItem.equals(other.beanTwoItem)
+            && enumeration == other.enumeration;
         if (!equalSoFar) {
             return false;
         }
@@ -163,6 +167,7 @@
         } else {
             builder.append(beanTwoNotRequiredItem.toString()); 
         }
+        builder.append(" " + enumeration);
         
         return builder.toString();
     }



Mime
View raw message