cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r589472 - in /incubator/cxf/trunk: rt/core/src/main/java/org/apache/cxf/databinding/source/mime/ rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ tools/javato/ws/sr...
Date Mon, 29 Oct 2007 02:38:01 GMT
Author: mmao
Date: Sun Oct 28 19:37:58 2007
New Revision: 589472

URL: http://svn.apache.org/viewvc?rev=589472&view=rev
Log:
CXF-1114 
  XmlMimeType support in the SEI 


Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/CustomExtensionRegistry.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeAttribute.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeSerializer.java
Modified:
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ImageSender.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/expected_send_image.wsdl

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/CustomExtensionRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/CustomExtensionRegistry.java?rev=589472&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/CustomExtensionRegistry.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/CustomExtensionRegistry.java
Sun Oct 28 19:37:58 2007
@@ -0,0 +1,28 @@
+/**
+ * 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.databinding.source.mime;
+
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+
+public class CustomExtensionRegistry extends ExtensionRegistry {
+    public CustomExtensionRegistry() {
+        registerSerializer(MimeAttribute.class, new MimeSerializer());
+    }
+}

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeAttribute.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeAttribute.java?rev=589472&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeAttribute.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeAttribute.java
Sun Oct 28 19:37:58 2007
@@ -0,0 +1,37 @@
+/**
+ * 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.databinding.source.mime;
+
+import javax.xml.namespace.QName;
+
+public final class MimeAttribute {
+    public static final QName MIME_QNAME = new QName("http://www.w3.org/2005/05/xmlmime",

+                                                     "expectedContentTypes");
+
+    private String value;
+    
+    public void setValue(String v) {
+        this.value = v;
+    }
+    
+    public String getValue() {
+        return this.value;
+    }
+
+}

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeSerializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeSerializer.java?rev=589472&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeSerializer.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/mime/MimeSerializer.java
Sun Oct 28 19:37:58 2007
@@ -0,0 +1,44 @@
+/**
+ * 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.databinding.source.mime;
+
+import java.util.Map;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
+
+public class MimeSerializer implements ExtensionSerializer {
+    
+    public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode)
{
+        Map metaInfoMap = schemaObject.getMetaInfoMap();
+        MimeAttribute mimeType = (MimeAttribute)metaInfoMap.get(MimeAttribute.MIME_QNAME);
+
+        Element elt = (Element)domNode;
+        Attr att1 = elt.getOwnerDocument().createAttributeNS(MimeAttribute.MIME_QNAME.getNamespaceURI(),
+                                                             MimeAttribute.MIME_QNAME.getLocalPart());
+        att1.setValue(mimeType.getValue());
+        elt.setAttributeNodeNS(att1);
+    }
+
+}

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=589472&r1=589471&r2=589472&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Sun Oct 28 19:37:58 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.service.factory;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
@@ -39,6 +40,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.xml.bind.annotation.XmlMimeType;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Holder;
 
@@ -46,6 +48,8 @@
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.databinding.source.mime.MimeAttribute;
+import org.apache.cxf.databinding.source.mime.MimeSerializer;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.EndpointImpl;
@@ -104,6 +108,8 @@
     public static final String HEADER = "messagepart.isheader";
     public static final String ELEMENT_NAME = "messagepart.elementName";
     public static final String METHOD = "operation.method";
+    public static final String METHOD_PARAM_ANNOTATIONS = "method.parameters.annotations";
+    public static final String METHOD_ANNOTATONS = "method.return.annotations";
 
     private static final Logger LOG = LogUtils.getL7dLogger(ReflectionServiceFactoryBean.class,
                                                             "SimpleMessages");
@@ -141,6 +147,9 @@
 
     @Override
     public Service create() {
+//        System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+//                           CustomExtensionRegistry.class.getName());
+
         initializeServiceConfigurations();
 
         initializeServiceModel();
@@ -674,6 +683,7 @@
                                             AbstractMessageContainer unwrappedMessage,
                                             XmlSchema schema,
                                             QName wrapperName) {
+        
         XmlSchemaElement el = new XmlSchemaElement();
         el.setQName(wrapperName);
         el.setName(wrapperName.getLocalPart());
@@ -691,7 +701,6 @@
         ct.setParticle(seq);
 
         for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
-
             el = new XmlSchemaElement();
             el.setName(mpi.getName().getLocalPart());
             el.setQName(mpi.getName());
@@ -707,6 +716,16 @@
                 if (!mpi.isElement()) {
                     mpi.setXmlSchema(el);                    
                 }
+                Annotation[] parameterAnnotation = getMethodParameterAnnotations(mpi);
+                if (parameterAnnotation != null) {
+                    addMimeType(el, parameterAnnotation);
+                }
+                
+                Annotation[] methodAnnotations = getMethodAnnotations(mpi);
+                if (methodAnnotations != null) {
+                    addMimeType(el, methodAnnotations);
+                }                
+                                
                 if (mpi.getTypeClass() != null && mpi.getTypeClass().isArray()
                     && !Byte.TYPE.equals(mpi.getTypeClass().getComponentType()))
{
                     String min = (String)mpi.getProperty("minOccurs");
@@ -757,6 +776,29 @@
         }
 
     }
+    
+    private Annotation[] getMethodParameterAnnotations(final MessagePartInfo mpi) {
+        Annotation[][] paramAnno = (Annotation[][])mpi.getProperty(METHOD_PARAM_ANNOTATIONS);
+        int index = mpi.getIndex();
+        if (paramAnno != null && index < paramAnno.length && index >=
0) {
+            return paramAnno[index];
+        }
+        return null;
+    }
+    
+    private Annotation[] getMethodAnnotations(final MessagePartInfo mpi) {
+        return (Annotation[])mpi.getProperty(METHOD_ANNOTATONS);        
+    }    
+    
+    private void addMimeType(final XmlSchemaElement element, final Annotation[] annotations)
{
+        for (Annotation annotation : annotations) {
+            if (annotation instanceof XmlMimeType) {
+                MimeAttribute attr = new MimeAttribute();
+                attr.setValue(((XmlMimeType)annotation).value());
+                element.addMetaInfo(MimeAttribute.MIME_QNAME, attr);
+            }
+        }         
+    }
 
     private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo,
                                          String namespaceURI, 
@@ -769,6 +811,7 @@
 
         SchemaInfo schemaInfo = new SchemaInfo(serviceInfo, namespaceURI);
         XmlSchemaCollection col = new XmlSchemaCollection();
+        col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
         XmlSchema schema = new XmlSchema(namespaceURI, col);
         if (qualified) {
             schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
@@ -808,7 +851,7 @@
                 final QName q2 = getInPartName(op, method, j);
                 MessagePartInfo part = inMsg.addMessagePart(q2);
                 initializeParameter(part, paramClasses[j], method.getGenericParameterTypes()[j]);
-
+                part.setProperty(METHOD_PARAM_ANNOTATIONS, method.getParameterAnnotations());
               
                 if (!isWrapped(method) && !isRPC(method)) {
                     part.setProperty(ELEMENT_NAME, q);
                 }
@@ -838,7 +881,7 @@
                 if (!isRPC(method) && !isWrapped(method)) {
                     part.setProperty(ELEMENT_NAME, q2);
                 }
-
+                part.setProperty(METHOD_ANNOTATONS, method.getAnnotations());
                 if (isHeader(method, -1)) {
                     part.setProperty(HEADER, Boolean.TRUE);
                     if (isRPC(method) || !isWrapped(method)) {
@@ -982,7 +1025,6 @@
             ParameterizedType paramType = (ParameterizedType)type;
             rawClass = getHolderClass(paramType);
         }
-
         part.setProperty(GENERIC_TYPE, type);
         part.setTypeClass(rawClass);
     }

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ImageSender.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ImageSender.java?rev=589472&r1=589471&r2=589472&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ImageSender.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/ImageSender.java
Sun Oct 28 19:37:58 2007
@@ -27,6 +27,11 @@
     public void sendImage(@XmlMimeType("image/png") Image photo) {
         // empty
     }
+
+    @XmlMimeType("image/png")
+    public Image getImage(String key) {
+        return null;
+    }
 }
 
 

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/expected_send_image.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/expected_send_image.wsdl?rev=589472&r1=589471&r2=589472&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/expected_send_image.wsdl
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/expected_send_image.wsdl
Sun Oct 28 19:37:58 2007
@@ -20,10 +20,22 @@
 <wsdl:definitions name="ImageSenderService" targetNamespace="http://fortest.tools.cxf.apache.org/"
xmlns:tns="http://fortest.tools.cxf.apache.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
   <wsdl:types>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://fortest.tools.cxf.apache.org/"
attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://fortest.tools.cxf.apache.org/">
+    <xsd:element name="getImage" type="tns:getImage"/>
+    <xsd:complexType name="getImage">
+        <xsd:sequence>
+            <xsd:element minOccurs="0" name="arg0" type="xsd:string"/>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:element name="getImageResponse" type="tns:getImageResponse"/>
+    <xsd:complexType name="getImageResponse">
+        <xsd:sequence>
+            <xsd:element xmlns:ns0="http://www.w3.org/2005/05/xmlmime" minOccurs="0" name="return"
ns0:expectedContentTypes="image/png" type="xsd:base64Binary"/>
+        </xsd:sequence>
+    </xsd:complexType>
     <xsd:element name="sendImage" type="tns:sendImage"/>
     <xsd:complexType name="sendImage">
         <xsd:sequence>
-            <xsd:element minOccurs="0" name="arg0" type="xsd:base64Binary"/>
+	    <xsd:element xmlns:ns0="http://www.w3.org/2005/05/xmlmime" minOccurs="0" name="arg0"
ns0:expectedContentTypes="image/png" type="xsd:base64Binary"/>
         </xsd:sequence>
     </xsd:complexType>
     <xsd:element name="sendImageResponse" type="tns:sendImageResponse"/>



Mime
View raw message