This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-xmlschema.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e56c44  XMLSCHEMA-58 - Schema version not set
6e56c44 is described below

commit 6e56c44c60b1ebaf44a6ea5267458b875405bfc8
Author: Colm O hEigeartaigh <cohei...@apache.org>
AuthorDate: Thu Jan 2 12:06:55 2020 +0000

    XMLSCHEMA-58 - Schema version not set
---
 .../apache/ws/commons/schema/SchemaBuilder.java    | 16 ++++----
 .../src/test/java/tests/VersionTest.java           | 45 ++++++++++++++++++++++
 xmlschema-core/src/test/resources/version.xsd      | 36 +++++++++++++++++
 3 files changed, 90 insertions(+), 7 deletions(-)

diff --git 
a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java 
b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
index 10af77c..6967b4a 100644
--- 
a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
+++ 
b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
-import java.util.Vector;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -1491,10 +1490,14 @@ public class SchemaBuilder {
         currentSchema.setAttributeFormDefault(this.getFormDefault(schemaEl, 
"attributeFormDefault"));
         currentSchema.setBlockDefault(this.getDerivation(schemaEl, 
"blockDefault"));
         currentSchema.setFinalDefault(this.getDerivation(schemaEl, 
"finalDefault"));
-        /* set id attribute */
+
+        /* set id and version attributes */
         if (schemaEl.hasAttribute("id")) {
             currentSchema.setId(schemaEl.getAttribute("id"));
         }
+        if (schemaEl.hasAttribute("version")) {
+            currentSchema.setVersion(schemaEl.getAttribute("version"));
+        }
 
         currentSchema.setSourceURI(systemId);
     }
@@ -1759,14 +1762,13 @@ public class SchemaBuilder {
         if (unionEl.hasAttribute("memberTypes")) {
             String memberTypes = unionEl.getAttribute("memberTypes");
             union.setMemberTypesSource(memberTypes);
-            Vector<QName> v = new Vector<QName>();
+            List<QName> v = new ArrayList<QName>();
             StringTokenizer tokenizer = new StringTokenizer(memberTypes, " ");
             while (tokenizer.hasMoreTokens()) {
                 String member = tokenizer.nextToken();
                 v.add(getRefQName(member, unionEl));
             }
-            union.setMemberTypesQNames(new QName[v.size()]);
-            v.copyInto(union.getMemberTypesQNames());
+            union.setMemberTypesQNames(v.toArray(new QName[v.size()]));
         }
 
         Element inlineUnionType = XDOMUtil.getFirstChildElementNS(unionEl, 
XmlSchema.SCHEMA_NS, "simpleType");
@@ -1828,7 +1830,7 @@ public class SchemaBuilder {
      * @param schemaObject
      * @param parentElement
      */
-    private void processExtensibilityComponents(XmlSchemaObject schemaObject, 
+    private void processExtensibilityComponents(XmlSchemaObject schemaObject,
                                                 Element parentElement,
                                                 boolean namespaces) {
 
@@ -1843,7 +1845,7 @@ public class SchemaBuilder {
 
                 if (namespaceURI != null && !"".equals(namespaceURI) // ignore 
unqualified attributes
                     // ignore namespaces
-                    && (namespaces || 
!namespaceURI.startsWith(Constants.XMLNS_ATTRIBUTE_NS_URI)) 
+                    && (namespaces || 
!namespaceURI.startsWith(Constants.XMLNS_ATTRIBUTE_NS_URI))
                     // does not belong to the schema namespace by any chance!
                     && !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI)) {
                     QName qName = new QName(namespaceURI, name);
diff --git a/xmlschema-core/src/test/java/tests/VersionTest.java 
b/xmlschema-core/src/test/java/tests/VersionTest.java
new file mode 100644
index 0000000..6348db7
--- /dev/null
+++ b/xmlschema-core/src/test/java/tests/VersionTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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 tests;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VersionTest extends Assert {
+
+    @Test
+    public void testVersion() throws Exception {
+
+        InputStream is = new FileInputStream(Resources.asURI("version.xsd"));
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is));
+
+        assertEquals("_12345", schema.getId());
+        assertEquals("some-version", schema.getVersion());
+    }
+
+}
diff --git a/xmlschema-core/src/test/resources/version.xsd 
b/xmlschema-core/src/test/resources/version.xsd
new file mode 100644
index 0000000..4bf9af3
--- /dev/null
+++ b/xmlschema-core/src/test/resources/version.xsd
@@ -0,0 +1,36 @@
+<!--
+  ~ 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.
+  -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+        xmlns:tns="http://soapinterop.org/types";
+        targetNamespace="http://soapinterop.org/types";
+        id="_12345"
+        version="some-version">
+
+  <element name="computer">
+    <complexType>
+      <sequence minOccurs="4" maxOccurs="50">
+        <element name="desktop" type="string"/>
+        <element name="laptop" type="string"/>
+      </sequence>
+    </complexType>
+  </element>
+
+
+</schema>
\ No newline at end of file

Reply via email to