Bug 530965: missing import for different namespace from the same location
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Reviewed-by: RomanG, JanS
diff --git a/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/employee.xsd b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/employee.xsd
index 1978519..fb78497 100644
--- a/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/employee.xsd
+++ b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/employee.xsd
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xsd:schema xmlns:ns1="b" xmlns:ns0="a" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="a">
+<xsd:schema xmlns:ns0="a" xmlns:ns1="b" xmlns:ns2="c" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="a">
<xsd:import schemaLocation="http://someuri.com/myschema.xsd" namespace="b"/>
+ <xsd:import schemaLocation="http://someuri.com/myschema.xsd" namespace="c"/>
<xsd:complexType name="employee">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0"/>
<xsd:element name="address" type="ns1:address" minOccurs="0"/>
+ <xsd:element name="gender" type="ns2:gender" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/a/Employee.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/a/Employee.java
index 042dee8..f1bd93b 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/a/Employee.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/a/Employee.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -16,4 +16,5 @@ public class Employee{
public String name;
public org.eclipse.persistence.testing.jaxb.schemagen.imports.url.b.Address address;
+ public org.eclipse.persistence.testing.jaxb.schemagen.imports.url.c.Gender gender;
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/Gender.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/Gender.java
new file mode 100644
index 0000000..3beecca
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/Gender.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Lukas Jungmann - Feb 2018
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.imports.url.c;
+
+public enum Gender {
+
+ MALE, FEMALE;
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/package-info.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/package-info.java
new file mode 100644
index 0000000..090f6be
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/c/package-info.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Lukas Jungmann - Feb 2018
+ ******************************************************************************/
+@XmlSchema(namespace="c", location="http://someuri.com/myschema.xsd")
+package org.eclipse.persistence.testing.jaxb.schemagen.imports.url.c;
+
+import javax.xml.bind.annotation.XmlSchema;
+
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/SchemaGenerator.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/SchemaGenerator.java
index bd02be4..6f0a346 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/SchemaGenerator.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/SchemaGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2016 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -788,7 +788,7 @@ public String getOrGeneratePrefixForNamespace(String URI, Schema schema) {
} else if (URI.equals(Constants.REF_URL)) {
prefix = schema.getNamespaceResolver().generatePrefix(Constants.REF_PREFIX);
- if(!importExists(schema, SWA_REF_IMPORT)){
+ if(!importExists(schema, URI, SWA_REF_IMPORT)){
Import schemaImport = new Import();
schemaImport.setSchemaLocation(SWA_REF_IMPORT);
schemaImport.setNamespace(URI);
@@ -926,12 +926,20 @@ public Map<String, SchemaTypeInfo> getSchemaTypeInfo() {
return this.schemaTypeInfo;
}
- private boolean importExists(Schema schema, String schemaName) {
+ private boolean importExists(Schema schema, String importNsURI, String schemaLocation) {
java.util.List imports = schema.getImports();
for (int i = 0; i < imports.size(); i++) {
Import nextImport = (Import) imports.get(i);
- if (nextImport.getSchemaLocation() != null && nextImport.getSchemaLocation().equals(schemaName)) {
- return true;
+ if (nextImport.getSchemaLocation() != null && nextImport.getSchemaLocation().equals(schemaLocation)) {
+ if ("".equals(importNsURI)) {
+ if (nextImport.getNamespace() == null) {
+ return true;
+ }
+ } else {
+ if (importNsURI.equals(nextImport.getNamespace())) {
+ return true;
+ }
+ }
}
}
return false;
@@ -972,7 +980,7 @@ private boolean addImportIfRequired(Schema sourceSchema, Schema importSchema, St
}
}
- if (schemaName != null && !importExists(sourceSchema, schemaName)) {
+ if (schemaName != null && !importExists(sourceSchema, importNamespace, schemaName)) {
Import schemaImport = new Import();
schemaImport.setSchemaLocation(schemaName);
if (importNamespace != null && !importNamespace.equals(EMPTY_STRING)) {