Author: bimargulies
Date: Thu Nov  1 09:51:12 2007
New Revision: 591082

URL: http://svn.apache.org/viewvc?rev=591082&view=rev
Log:
Work around possible problem in RSFB in setting up refNames, fill in more 
testing of the javascript generator, and turn the tests 
back on.

Modified:
    
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/JavascriptTestUtilities.java
    
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java

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=591082&r1=591081&r2=591082&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
 Thu Nov  1 09:51:12 2007
@@ -303,6 +303,28 @@
     }
     
     /**
+     * This copes with an observed phenomenon in the schema built by the 
ReflectionServiceFactoryBean. It 
+     * is creating element such that: (a) the type is not set. (b) the refName 
is set. 
+     * (c) the namespaceURI in the refName is set empty. This apparently 
indicates 
+     * 'same Schema' to everyone else, so thus function implements
+     * that convention here. It is unclear if that is a correct structure, 
+     * and it if changes, we can simplify or eliminate this function.
+     * @param name
+     * @param referencingURI
+     * @return
+     */
+    private XmlSchemaElement findElementByRefName(QName name, String 
referencingURI) {
+        String uri = name.getNamespaceURI();
+        if ("".equals(uri)) {
+            uri = referencingURI;
+        }
+        QName copyName = new QName(uri, name.getLocalPart());
+        XmlSchemaElement target = 
xmlSchemaCollection.getElementByQName(copyName);
+        assert target != null;
+        return target;
+    }
+    
+    /**
      * Follow a chain of references from element to element until we can 
obtain a type.
      * @param element
      * @return
@@ -310,7 +332,8 @@
     private XmlSchemaType getElementType(XmlSchemaComplexType containingType, 
XmlSchemaElement element) {
         XmlSchemaElement originalElement = element;
         while (element.getSchemaType() == null && element.getRefName() != 
null) {
-            XmlSchemaElement nextElement = 
xmlSchemaCollection.getElementByQName(element.getRefName());
+            XmlSchemaElement nextElement = 
findElementByRefName(element.getRefName(), 
+                                                                
containingType.getQName().getNamespaceURI());
             assert nextElement != null;
             element = nextElement;
         }
@@ -426,7 +449,17 @@
             
             // now for the thing itself.
             if (elType instanceof XmlSchemaComplexType) {
-                utils.appendExpression(elementName + ".serialize(cxfjsutils, 
'" + elementXmlRef + "')");
+                if (elChild.getMinOccurs() != 0) { // required
+                    utils.startIf(elementName + " == null");
+                    utils.appendString("<" + elementXmlRef + " " + 
NIL_ATTRIBUTES + "/>");
+                    utils.appendElse();
+                    utils.appendExpression(elementName + 
".serialize(cxfjsutils, '" + elementXmlRef + "')");
+                    utils.endBlock();
+                } else {
+                    utils.startIf(elementName + " != null");
+                    utils.appendExpression(elementName + 
".serialize(cxfjsutils, '" + elementXmlRef + "')");
+                    utils.endBlock();
+                }
             } else {
                 QName typeName = elType.getQName();
                 utils.appendString("<" + elementXmlRef + ">");

Modified: 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=591082&r1=591081&r2=591082&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
 (original)
+++ 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
 Thu Nov  1 09:51:12 2007
@@ -105,7 +105,7 @@
     }
     
     public void readStringIntoRhino(String js, String sourceName) {
-        LOG.info(sourceName + ":\n" + js);
+        LOG.fine(sourceName + ":\n" + js);
         rhinoContext.evaluateString(rhinoScope, js, sourceName, 1, null);
     }
     

Modified: 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java?rev=591082&r1=591081&r2=591082&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
 (original)
+++ 
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
 Thu Nov  1 09:51:12 2007
@@ -46,7 +46,6 @@
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mozilla.javascript.RhinoException;
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;


Reply via email to