5266N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 169N/A * Generates a set of W3C XML Schema documents from a set of Java classes. 169N/A * A client must invoke methods in the following order: 169N/A * <li>Create a new {@link XmlSchemaGenerator} 169N/A * <li>Invoke {@link #add} methods, multiple times if necessary. 169N/A * <li>Invoke {@link #write} 169N/A * <li>Discard the {@link XmlSchemaGenerator}. 169N/A * @author Ryan Shoemaker 169N/A * @author Kohsuke Kawaguchi (kk@kohsuke.org) 169N/A * Java classes to be written, organized by their namespace. 169N/A * We use a {@link TreeMap} here so that the suggested names will 0N/A * be consistent across JVMs. 0N/A * @see SchemaOutputResolver#createOutput(String, String) 169N/A * {@link ErrorListener} to send errors to. 169N/A /** model navigator **/ 169N/A * Representation for xs:string. 169N/A * Represents xs:anyType. 169N/A * Used to detect cycles in anonymous types. * Adds a new class to the list of classes to be written. * A {@link ClassInfo} may have two namespaces --- one for the element name * and the other for the type name. If they are different, we put the same * {@link ClassInfo} to two {@link Namespace}s. return;
// this is a special class we introduced for JAX-WS that we *don't* want in the schema // put element -> type reference // schedule writing this global element // search properties for foreign namespace references // recurse on baseTypes to make sure that we can refer to them in the schema * Adds a new element to the list of elements to be written. boolean nillable =
false;
// default value // search for foreign namespace references // put element -> type reference // schedule writing this global element return;
// anonymous type // search for foreign namespace references // search for foreign namespace references * Adds an additional element declaration. * The name of the element declaration to be added. * The type this element refers to. * Can be null, in which case the element refers to an empty anonymous complex type. return;
// this is a special class we introduced for JAX-WS that we *don't* want in the schema // search for foreign namespace references * Writes out the episode file. // TODO: don't we want to bake in versions? // generate listing per schema * Write out the schema documents. // debug logging to see what's going on. // we create a Namespace object for the XML Schema namespace // as a side-effect, but we don't want to generate it. // first create the outputs for all so that we can resolve references among // schema files when we write if(
output!=
null) {
// null result means no schema for that namespace * Schema components are organized per namespace. * Other {@link Namespace}s that this namespace depends on. * If this schema refers to components from this schema by itself. * List of classes in this namespace. * Set of enums in this namespace * Set of arrays in this namespace * Global attribute declarations keyed by their local names. * Global element declarations to be written, keyed by their local names. * Does schema in this namespace uses swaRef? If so, we need to generate import * Import for mime namespace needs to be generated. * 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 <import> * @param p the PropertyInfo // even though the Element interface says getElementName() returns non-null, // ClassInfo always implements Element (even if an instance of ClassInfo might not be an Element). // so this check is still necessary // no need to explicitly refer to XSD namespace // found a type in a foreign namespace, so make sure we generate an import for it * Writes the schema document to the specified result. * System IDs of the other schema documents. "" indicates 'implied'. // additional namespace declarations to be made. // TODO: if elementFormDefault is UNSET, figure out the right default value to use // declare XML Schema namespace to be xs, but allow the user to override it. // if 'xs' is used for other things, we'll just let TXW assign a random prefix // declare prefixes for them at this level, so that we can avoid redundant // namespace declarations // use common 'tns' prefix for the own namespace // if self-reference is needed // refer to other schemas // "" means implied. null if the SchemaOutputResolver said "don't generate!" // then write each component // don't generate anything if it's an anonymous type // don't generate anything if it's an anonymous type * Writes a type attribute (if the referenced type is a global type) * or writes out the definition of the anonymous type in place (if the referenced * type is not a global type.) * Also provides processing for ID/IDREF, MTOM @xmime, and swa:ref * ComplexTypeHost and SimpleTypeHost don't share an api for creating * and attribute in a type-safe way, so we will compromise for now and // no ID/IDREF, so continue on and generate the type // normal type generation * Writes a type attribute (if the referenced type is a global type) * or writes out the definition of the anonymous type in place (if the referenced * type is not a global type.) * the TXW interface to which the attribute will be written. * The name of the attribute used when referencing a type by QName. th.
block();
// so that the caller may write other attributes th.
block();
// so that the caller may write other attributes * writes the schema definition for the given array class * writes the schema definition for the specified type-safe enum in the given TypeHost * Writes the schema definition for the specified class to the schema writer. * @param c the class info * @param parent the writer of the parent element into which the type will be defined // special handling for value properties // [RESULT 2 - simpleType if the value prop is the only prop] // <simpleType name="foo"> // <xs:restriction base="xs:int"/> // [RESULT 1 - complexType with simpleContent] // <complexType name="foo"> // <extension base="xs:int"/> // <attribute name="b" type="xs:boolean"/> // <element name="f" type="foo"/> se.
block();
// because we might have attribute before value // Java types containing value props can only contain properties of type // ValuePropertyinfo and AttributePropertyInfo which have just been handled, // we didn't fall into the special case for value props, so we // need to initialize the ct. // generate the complexType // these are where we write content model and attributes // if there is a base class, we need to generate an extension in the schema // extending complex type with simple content // TODO: what if the base type is anonymous? // build the tree that represents the explicit content model from iterate over the properties // handling for <complexType @mixed='true' ...> // write the content model * Writes the name attribute if it's named. * Builds content model writer for the specified property. // attribuets are handled later // value props handled above in writeClass() * Generate the proper schema fragment for the given element property into the * specified schema compositor. * The element property may or may not represent a collection and it may or may * @param ep the element property e.
block();
// we will write occurs later // TODO: we need to generate the corresponding element declaration for this * Checks if we can collapse * <element name='foo' type='t' /> to <element ref='foo' />. * This is possible if we already have such declaration to begin with. // can't put those attributes on <element ref> // there's a circular reference from an anonymous subtype to a global element // we have the precise element defined already if (
te !=
null) {
// it is instanceof Element * Generate an attribute for the specified property on the specified complexType * @param ap the attribute * @param attr the schema definition to which the attribute will be added // attr is either a top-level ComplexType or a ComplexExtension // <attribute name="foo" type="xs:int"/> // <attribute name="foo" type="xs:int"/> // or it could also be an in-lined type (attr ref) if (
attrURI.
equals(
"")
/*|| attrURI.equals(uri) --- those are generated as global attributes anyway, so use them.*/) {
}
else {
// generate an attr ref * Generate the proper schema fragment for the given reference property into the * specified schema compositor. * The reference property may or may not refer to a collection and it may or may // scoped. needs to be inlined // write form="..." if necessary // write out type reference * Generate the proper schema fragment for the given map property into the * specified schema compositor. * @param mp the map property // TODO: entry, key, and value are always unqualified. that needs to be fixed, too. // TODO: we need to generate the corresponding element declaration, if they are qualified * Represents a global element declaration to be written. * Because multiple properties can name the same global element even if * they have different Java type, the schema generator first needs to * walk through the model and decide what to generate for the given * This class represents what will be written, and its {@link #equals(Object)} * method is implemented in such a way that two identical declarations * are considered as the same. * Returns true if two {@link ElementDeclaration}s are representing * the same schema fragment. * Generates the declaration. * {@link ElementDeclaration} that refers to a {@link NonElement}. e.
complexType();
// refer to the nested empty complex type if (
this == o)
return true;
* Examine the specified element ref and determine if a swaRef attribute needs to be generated * Examine the specified element ref and determine if a swaRef attribute needs to be generated if (o ==
null)
return false;
* Debug information of what's in this {@link XmlSchemaGenerator}. * return the string representation of the processContents mode of the * give wildcard, or null if it is the schema default "strict" * Relativizes a URI by using another URI (base URI.) * This method only works on hierarchical URI's, not opaque URI's (refer to the * javadoc for complete definitions of these terms. * This method will not normalize the relative URI. * @return the relative URI or the original URI if a relative one could not be computed return uri;
// recursion found no commonality in the two uris at all // if this is a file URL (very likely), and if this is on a case-insensitive file system, // then treat it accordingly. * JAX-RPC wants the namespaces to be sorted in the reverse order * so that the empty namespace "" comes to the very end. Don't ask me why.