Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1682: Non-deterministic definition of default namespace in @XmlSchema #1693

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/1679">#1679</link>: Add/implement JAnnotationUse.param(String name, JAnnotationValue annotationValue)
</para></listitem>
<listitem><para>
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/1680">#1680</link>: Avoid eager initialization of Scope objects.
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/1680">#1680</link>: Avoid eager initialization of Scope objects
</para></listitem>
<listitem><para>
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/1682">#1682</link>: Non-deterministic definition of default namespace @XmlSchema(namespace=...) in package-info.java
</para></listitem>
</itemizedlist>
</para></listitem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -10,16 +10,6 @@

package com.sun.tools.xjc.generator.bean;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import jakarta.xml.bind.annotation.XmlNsForm;
import jakarta.xml.bind.annotation.XmlSchema;
import javax.xml.namespace.QName;

import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JPackage;
import com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter;
Expand All @@ -33,8 +23,17 @@
import com.sun.tools.xjc.model.CTypeRef;
import com.sun.tools.xjc.model.CValuePropertyInfo;
import com.sun.tools.xjc.model.Model;
import com.sun.tools.xjc.outline.PackageOutline;
import com.sun.tools.xjc.outline.Aspect;
import com.sun.tools.xjc.outline.PackageOutline;
import jakarta.xml.bind.annotation.XmlNsForm;
import jakarta.xml.bind.annotation.XmlSchema;

import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
* {@link PackageOutline} enhanced with schema2java specific
Expand All @@ -48,7 +47,7 @@ public final class PackageOutlineImpl implements PackageOutline {
private final JPackage _package;
private final ObjectFactoryGenerator objectFactoryGenerator;

/*package*/ final Set<ClassOutlineImpl> classes = new HashSet<>();
/*package*/ final Set<ClassOutlineImpl> classes = new LinkedHashSet<>();
private final Set<ClassOutlineImpl> classesView = Collections.unmodifiableSet(classes);

private String mostUsedNamespaceURI;
Expand Down Expand Up @@ -205,18 +204,18 @@ public Void onValue(CValuePropertyInfo p) {

// Map to keep track of how often each type or element uri is used in this package
// mostly used to calculate mostUsedNamespaceURI
private HashMap<String, Integer> uriCountMap = new HashMap<>();
private Map<String, Integer> uriCountMap = new LinkedHashMap<>();

// Map to keep track of how often each property uri is used in this package
// used to calculate elementFormDefault
private HashMap<String, Integer> propUriCountMap = new HashMap<>();
private Map<String, Integer> propUriCountMap = new LinkedHashMap<>();

/**
* pull the uri out of the specified QName and keep track of it in the
* specified hash map
*
*/
private void countURI(HashMap<String, Integer> map, QName qname) {
private void countURI(Map<String, Integer> map, QName qname) {
if (qname == null) return;

String uri = qname.getNamespaceURI();
Expand All @@ -238,7 +237,7 @@ private void countURI(HashMap<String, Integer> map, QName qname) {
* and when that happens it unintentionally also renames (normally
* unqualified) local elements, prefer non-"" URI when there's a tie.
*/
private String getMostUsedURI(HashMap<String, Integer> map) {
private String getMostUsedURI(Map<String, Integer> map) {
String mostPopular = null;
int count = 0;

Expand Down