< prev index next >

src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/schemagen/XmlSchemaGenerator.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2014, 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 --- 1,7 ---- /* ! * 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,117 **** --- 108,118 ---- 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,444 **** 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()); } // make it fool-proof resolver = new FoolProofResolver(resolver); this.errorListener = errorListener; --- 435,445 ---- if(resolver==null) throw new IllegalArgumentException(); if(logger.isLoggable(Level.FINE)) { // debug logging to see what's going on. ! logger.log(Level.FINE,"Writing XML Schema for "+toString(),new StackRecorder()); } // make it fool-proof resolver = new FoolProofResolver(resolver); this.errorListener = errorListener;
*** 463,472 **** --- 464,475 ---- 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,556 **** --- 543,571 ---- * 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,860 **** --- 866,879 ---- * * @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,1090 **** cImpl = (ClassInfoImpl) ref; break; } } } ! if (cImpl != null) e.ref(new QName(cImpl.getElementName().getNamespaceURI(), tn.getLocalPart())); ! else e.ref(new QName("", tn.getLocalPart())); } else e.ref(tn); } } else { --- 1097,1113 ---- cImpl = (ClassInfoImpl) ref; break; } } } ! 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 e.ref(new QName("", tn.getLocalPart())); } else e.ref(tn); } } else {
< prev index next >