cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r731383 - in /cxf/sandbox/benson/aegis_xmlschema: common/common/src/main/java/org/apache/cxf/common/xmlschema/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ rt/...
Date Sun, 04 Jan 2009 23:03:58 GMT
Author: bimargulies
Date: Sun Jan  4 15:03:57 2009
New Revision: 731383

URL: http://svn.apache.org/viewvc?rev=731383&view=rev
Log:
Apparently finish the first pass of this by fixing the management of the outboard schemas.

Added:
    cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
  (with props)
Modified:
    cxf/sandbox/benson/aegis_xmlschema/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
    cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
    cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
    cxf/sandbox/benson/aegis_xmlschema/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java

Modified: cxf/sandbox/benson/aegis_xmlschema/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/benson/aegis_xmlschema/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java?rev=731383&r1=731382&r2=731383&view=diff
==============================================================================
--- cxf/sandbox/benson/aegis_xmlschema/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
(original)
+++ cxf/sandbox/benson/aegis_xmlschema/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
Sun Jan  4 15:03:57 2009
@@ -179,6 +179,11 @@
      * @param namespaceUri
      */
     public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) {
+        // no need to import nothing or the XSD schema.
+        if ("".equals(namespaceUri) || XmlSchemaConstants.XSD_NAMESPACE_URI.equals(namespaceUri))
{
+            return;
+        }
+            
         XmlSchemaObjectCollection inc = schema.getIncludes();
         for (int x = 0; x < inc.getCount(); x++) {
             XmlSchemaObject what = inc.getItem(x);
@@ -193,5 +198,6 @@
         XmlSchemaImport imp = new XmlSchemaImport();
         imp.setNamespace(namespaceUri);
         inc.add(imp);
+        schema.getItems().add(imp);
     }
 }

Modified: cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java?rev=731383&r1=731382&r2=731383&view=diff
==============================================================================
--- cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
(original)
+++ cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
Sun Jan  4 15:03:57 2009
@@ -18,16 +18,20 @@
  */
 package org.apache.cxf.aegis;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.xml.sax.InputSource;
+import org.w3c.dom.Document;
+
+import org.xml.sax.SAXException;
 
 import org.apache.cxf.aegis.type.AbstractTypeCreator;
 import org.apache.cxf.aegis.type.DefaultTypeCreator;
@@ -43,6 +47,7 @@
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.common.xmlschema.XmlSchemaTools;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 
@@ -68,9 +73,11 @@
 public class AegisContext {
 
     /**
-     * Namespace used for miscellaneous Aegis types.
+     * Namespace used for the miscellaneous Aegis type schema.
      */
-    public static final String SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
+    public static final String UTILITY_TYPES_SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
+    private Document aegisTypesSchemaDocument;
+    private Document xmimeSchemaDocument;
 
     private boolean writeXsiTypes;
     private boolean readXsiTypes = true;
@@ -232,17 +239,46 @@
     }
 
     public static boolean schemaImportsUtilityTypes(XmlSchema schema) {
-        return XmlSchemaTools.schemaImportsNamespace(schema, SCHEMA_NS);
+        return XmlSchemaTools.schemaImportsNamespace(schema, UTILITY_TYPES_SCHEMA_NS);
+    }
+    
+    private Document getSchemaDocument(String resourcePath) { 
+        try {
+            return XMLUtils.parse(getClass().getResourceAsStream(resourcePath));
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    // could we make these documents static? What would we synchronize on?
+    private Document getAegisTypesSchemaDocument() { 
+        if (aegisTypesSchemaDocument == null) {
+            aegisTypesSchemaDocument = getSchemaDocument("/META-INF/cxf/aegisTypes.xsd");
+        } 
+        return aegisTypesSchemaDocument;
+    }
+    
+    private Document getXmimeSchemaDocument() {
+        if (xmimeSchemaDocument == null) {
+            xmimeSchemaDocument = getSchemaDocument("/schemas/wsdl/xmime.xsd");
+        }
+        return xmimeSchemaDocument;
     }
 
-    public void addTypesSchemaDocument(XmlSchemaCollection collection) {
-        collection.read(new 
-                        InputSource(getClass().getResourceAsStream("/META-INF/cxf/aegisTypes.xsd")),
-                        null);
+    public XmlSchema addTypesSchemaDocument(XmlSchemaCollection collection) {
+        return collection.read(getAegisTypesSchemaDocument(), null);
+    }
+    
+    public XmlSchema addXmimeSchemaDocument(XmlSchemaCollection collection) {
+        return collection.read(getXmimeSchemaDocument(), null);
     }
 
     public static void addUtilityTypesToSchema(XmlSchema root) {
-        XmlSchemaTools.addImportIfNeeded(root, SCHEMA_NS);
+        XmlSchemaTools.addImportIfNeeded(root, UTILITY_TYPES_SCHEMA_NS);
     }
 
     /**

Modified: cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=731383&r1=731382&r2=731383&view=diff
==============================================================================
--- cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
(original)
+++ cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
Sun Jan  4 15:03:57 2009
@@ -33,11 +33,9 @@
 
 import org.w3c.dom.Node;
 
-import org.xml.sax.InputSource;
-
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.DatabindingException;
-import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
+import org.apache.cxf.aegis.type.AbstractTypeCreator;
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeCreationOptions;
 import org.apache.cxf.aegis.type.TypeCreator;
@@ -65,7 +63,6 @@
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotated;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 
@@ -117,11 +114,6 @@
         part2Type = new HashMap<MessagePartInfo, Type>();
     }
 
-    private void addXmimeSchema(XmlSchemaCollection collection) {
-        collection.read(new 
-                        InputSource(getClass().getResourceAsStream("/schemas/wsdl/xmime.xsd")),
null);
-    }
-
     /**
      * The Databinding API has initialize(Service). However, this object should
      * be usable even if that API is never called.
@@ -428,17 +420,29 @@
             }
         }
 
-        boolean needXmimeSchema = false;
-        boolean needTypesSchema = false;
         Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
 
-        
         for (ServiceInfo si : s.getServiceInfos()) {
+            // these two must be recalculated per-service-info!
+            boolean needXmimeSchema = false;
+            boolean needTypesSchema = false;
+
             for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
+                
                 String schemaNamespaceUri = entry.getKey();
+                
                 if (XmlSchemaConstants.XSD_NAMESPACE_URI.equals(schemaNamespaceUri)) {
                     continue;
                 }
+                
+                if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schemaNamespaceUri)) {
+                    continue; // we handle this separately.
+                }
+                
+                if (AbstractXOPType.XML_MIME_NS.equals(schemaNamespaceUri)) {
+                    continue; // similiarly.
+                }
+                
                 SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
                 XmlSchema schema = schemaInfo.getSchema(); 
                 NamespaceMap xmlsNamespaceMap = new NamespaceMap();
@@ -479,15 +483,22 @@
                 if (AegisContext.schemaImportsUtilityTypes(schema)) {
                     needTypesSchema = true;
                 }
-
             }
 
             if (needXmimeSchema) {
-                addXmimeSchema(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                XmlSchema schema = 
+                    aegisContext.addXmimeSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
+                schemaInfo.setSchema(schema);
+                si.addSchema(schemaInfo);
             }
             
             if (needTypesSchema) {
-                aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                XmlSchema schema = 
+                    aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
+                schemaInfo.setSchema(schema);
+                si.addSchema(schemaInfo);
             }
         }
         
@@ -536,7 +547,7 @@
             OperationInfo op = param.getMessageInfo().getOperation();
 
             Method m = getMethod(s, op);
-            TypeClassInfo info;
+            AbstractTypeCreator.TypeClassInfo info;
             if (paramtype != FAULT_PARAM && m != null) {
                 info = typeCreator.createClassInfo(m, param.getIndex() - offset);
             } else {

Added: cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java?rev=731383&view=auto
==============================================================================
--- cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
(added)
+++ cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
Sun Jan  4 15:03:57 2009
@@ -0,0 +1,66 @@
+/**
+ * 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.aegis.standalone;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.aegis.AegisContext;
+import org.apache.cxf.test.TestUtilities;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSerializer;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SchemaAddinsTest extends Assert {
+    private TestUtilities testUtilities;
+    
+    @Before
+    public void before() {
+        testUtilities = new TestUtilities(getClass());
+        testUtilities.addDefaultNamespaces();
+    }
+    
+    @Test
+    public void testAegisTypeSchema() throws Exception {
+        AegisContext context = new AegisContext();
+        context.initialize();
+        XmlSchemaCollection collection = new XmlSchemaCollection();
+        context.addTypesSchemaDocument(collection);
+        XmlSchema[] schemas = collection.getXmlSchemas();
+        XmlSchema typeSchema = null;
+        for (XmlSchema schema : schemas) {
+            if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schema.getTargetNamespace()))
{
+                typeSchema = schema;
+                break;
+            }
+        }
+        assertNotNull(typeSchema);
+        
+        assertNotSame(0, typeSchema.getItems().getCount());
+        XmlSchemaSerializer serializer = new XmlSchemaSerializer();
+        Document[] docs = serializer.serializeSchema(typeSchema, false);
+        testUtilities.assertValid("/xsd:schema/xsd:simpleType[@name='char']", docs[0]);
+        
+        
+        
+    }
+}

Propchange: cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/benson/aegis_xmlschema/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/sandbox/benson/aegis_xmlschema/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/benson/aegis_xmlschema/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java?rev=731383&r1=731382&r2=731383&view=diff
==============================================================================
--- cxf/sandbox/benson/aegis_xmlschema/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java
(original)
+++ cxf/sandbox/benson/aegis_xmlschema/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.java
Sun Jan  4 15:03:57 2009
@@ -47,7 +47,7 @@
     
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(AegisServer.class));
+        assertTrue("server did not launch correctly", launchServer(AegisServer.class, true));
     }
     
     @Test



Mime
View raw message