You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2008/01/19 04:00:09 UTC

svn commit: r613348 - in /incubator/cxf/trunk/rt/javascript/src: main/java/org/apache/cxf/javascript/ main/java/org/apache/cxf/javascript/service/ main/java/org/apache/cxf/javascript/types/ test/java/org/apache/cxf/javascript/ test/java/org/apache/cxf/...

Author: bimargulies
Date: Fri Jan 18 19:00:06 2008
New Revision: 613348

URL: http://svn.apache.org/viewvc?rev=613348&view=rev
Log:
Make Javascript generator recognize xmime:contentType as a clue that MTOM is 
desired.

Added:
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java   (with props)
Modified:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.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/MtoMTest.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanNoDataHandler.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanWithDataHandler.java

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java?rev=613348&r1=613347&r2=613348&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java Fri Jan 18 19:00:06 2008
@@ -29,11 +29,14 @@
 
 import org.w3c.dom.Attr;
 
+import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.databinding.source.mime.MimeAttribute;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.ws.commons.schema.constants.Constants;
@@ -218,9 +221,15 @@
         return token;
     }
     
-    private String getMtomContentTypes(XmlSchemaObject schemaObject) {
+    /**
+     * We really don't want to take the attitude that 'all base64Binary elements are candidates for MTOM'.
+     * So we look for clues.
+     * @param schemaObject
+     * @return
+     */
+    private boolean treatAsMtom(XmlSchemaObject schemaObject) {
         if (schemaObject == null) {
-            return null;
+            return false;
         }
         
         Map metaInfoMap = schemaObject.getMetaInfoMap();
@@ -228,10 +237,38 @@
             Map attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
             Attr ctAttr = (Attr)attribMap.get(MimeAttribute.MIME_QNAME);
             if (ctAttr != null) {
-                return ctAttr.getValue();
+                return true;
+            }
+        }
+        
+        if (schemaObject instanceof XmlSchemaElement) {
+            XmlSchemaElement element = (XmlSchemaElement) schemaObject;
+            if (element.getSchemaType() == null) {
+                return false;
+            }
+            QName typeName = element.getSchemaType().getQName();
+            // We could do something much more complex in terms of evaluating whether the type
+            // permits the contentType attribute. This, however, is enough to clue us in for what Aegis
+            // does.
+            if (AbstractXOPType.XML_MIME_BASE64.equals(typeName)) {
+                return true;
             }
+            
         }
-        return null;
+        
+        return false;
+    }
+    
+    /**
+     * We don't want to generate Javascript overhead for complex types with simple content models,
+     * at least until or unless we decide to cope with attributes in a general way.
+     * @param type
+     * @return
+     */
+    public static boolean notVeryComplexType(XmlSchemaType type) {
+        return type instanceof XmlSchemaSimpleType 
+               || (type instanceof XmlSchemaComplexType 
+                   && ((XmlSchemaComplexType)type).getContentModel() instanceof XmlSchemaSimpleContent);
     }
 
     /**
@@ -249,7 +286,7 @@
         boolean nillable = elementInfo.isNillable();
         boolean optional = elementInfo.isOptional();
         boolean array = elementInfo.isArray();
-        String mtomContentTypes = getMtomContentTypes(elementInfo.getParticle());
+        boolean mtom = treatAsMtom(elementInfo.getParticle());
         String jsVar = referencePrefix + elementInfo.getJavascriptName();
         appendLine("// block for local variables");
         startBlock(); // allow local variables.
@@ -286,7 +323,9 @@
         
         if (elementInfo.isAnyType()) {
             serializeAnyTypeElement(elementInfo, jsVar);
-        } else if (type instanceof XmlSchemaComplexType) {
+            // mtom can be turned on for the special complex type that is really a basic type with 
+            // a content-type attribute.
+        } else if (!mtom && type instanceof XmlSchemaComplexType) {
             // it has a value
             // pass the extra null in the slot for the 'extra namespaces' needed
             // by 'any'.
@@ -295,7 +334,7 @@
                              + elementInfo.getXmlName() + "', null)");
         } else { // simple type
             appendString("<" + elementInfo.getXmlName() + ">");
-            if (mtomContentTypes != null) {
+            if (mtom) {
                 appendExpression("cxfjsutils.packageMtom(" + jsVar + ")");
             } else {
                 appendExpression("cxfjsutils.escapeXmlEntities(" + jsVar + ")");

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=613348&r1=613347&r2=613348&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java Fri Jan 18 19:00:06 2008
@@ -167,7 +167,7 @@
                 XmlSchemaElement element = (XmlSchemaElement) globalElements.getItem(name);
                 // For now, at least, don't handle elements with simple types.
                 // That comes later to improve deserialization.
-                if (!(element.getSchemaType() instanceof XmlSchemaComplexType)) {
+                if (JavascriptUtils.notVeryComplexType(element.getSchemaType())) {
                     continue;
                 }
                 // If the element uses a named type, we use the functions for the type.
@@ -189,7 +189,7 @@
                 QName name = (QName)namesIterator.next();
                 XmlSchemaType type = (XmlSchemaType) globalElements.getItem(name);
                 // For now, at least, don't handle simple types.
-                if (!(type instanceof XmlSchemaComplexType)) {
+                if (JavascriptUtils.notVeryComplexType(type)) {
                     continue;
                 }
                 // the names are misleading, but that's OK.

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=613348&r1=613347&r2=613348&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 Jan 18 19:00:06 2008
@@ -65,8 +65,7 @@
 
     // In general, I (bimargulies) hate fields that are temporary communications
     // between members of a class. However, given the style restrictions on the
-    // number
-    // of parameters, it's the least of the evils.
+    // number of parameters, it's the least of the evils.
     private StringBuilder code;
     private StringBuilder accessors;
     private JavascriptUtils utils;
@@ -96,7 +95,8 @@
             if (xmlSchemaObject instanceof XmlSchemaComplexType) {
                 try {
                     XmlSchemaComplexType complexType = (XmlSchemaComplexType)xmlSchemaObject;
-                    if (complexType.getName() != null) {
+                    if (!JavascriptUtils.notVeryComplexType(complexType)
+                        && complexType.getName() != null) {
                         complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
                         complexTypeSerializerFunction(complexType.getQName(), complexType);
                         domDeserializerFunction(complexType.getQName(), complexType);
@@ -153,7 +153,8 @@
                     XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
                     // for named types we don't bother to generate for the
                     // element.
-                    if (complexType.getName() == null) {
+                    if (!JavascriptUtils.notVeryComplexType(complexType)
+                        && complexType.getName() == null) {
                         complexTypeConstructorAndAccessors(element.getQName(), complexType);
                         complexTypeSerializerFunction(element.getQName(), complexType);
                         domDeserializerFunction(element.getQName(), complexType);
@@ -555,7 +556,8 @@
                                                           prefixAccumulator, 
                                                           type.getQName());
         XmlSchemaType itemType = itemInfo.getType();
-        boolean simple = itemType instanceof XmlSchemaSimpleType;
+        boolean simple = itemType instanceof XmlSchemaSimpleType
+            || JavascriptUtils.notVeryComplexType(itemType);
         String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
         utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
         XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java?rev=613348&r1=613347&r2=613348&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java Fri Jan 18 19:00:06 2008
@@ -88,7 +88,7 @@
 
     @org.junit.Ignore
     @Test
-    public void jaxwsClientExperimentExpectAutoBase64() {
+    public void jaxwsClientExperimentExpectAutoBase64() throws Exception {
         MtoM client = getBean(MtoM.class, "mtom-client");
         assertNotNull(client);
         MtoMParameterBeanNoDataHandler param = new MtoMParameterBeanNoDataHandler();

Added: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java?rev=613348&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java (added)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java Fri Jan 18 19:00:06 2008
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.javascript.fortest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ * This class is here to make JAXB happy. We will in fact use a DataHandler along 
+ * with this schema type.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(namespace = "http://www.w3.org/2005/05/xmlmime", 
+         name = "base64Binary", propOrder = {
+                                             "byteValue"
+                                             })
+public class Base64Binary {
+
+    @XmlValue
+    protected byte[] byteValue;
+    @XmlAttribute(namespace = "http://www.w3.org/2005/05/xmlmime")
+    protected String contentType;
+
+    /**
+     * Gets the value of the value property.
+     * 
+     * @return
+     *     possible object is
+     *     byte[]
+     */
+    public byte[] getValue() {
+        return byteValue;
+    }
+
+    /**
+     * Sets the value of the value property.
+     * 
+     * @param value
+     *     allowed object is
+     *     byte[]
+     */
+    public void setValue(byte[] newValue) {
+        this.byteValue = newValue;
+    }
+
+    /**
+     * Gets the value of the contentType property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getContentType() {
+        return contentType;
+    }
+
+    /**
+     * Sets the value of the contentType property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setContentType(String value) {
+        this.contentType = value;
+    }
+}

Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/Base64Binary.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanNoDataHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanNoDataHandler.java?rev=613348&r1=613347&r2=613348&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanNoDataHandler.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanNoDataHandler.java Fri Jan 18 19:00:06 2008
@@ -19,13 +19,17 @@
 
 package org.apache.cxf.javascript.fortest;
 
+import java.io.UnsupportedEncodingException;
+
 import javax.xml.bind.annotation.XmlMimeType;
 import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlType;
 
 /**
  * 
  */
+@XmlSeeAlso(Base64Binary.class)
 @XmlType(namespace = "uri:org.apache.cxf.javascript.testns")
 public class MtoMParameterBeanNoDataHandler {
     private String ordinary;
@@ -38,11 +42,12 @@
         this.ordinary = ordinary;
     }
     
-    @XmlMimeType("text/plain")
-    @XmlSchemaType(name = "base64Binary")
-    public String getNotXml10() {
-        return notXml10;
+    @XmlMimeType("text/plain;charset=utf-8")
+    @XmlSchemaType(namespace = "http://www.w3.org/2005/05/xmlmime", name = "base64Binary")
+    public byte[] getNotXml10() throws UnsupportedEncodingException {
+        return notXml10.getBytes("utf-8");
     }
+    
     public void setNotXml10(String notXml10) {
         this.notXml10 = notXml10;
     }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanWithDataHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanWithDataHandler.java?rev=613348&r1=613347&r2=613348&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanWithDataHandler.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/MtoMParameterBeanWithDataHandler.java Fri Jan 18 19:00:06 2008
@@ -22,11 +22,13 @@
 import javax.activation.DataHandler;
 import javax.xml.bind.annotation.XmlMimeType;
 import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlType;
 
 /**
  * 
  */
+@XmlSeeAlso(Base64Binary.class)
 @XmlType(namespace = "uri:org.apache.cxf.javascript.testns")
 public class MtoMParameterBeanWithDataHandler {
     private String ordinary;
@@ -39,8 +41,8 @@
         this.ordinary = ordinary;
     }
     
-    @XmlMimeType("text/plain")
-    @XmlSchemaType(name = "base64Binary")
+    @XmlMimeType("text/plain;charset=utf-8")
+    @XmlSchemaType(namespace = "http://www.w3.org/2005/05/xmlmime", name = "base64Binary")
     public DataHandler getNotXml10() {
         return notXml10;
     }
@@ -48,3 +50,4 @@
         this.notXml10 = notXml10;
     }
 }
+