< prev index next >
src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/schemagen/XmlSchemaGenerator.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -108,10 +108,11 @@
import com.sun.xml.internal.txw2.TxwException;
import com.sun.xml.internal.txw2.TypedXmlWriter;
import com.sun.xml.internal.txw2.output.ResultFactory;
import com.sun.xml.internal.txw2.output.XmlSerializer;
import java.util.Collection;
+import java.util.HashSet;
import org.xml.sax.SAXParseException;
/**
* Generates a set of W3C XML Schema documents from a set of Java classes.
*
@@ -434,11 +435,11 @@
if(resolver==null)
throw new IllegalArgumentException();
if(logger.isLoggable(Level.FINE)) {
// debug logging to see what's going on.
- logger.log(Level.FINE,"Wrigin XML Schema for "+toString(),new StackRecorder());
+ logger.log(Level.FINE,"Writing XML Schema for "+toString(),new StackRecorder());
}
// make it fool-proof
resolver = new FoolProofResolver(resolver);
this.errorListener = errorListener;
@@ -463,10 +464,12 @@
if(output!=null) { // null result means no schema for that namespace
out.put(n,output);
systemIds.put(n,output.getSystemId());
}
}
+ //Clear the namespace specific set with already written classes
+ n.resetWritten();
}
// then write'em all
for( Map.Entry<Namespace,Result> e : out.entrySet() ) {
Result result = e.getValue();
@@ -540,17 +543,29 @@
* Import for mime namespace needs to be generated.
* See #856
*/
private boolean useMimeNs;
+ /**
+ * Container for already processed classes
+ */
+ private final Set<ClassInfo> written = new HashSet<ClassInfo>();
+
public Namespace(String uri) {
this.uri = uri;
assert !XmlSchemaGenerator.this.namespaces.containsKey(uri);
XmlSchemaGenerator.this.namespaces.put(uri,this);
}
/**
+ * Clear out the set of already processed classes for this namespace
+ */
+ void resetWritten() {
+ written.clear();
+ }
+
+ /**
* Process the given PropertyInfo looking for references to namespaces that
* are foreign to the given namespace. Any foreign namespace references
* found are added to the given namespaces dependency list and an {@code <import>}
* is generated for it.
*
@@ -851,10 +866,14 @@
*
* @param c the class info
* @param parent the writer of the parent element into which the type will be defined
*/
private void writeClass(ClassInfo<T,C> c, TypeHost parent) {
+ if (written.contains(c)) { // to avoid cycles let's check if we haven't already processed the class
+ return;
+ }
+ written.add(c);
// special handling for value properties
if (containsValueProp(c)) {
if (c.getProperties().size() == 1) {
// [RESULT 2 - simpleType if the value prop is the only prop]
//
@@ -1078,13 +1097,17 @@
cImpl = (ClassInfoImpl) ref;
break;
}
}
}
- if (cImpl != null)
+ if (cImpl != null) {
+ if (tn.getNamespaceURI() != null && tn.getNamespaceURI().trim().length() != 0) {
+ e.ref(new QName(tn.getNamespaceURI(), tn.getLocalPart()));
+ } else {
e.ref(new QName(cImpl.getElementName().getNamespaceURI(), tn.getLocalPart()));
- else
+ }
+ } else
e.ref(new QName("", tn.getLocalPart()));
} else
e.ref(tn);
}
} else {
< prev index next >