Author: veithen
Date: Wed Dec  5 12:20:00 2012
New Revision: 1417378

URL: http://svn.apache.org/viewvc?rev=1417378&view=rev
Log:
Added support for javax.xml.namespace.QName to EMF.

Added:
    
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/
    
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLHelper.java
    
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLResource.java
Modified:
    
axis/axis1/java/branches/EMF/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
    axis/axis1/java/branches/EMF/axis-model/pom.xml
    
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/wsdd/WSDDUtil.java

Modified: 
axis/axis1/java/branches/EMF/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/branches/EMF/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaDeployWriter.java?rev=1417378&r1=1417377&r2=1417378&view=diff
==============================================================================
--- 
axis/axis1/java/branches/EMF/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
 (original)
+++ 
axis/axis1/java/branches/EMF/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
 Wed Dec  5 12:20:00 2012
@@ -207,8 +207,8 @@ public class JavaDeployWriter extends Ja
             QName bQName = binding.getQName();
 
             TypeMapping typeMapping = 
WSDDFactory.eINSTANCE.createTypeMapping();
-            typeMapping.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(bQName.getNamespaceURI(), 
"DataHandler", "ns"));
-            typeMapping.setType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(WSDDConstants.URI_WSDD_JAVA,
 "javax.activation.DataHandler", WSDDConstants.NS_PREFIX_WSDD_JAVA));
+            typeMapping.setQname(new QName(bQName.getNamespaceURI(), 
"DataHandler"));
+            typeMapping.setType(new QName(WSDDConstants.URI_WSDD_JAVA, 
"javax.activation.DataHandler", WSDDConstants.NS_PREFIX_WSDD_JAVA));
             
typeMapping.setSerializer("org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory");
             
typeMapping.setDeserializer("org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory");
             typeMapping.setEncodingStyle(use.getEncoding());
@@ -281,8 +281,8 @@ public class JavaDeployWriter extends Ja
                 if (innerType == null) {
                     // no arrays
                     TypeMapping typeMapping = 
WSDDFactory.eINSTANCE.createTypeMapping();
-                    typeMapping.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(namespaceURI, localPart, 
"ns"));
-                    typeMapping.setType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(WSDDConstants.URI_WSDD_JAVA,
 javaType, WSDDConstants.NS_PREFIX_WSDD_JAVA));
+                    typeMapping.setQname(new QName(namespaceURI, localPart));
+                    typeMapping.setType(new QName(WSDDConstants.URI_WSDD_JAVA, 
javaType));
                     typeMapping.setSerializer(serializerFactory);
                     typeMapping.setDeserializer(deserializerFactory);
                     typeMapping.setEncodingStyle(encodingStyle);
@@ -290,10 +290,10 @@ public class JavaDeployWriter extends Ja
                 } else {
                     // arrays
                     ArrayMapping arrayMapping = 
WSDDFactory.eINSTANCE.createArrayMapping();
-                    arrayMapping.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(namespaceURI, localPart, 
"ns"));
-                    arrayMapping.setType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(WSDDConstants.URI_WSDD_JAVA,
 javaType, WSDDConstants.NS_PREFIX_WSDD_JAVA));
+                    arrayMapping.setQname(new QName(namespaceURI, localPart));
+                    arrayMapping.setType(new 
QName(WSDDConstants.URI_WSDD_JAVA, javaType));
                     arrayMapping.setEncodingStyle(encodingStyle);
-                    arrayMapping.setInnerType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(innerType.getNamespaceURI(),
 innerType.getLocalPart(), "cmp-ns"));
+                    arrayMapping.setInnerType(innerType);
                     service.getArrayMappings().add(arrayMapping);
                 }
             }
@@ -341,7 +341,7 @@ public class JavaDeployWriter extends Ja
 
         org.apache.axis.model.wsdd.Service wsddService = 
WSDDFactory.eINSTANCE.createService();
         wsddService.setName(serviceName);
-        wsddService.setProvider(new 
org.apache.axis.model.ecore.xml.type.internal.QName(WSDDConstants.URI_WSDD_JAVA,
 "RPC", WSDDConstants.NS_PREFIX_WSDD_JAVA));
+        wsddService.setProvider(new QName(WSDDConstants.URI_WSDD_JAVA, "RPC"));
         
wsddService.setStyle(org.apache.axis.model.wsdd.Style.getByName(style.getName()));
         
wsddService.setUse(org.apache.axis.model.wsdd.Use.getByName(use.getName()));
         wsddService.setParameter("wsdlTargetNamespace", 
service.getQName().getNamespaceURI());
@@ -520,15 +520,15 @@ public class JavaDeployWriter extends Ja
         operation.setName(javaOperName);
 
         if (elementQName != null) {
-            operation.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(elementQName.getNamespaceURI(),
 elementQName.getLocalPart(), "operNS"));
+            operation.setQname(elementQName);
         }
 
         if (returnQName != null) {
-            operation.setReturnQName(new 
org.apache.axis.model.ecore.xml.type.internal.QName(returnQName.getNamespaceURI(),
 Utils.getLastLocalPart(returnQName.getLocalPart()), "retNS"));
+            operation.setReturnQName(new QName(returnQName.getNamespaceURI(), 
Utils.getLastLocalPart(returnQName.getLocalPart())));
         }
 
         if (returnType != null) {
-            operation.setReturnQName(new 
org.apache.axis.model.ecore.xml.type.internal.QName(returnType.getNamespaceURI(),
 returnType.getLocalPart(), "rtns"));
+            operation.setReturnQName(returnType);
         }
 
         Parameter retParam = params.returnParam;
@@ -536,11 +536,11 @@ public class JavaDeployWriter extends Ja
             TypeEntry type = retParam.getType();
             QName returnItemQName = Utils.getItemQName(type);
             if (returnItemQName != null) {
-                operation.setReturnItemQName(new 
org.apache.axis.model.ecore.xml.type.internal.QName(returnItemQName.getNamespaceURI(),
 returnItemQName.getLocalPart(), "tns"));
+                operation.setReturnItemQName(returnItemQName);
             }
             QName returnItemType = Utils.getItemType(type);
             if (returnItemType != null && use == Use.ENCODED) {
-                operation.setReturnItemType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(returnItemType.getNamespaceURI(),
 returnItemType.getLocalPart(), "tns2"));
+                operation.setReturnItemType(returnItemType);
             }
         }
 
@@ -573,10 +573,10 @@ public class JavaDeployWriter extends Ja
             if (paramQName == null) {
                 parameter.setName(param.getName());
             } else {
-                parameter.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(paramQName.getNamespaceURI(),
 Utils.getLastLocalPart(paramQName.getLocalPart()), "pns"));
+                parameter.setQname(new QName(paramQName.getNamespaceURI(), 
Utils.getLastLocalPart(paramQName.getLocalPart())));
             }
 
-            parameter.setType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(paramType.getNamespaceURI(),
 paramType.getLocalPart(), "tns"));
+            parameter.setType(paramType);
 
             // Get the parameter mode
             if (param.getMode() != Parameter.IN) {
@@ -594,7 +594,7 @@ public class JavaDeployWriter extends Ja
 
             QName itemQName = Utils.getItemQName(param.getType());
             if (itemQName != null) {
-                parameter.setItemQName(new 
org.apache.axis.model.ecore.xml.type.internal.QName(itemQName.getNamespaceURI(),
 itemQName.getLocalPart(), "itns"));
+                parameter.setItemQName(itemQName);
             }
 
             operation.getParameters().add(parameter);
@@ -612,10 +612,9 @@ public class JavaDeployWriter extends Ja
 
                     Fault fault = WSDDFactory.eINSTANCE.createFault();
                     fault.setName(faultInfo.getName());
-                    fault.setQname(new 
org.apache.axis.model.ecore.xml.type.internal.QName(faultQName.getNamespaceURI(),
 faultQName.getLocalPart(), "fns"));
+                    fault.setQname(faultQName);
                     fault.setClass(className);
-                    QName type = faultInfo.getXMLType();
-                    fault.setType(new 
org.apache.axis.model.ecore.xml.type.internal.QName(type.getNamespaceURI(), 
type.getLocalPart(), "tns"));
+                    fault.setType(faultInfo.getXMLType());
                     operation.getFaults().add(fault);
                 }
             }

Modified: axis/axis1/java/branches/EMF/axis-model/pom.xml
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/branches/EMF/axis-model/pom.xml?rev=1417378&r1=1417377&r2=1417378&view=diff
==============================================================================
--- axis/axis1/java/branches/EMF/axis-model/pom.xml (original)
+++ axis/axis1/java/branches/EMF/axis-model/pom.xml Wed Dec  5 12:20:00 2012
@@ -29,6 +29,12 @@
     <name>EMF Model for WSDD Files</name>
     <dependencies>
         <dependency>
+            <!-- This is just to get javax.xml.namespace.QName -->
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axis-jaxrpc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.eclipse.emf</groupId>
             <artifactId>common</artifactId>
             <version>2.2.3</version>

Added: 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLHelper.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLHelper.java?rev=1417378&view=auto
==============================================================================
--- 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLHelper.java
 (added)
+++ 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLHelper.java
 Wed Dec  5 12:20:00 2012
@@ -0,0 +1,65 @@
+/*
+ * 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.axis.model.util;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.xmi.XMLHelper;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl;
+
+/**
+ * Custom {@link XMLHelper} that adds support for {@link QName}. This is 
necessary because we use an
+ * EMF version compatible with Java 1.4 and that version doesn't support 
{@link QName} (because it's
+ * not included in the JRE). Instead it uses its own class to represent 
QNames. Since Axis depends
+ * on {@link QName} anyway, we add support for it here.
+ * 
+ * @author Andreas Veithen
+ */
+// TODO: this is actually not entirely correct; Axis may generate QNames that 
are not strictly valid (such as "ns:>fault") and they should be represented 
using a specific class
+public class AxisXMLHelper extends XMLHelperImpl {
+    public AxisXMLHelper(XMLResource resource) {
+        super(resource);
+    }
+
+    protected String updateQNamePrefix(EFactory factory, EDataType dataType, 
Object value, boolean list) {
+        if (!list && value instanceof QName) {
+            QName qname = (QName)value;
+            String namespace = qname.getNamespaceURI();
+            if (namespace.length() == 0) {
+                return qname.getLocalPart();
+            } else {
+                EPackage ePackage = extendedMetaData.getPackage(namespace);
+                if (ePackage == null) {
+                    ePackage = extendedMetaData.demandPackage(namespace);
+                }
+                String prefix = getPrefix(ePackage, true);
+                if (!packages.containsKey(ePackage)) {
+                    packages.put(ePackage, prefix);
+                }
+                return prefix + ":" + qname.getLocalPart();
+            }
+        } else {
+            return super.updateQNamePrefix(factory, dataType, value, list);
+        }
+    }
+}

Added: 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLResource.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLResource.java?rev=1417378&view=auto
==============================================================================
--- 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLResource.java
 (added)
+++ 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/util/AxisXMLResource.java
 Wed Dec  5 12:20:00 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.axis.model.util;
+
+import org.eclipse.emf.ecore.xmi.XMLHelper;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+
+/**
+ * {@link XMLHelper} implementation that uses {@link AxisXMLHelper}.
+ * 
+ * @author Andreas Veithen
+ */
+public class AxisXMLResource extends XMLResourceImpl {
+    protected XMLHelper createXMLHelper() {
+        return new AxisXMLHelper(this);
+    }
+}

Modified: 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/wsdd/WSDDUtil.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/wsdd/WSDDUtil.java?rev=1417378&r1=1417377&r2=1417378&view=diff
==============================================================================
--- 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/wsdd/WSDDUtil.java
 (original)
+++ 
axis/axis1/java/branches/EMF/axis-model/src/main/java/org/apache/axis/model/wsdd/WSDDUtil.java
 Wed Dec  5 12:20:00 2012
@@ -21,14 +21,14 @@ package org.apache.axis.model.wsdd;
 import java.io.IOException;
 import java.io.Writer;
 
-import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.apache.axis.model.util.AxisXMLResource;
 import org.eclipse.emf.ecore.xmi.util.XMLProcessor;
 
 public final class WSDDUtil {
     private WSDDUtil() {}
 
     public static void write(Deployment deployment, Writer writer) throws 
IOException {
-        XMLResourceImpl resource = new XMLResourceImpl();
+        AxisXMLResource resource = new AxisXMLResource();
         XMLProcessor processor = new XMLProcessor();
         resource.getContents().add(deployment);
         processor.save(writer, resource, null);        


Reply via email to