Top Description Inners Fields Constructors Methods
org.glassfish.jaxb.runtime.v2.schemagen

public final Class XmlSchemaGenerator<T, C, F, M>

extends Object
Class Inheritance
Imports
com.sun.istack.NotNull, .Nullable, org.glassfish.jaxb.core.Utils, org.glassfish.jaxb.core.api.ErrorListener, org.glassfish.jaxb.runtime.api.CompositeStructure, org.glassfish.jaxb.core.v2.TODO, .WellKnownNamespace, org.glassfish.jaxb.core.v2.model.core.*, .Element, org.glassfish.jaxb.runtime.v2.model.impl.ClassInfoImpl, org.glassfish.jaxb.core.v2.model.nav.Navigator, org.glassfish.jaxb.runtime.v2.runtime.SwaRefAdapter, org.glassfish.jaxb.core.v2.schemagen.episode.Bindings, org.glassfish.jaxb.runtime.v2.util.CollisionCheckStack, .StackRecorder, com.sun.xml.txw2.TXW, .TxwException, .TypedXmlWriter, com.sun.xml.txw2.output.ResultFactory, .XmlSerializer, jakarta.activation.MimeType, jakarta.xml.bind.SchemaOutputResolver, jakarta.xml.bind.annotation.XmlElement, org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.*, org.xml.sax.SAXParseException, javax.xml.XMLConstants, javax.xml.namespace.QName, javax.xml.transform.Result, javax.xml.transform.stream.StreamResult, java.io.File, .IOException, .OutputStream, .Writer, java.net.URI, .URISyntaxException, java.util.*, java.util.logging.Level, .Logger

Generates a set of W3C XML Schema documents from a set of Java classes.

A client must invoke methods in the following order:

  1. Create a new XmlSchemaGenerator
  2. Invoke add methods, multiple times if necessary.
  3. Invoke write
  4. Discard the XmlSchemaGenerator.
Authors
Ryan Shoemaker, Kohsuke Kawaguchi ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
XmlSchemaGenerator.Namespace

Schema components are organized per namespace.

Field Summary

Modifier and TypeField and Description
private final NonElement<T, C>
anyType

Represents xs:anyType.

private final CollisionCheckStack<ClassInfo<T, C>>
collisionChecker

Used to detect cycles in types.

private ErrorListener
errorListener

ErrorListener to send errors to.

private static final Logger
private static final Comparator<String>
NAMESPACE_COMPARATOR

JAX-RPC wants the namespaces to be sorted in the reverse order so that the empty namespace "" comes to the very end.

private final Map<String, XmlSchemaGenerator<T, C, F, M>.Namespace>
namespaces

Java classes to be written, organized by their namespace.

private static final String
private final NonElement<T, C>
stringType

Representation for xs:string.

private final TypeInfoSet<T, C, F, M>

Constructor Summary

AccessConstructor and Description
public
XmlSchemaGenerator(Navigator<T, C, F, M> navigator, TypeInfoSet<T, C, F, M> types)

Method Summary

Modifier and TypeMethod and Description
public void
add(ClassInfo<T, C> clazz)

Adds a new class to the list of classes to be written.

public void
add(ElementInfo<T, C> elem)

Adds a new element to the list of elements to be written.

public void
add(EnumLeafInfo<T, C> envm)

public void
add(ArrayInfo<T, C> a)

public void
add(QName
The name of the element declaration to be added.
tagName
,
boolean isNillable, NonElement<T, C>
The type this element refers to. Can be null, in which case the element refers to an empty anonymous complex type.
type
)

Adds an additional element declaration.

private static String
calculateRelativePath(String uri, String base, boolean fileUrl)

private static String
private boolean
generateSwaRefAdapter(NonElementRef<T, C> typeRef)

Examine the specified element ref and determine if a swaRef attribute needs to be generated

private boolean
generateSwaRefAdapter(PropertyInfo<T, C> prop)

Examine the specified element ref and determine if a swaRef attribute needs to be generated

private XmlSchemaGenerator<T, C, F, M>.Namespace
private static String
getProcessContentsModeName(WildcardMode wc)

return the string representation of the processContents mode of the give wildcard, or null if it is the schema default "strict"

protected static String

Returns:

the relative URI or the original URI if a relative one could not be computed
relativize
(String uri, String baseUri)

Relativizes a URI by using another URI (base URI.)

For example, relative("http://www.sun.com/abc/def","http://www.sun.com/pqr/stu") => "../abc/def"

This method only works on hierarchical URI's, not opaque URI's (refer to the java.net.URI javadoc for complete definitions of these terms.

private static boolean
public String
toString()

Overrides java.lang.Object.toString.

Debug information of what's in this .

public void
write(SchemaOutputResolver resolver, ErrorListener errorListener)

Write out the schema documents.

public void
writeEpisodeFile(XmlSerializer out)

Writes out the episode file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

anyTypeback to summary
private final NonElement<T, C> anyType

Represents xs:anyType.

collisionCheckerback to summary
private final CollisionCheckStack<ClassInfo<T, C>> collisionChecker

Used to detect cycles in types.

errorListenerback to summary
private ErrorListener errorListener

ErrorListener to send errors to.

loggerback to summary
private static final Logger logger
NAMESPACE_COMPARATORback to summary
private static final Comparator<String> NAMESPACE_COMPARATOR

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.

namespacesback to summary
private final Map<String, XmlSchemaGenerator<T, C, F, M>.Namespace> namespaces

Java classes to be written, organized by their namespace.

We use a TreeMap here so that the suggested names will be consistent across JVMs.

See Also
SchemaOutputResolver#createOutput(String, String)
newlineback to summary
private static final String newline
stringTypeback to summary
private final NonElement<T, C> stringType

Representation for xs:string.

typesback to summary
private final TypeInfoSet<T, C, F, M> types

Constructor Detail

XmlSchemaGeneratorback to summary
public XmlSchemaGenerator(Navigator<T, C, F, M> navigator, TypeInfoSet<T, C, F, M> types)

Method Detail

addback to summary
public void add(ClassInfo<T, C> clazz)

Adds a new class to the list of classes to be written.

A 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 ClassInfo to two Namespaces.

addback to summary
public void add(ElementInfo<T, C> elem)

Adds a new element to the list of elements to be written.

addback to summary
public void add(EnumLeafInfo<T, C> envm)
addback to summary
public void add(ArrayInfo<T, C> a)
addback to summary
public void add(QName tagName, boolean isNillable, NonElement<T, C> type)

Adds an additional element declaration.

Parameters
tagName:QName

The name of the element declaration to be added.

type:NonElement<T, C>

The type this element refers to. Can be null, in which case the element refers to an empty anonymous complex type.

calculateRelativePathback to summary
private static String calculateRelativePath(String uri, String base, boolean fileUrl)
fixNullback to summary
private static String fixNull(String s)
generateSwaRefAdapterback to summary
private boolean generateSwaRefAdapter(NonElementRef<T, C> typeRef)

Examine the specified element ref and determine if a swaRef attribute needs to be generated

generateSwaRefAdapterback to summary
private boolean generateSwaRefAdapter(PropertyInfo<T, C> prop)

Examine the specified element ref and determine if a swaRef attribute needs to be generated

getNamespaceback to summary
private XmlSchemaGenerator<T, C, F, M>.Namespace getNamespace(String uri)
getProcessContentsModeNameback to summary
private static String getProcessContentsModeName(WildcardMode wc)

return the string representation of the processContents mode of the give wildcard, or null if it is the schema default "strict"

relativizeback to summary
protected static String relativize(String uri, String baseUri)

Relativizes a URI by using another URI (base URI.)

For example, relative("http://www.sun.com/abc/def","http://www.sun.com/pqr/stu") => "../abc/def"

This method only works on hierarchical URI's, not opaque URI's (refer to the java.net.URI javadoc for complete definitions of these terms.

This method will not normalize the relative URI.

Returns:String

the relative URI or the original URI if a relative one could not be computed

startsWithIgnoreCaseback to summary
private static boolean startsWithIgnoreCase(String s, String t)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Debug information of what's in this .

Annotations
@Override
writeback to summary
public void write(SchemaOutputResolver resolver, ErrorListener errorListener) throws IOException

Write out the schema documents.

writeEpisodeFileback to summary
public void writeEpisodeFile(XmlSerializer out)

Writes out the episode file.

org.glassfish.jaxb.runtime.v2.schemagen back to summary

private Class XmlSchemaGenerator.Namespace

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace

Schema components are organized per namespace.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
XmlSchemaGenerator.Namespace.ElementDeclaration

Represents a global element declaration to be written.

pack-priv class

Field Summary

Modifier and TypeField and Description
private final Set<ArrayInfo<T, C>>
arrays

Set of arrays in this namespace

private final MultiMap<String, AttributePropertyInfo<T, C>>
attributeDecls

Global attribute declarations keyed by their local names.

private Form
private final Set<ClassInfo<T, C>>
classes

List of classes in this namespace.

private final Set<XmlSchemaGenerator<T, C, F, M>.Namespace>
depends

Other Namespaces that this namespace depends on.

private final MultiMap<String, XmlSchemaGenerator<T, C, F, M>.Namespace.ElementDeclaration>
elementDecls

Global element declarations to be written, keyed by their local names.

private Form
private final Set<EnumLeafInfo<T, C>>
enums

Set of enums in this namespace

private boolean
selfReference

If this schema refers to components from this schema by itself.

pack-priv final String
private boolean
useMimeNs

Import for mime namespace needs to be generated.

private boolean
useSwaRef

Does schema in this namespace uses swaRef?

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
public void
private Tree
buildPropertyContentModel(PropertyInfo<T, C> p)

Builds content model writer for the specified property.

private boolean
canBeDirectElementRef(TypeRef<T, C> t, QName tn, TypeInfo<T, C> parentInfo)

Checks if we can collapse <element name='foo' type='t' /> to <element ref='foo' />.

private boolean
private void
handleAttributeProp(AttributePropertyInfo<T, C>
the attribute
ap
,
AttrDecls
the schema definition to which the attribute will be added
attr
)

Generate an attribute for the specified property on the specified complexType

private Tree
handleElementProp(final ElementPropertyInfo<T, C>
the element property
ep
)

Generate the proper schema fragment for the given element property into the specified schema compositor.

private Tree
handleMapProp(final MapPropertyInfo<T, C>
the map property
mp
)

Generate the proper schema fragment for the given map property into the specified schema compositor.

private Tree
handleReferenceProp(final ReferencePropertyInfo<T, C> rp)

Generate the proper schema fragment for the given reference property into the specified schema compositor.

private void
processForeignNamespaces(PropertyInfo<T, C>
the PropertyInfo
p
,
int processingDepth)

Process the given PropertyInfo looking for references to namespaces that are foreign to the given namespace.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
writeArray(ArrayInfo<T, C> a, Schema schema)

writes the schema definition for the given array class

private void
private void
writeClass(ClassInfo<T, C>
the class info
c
,
TypeHost
the writer of the parent element into which the type will be defined
parent
)

Writes the schema definition for the specified class to the schema writer.

private void
writeEnum(EnumLeafInfo<T, C> e, SimpleTypeHost th)

writes the schema definition for the specified type-safe enum in the given TypeHost

private void
writeKeyOrValue(ExplicitGroup seq, String tagName, NonElement<T, C> typeRef)

private void
writeName(NonElement<T, C> c, TypedXmlWriter xw)

Writes the name attribute if it's named.

private void
writeTo(Result result, Map<XmlSchemaGenerator<T, C, F, M>.Namespace, String>
System IDs of the other schema documents. "" indicates 'implied'.
systemIds
)

Writes the schema document to the specified result.

private void
writeTypeRef(TypeHost th, NonElementRef<T, C> typeRef, String refAttName)

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 use _attribute().

private void
writeTypeRef(TypeHost
the TXW interface to which the attribute will be written.
th
,
NonElement<T, C>
type to be referenced.
type
,
String
The name of the attribute used when referencing a type by QName.
refAttName
)

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.)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

arraysback to summary
private final Set<ArrayInfo<T, C>> arrays

Set of arrays in this namespace

attributeDeclsback to summary
private final MultiMap<String, AttributePropertyInfo<T, C>> attributeDecls

Global attribute declarations keyed by their local names.

attributeFormDefaultback to summary
private Form attributeFormDefault
classesback to summary
private final Set<ClassInfo<T, C>> classes

List of classes in this namespace.

dependsback to summary
private final Set<XmlSchemaGenerator<T, C, F, M>.Namespace> depends

Other Namespaces that this namespace depends on.

elementDeclsback to summary
private final MultiMap<String, XmlSchemaGenerator<T, C, F, M>.Namespace.ElementDeclaration> elementDecls

Global element declarations to be written, keyed by their local names.

elementFormDefaultback to summary
private Form elementFormDefault
enumsback to summary
private final Set<EnumLeafInfo<T, C>> enums

Set of enums in this namespace

selfReferenceback to summary
private boolean selfReference

If this schema refers to components from this schema by itself.

uriback to summary
pack-priv final String uri
Annotations
@NotNull
useMimeNsback to summary
private boolean useMimeNs

Import for mime namespace needs to be generated. See #856

useSwaRefback to summary
private boolean useSwaRef

Does schema in this namespace uses swaRef? If so, we need to generate import statement.

Constructor Detail

Namespaceback to summary
public Namespace(String uri)

Method Detail

addDependencyToback to summary
private void addDependencyTo(QName qname)
addGlobalAttributeback to summary
public void addGlobalAttribute(AttributePropertyInfo<T, C> ap)
addGlobalElementback to summary
public void addGlobalElement(TypeRef<T, C> tref)
buildPropertyContentModelback to summary
private Tree buildPropertyContentModel(PropertyInfo<T, C> p)

Builds content model writer for the specified property.

canBeDirectElementRefback to summary
private boolean canBeDirectElementRef(TypeRef<T, C> t, QName tn, TypeInfo<T, C> parentInfo)

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.

containsValuePropback to summary
private boolean containsValueProp(ClassInfo<T, C> c)
handleAttributePropback to summary
private void handleAttributeProp(AttributePropertyInfo<T, C> ap, AttrDecls attr)

Generate an attribute for the specified property on the specified complexType

Parameters
ap:AttributePropertyInfo<T, C>

the attribute

attr:AttrDecls

the schema definition to which the attribute will be added

handleElementPropback to summary
private Tree handleElementProp(final ElementPropertyInfo<T, C> ep)

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 not be wrapped.

Parameters
ep:ElementPropertyInfo<T, C>

the element property

handleMapPropback to summary
private Tree handleMapProp(final MapPropertyInfo<T, C> mp)

Generate the proper schema fragment for the given map property into the specified schema compositor.

Parameters
mp:MapPropertyInfo<T, C>

the map property

handleReferencePropback to summary
private Tree handleReferenceProp(final ReferencePropertyInfo<T, C> rp)

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 not be wrapped.

processForeignNamespacesback to summary
private void processForeignNamespaces(PropertyInfo<T, C> p, int processingDepth)

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> is generated for it.

Parameters
p:PropertyInfo<T, C>

the PropertyInfo

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
writeArrayback to summary
private void writeArray(ArrayInfo<T, C> a, Schema schema)

writes the schema definition for the given array class

writeAttributeTypeRefback to summary
private void writeAttributeTypeRef(AttributePropertyInfo<T, C> ap, AttributeType a)
writeClassback to summary
private void writeClass(ClassInfo<T, C> c, TypeHost parent)

Writes the schema definition for the specified class to the schema writer.

Parameters
c:ClassInfo<T, C>

the class info

parent:TypeHost

the writer of the parent element into which the type will be defined

writeEnumback to summary
private void writeEnum(EnumLeafInfo<T, C> e, SimpleTypeHost th)

writes the schema definition for the specified type-safe enum in the given TypeHost

writeKeyOrValueback to summary
private void writeKeyOrValue(ExplicitGroup seq, String tagName, NonElement<T, C> typeRef)
writeNameback to summary
private void writeName(NonElement<T, C> c, TypedXmlWriter xw)

Writes the name attribute if it's named.

writeToback to summary
private void writeTo(Result result, Map<XmlSchemaGenerator<T, C, F, M>.Namespace, String> systemIds) throws IOException

Writes the schema document to the specified result.

Parameters
systemIds:Map<XmlSchemaGenerator<T, C, F, M>.Namespace, String>

System IDs of the other schema documents. "" indicates 'implied'.

writeTypeRefback to summary
private void writeTypeRef(TypeHost th, NonElementRef<T, C> typeRef, String refAttName)

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 use _attribute().

writeTypeRefback to summary
private void writeTypeRef(TypeHost th, NonElement<T, C> type, String refAttName)

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.)

Parameters
th:TypeHost

the TXW interface to which the attribute will be written.

type:NonElement<T, C>

type to be referenced.

refAttName:String

The name of the attribute used when referencing a type by QName.

org.glassfish.jaxb.runtime.v2.schemagen back to summary

pack-priv abstract Class XmlSchemaGenerator.Namespace.ElementDeclaration

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration
Known Direct Subclasses
org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementWithType

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 element declaration.

This class represents what will be written, and its equals(Object) method is implemented in such a way that two identical declarations are considered as the same.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public abstract boolean
equals(Object o)

Overrides java.lang.Object.equals.

Returns true if two s are representing the same schema fragment.

public abstract int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public abstract void
writeTo(String localName, Schema schema)

Generates the declaration.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ElementDeclarationback to summary
pack-priv ElementDeclaration()

Method Detail

equalsback to summary
public abstract boolean equals(Object o)

Overrides java.lang.Object.equals.

Returns true if two s are representing the same schema fragment.

Annotations
@Override
hashCodeback to summary
public abstract int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
writeToback to summary
public abstract void writeTo(String localName, Schema schema)

Generates the declaration.

org.glassfish.jaxb.runtime.v2.schemagen back to summary

pack-priv Class XmlSchemaGenerator.Namespace.ElementWithType

extends XmlSchemaGenerator<T, C, F, M>.Namespace.ElementDeclaration
Class Inheritance

ElementDeclaration that refers to a NonElement.

Field Summary

Modifier and TypeField and Description
private final boolean
private final NonElement<T, C>

Constructor Summary

AccessConstructor and Description
public
ElementWithType(boolean nillable, NonElement<T, C> type)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Implements abstract org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.equals.

Returns true if two s are representing the same schema fragment.

public int
public void

Field Detail

nillableback to summary
private final boolean nillable
typeback to summary
private final NonElement<T, C> type

Constructor Detail

ElementWithTypeback to summary
public ElementWithType(boolean nillable, NonElement<T, C> type)

Method Detail

equalsback to summary
public boolean equals(Object o)

Implements abstract org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.equals.

Doc from org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.equals.

Returns true if two s are representing the same schema fragment.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Implements abstract org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
writeToback to summary
public void writeTo(String localName, Schema schema)

Implements abstract org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.writeTo.

Doc from org.glassfish.jaxb.runtime.v2.schemagen.XmlSchemaGenerator.Namespace.ElementDeclaration.writeTo.

Generates the declaration.

Annotations
@Override