com.sun.tools.xjc.model
Class Model

java.lang.Object
  extended by com.sun.tools.xjc.model.Model
All Implemented Interfaces:
CCustomizable, TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

public final class Model
extends java.lang.Object
implements TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>, CCustomizable

Root of the object model that represents the code that needs to be generated.

A Model is a schema language neutral representation of the result of a scehma parsing. The back-end then works against this model to turn this into a series of Java source code.


Field Summary
 com.sun.codemodel.JCodeModel codeModel
          This model uses this code model exclusively.
 SymbolSpace defaultSymbolSpace
          Default ID/IDREF symbol space.
 Options options
          Command-line options used for building this model.
 com.sun.codemodel.JClass rootClass
          If non-null, all the generated classes should eventually derive from this class.
 com.sun.codemodel.JClass rootInterface
          If non-null, all the generated interfaces should eventually derive from this interface.
 com.sun.xml.xsom.XSSchemaSet schemaComponent
          If this model was built from XML Schema, this field stores the root object of the parse schema model.
 boolean serializable
          True to generate serializable classes.
 java.lang.Long serialVersionUID
          serial version UID to be generated.
 ImplStructureStrategy strategy
          Specifies the code generation strategy.
 
Constructor Summary
Model(Options opts, com.sun.codemodel.JCodeModel cm, NameConverter nc, ClassNameAllocator allocator, com.sun.xml.xsom.XSSchemaSet schemaComponent)
           
 
Method Summary
 java.util.Map<NType,? extends CArrayInfo> arrays()
          No array mapping generation for XJC.
 java.util.Map<NClass,CClassInfo> beans()
          Returns all the ClassInfos known to this set.
 java.util.Map<NType,? extends CBuiltinLeafInfo> builtins()
          Returns all the BuiltinLeafInfos known to this set.
 java.util.Map<javax.xml.namespace.QName,CClassInfo> createTopLevelBindings()
          Represents the "top-level binding".
 void dump(javax.xml.transform.Result out)
          Dumps this model into XML.
 java.util.Map<NClass,CEnumLeafInfo> enums()
          Returns all the EnumLeafInfos known to this set.
 Outline generateCode(Options opt, ErrorReceiver receiver)
          Fully-generate the source code into the given model.
 java.lang.Iterable<? extends CElementInfo> getAllElements()
          Returns all the ElementInfo known to this set.
 CBuiltinLeafInfo getAnyTypeInfo()
          Gets the TypeInfo for the any type.
 javax.xml.bind.annotation.XmlNsForm getAttributeFormDefault(java.lang.String nsUri)
          Gets the reasonable XmlNsForm for the given namespace URI.
 CClassInfo getClassInfo(NClass t)
          Returns a ClassInfo, ArrayInfo, or LeafInfo for the given bean.
 CCustomizations getCustomizations()
          Gets the global customizations.
 javax.xml.bind.annotation.XmlNsForm getElementFormDefault(java.lang.String nsUri)
          Gets the reasonable XmlNsForm for the given namespace URI.
 CElementInfo getElementInfo(NClass scope, javax.xml.namespace.QName name)
          Returns a ElementInfo for the given element.
 java.util.Map<javax.xml.namespace.QName,CElementInfo> getElementMappings(NClass scope)
          Returns all ElementInfos in the given scope.
 org.xml.sax.Locator getLocator()
          Deprecated. No line number available for the "root" component.
 NameConverter getNameConverter()
          Gets the name converter that shall be used to parse XML names into Java names.
 Navigator<NType,NClass,java.lang.Void,java.lang.Void> getNavigator()
          Navigator for this model.
 CClassInfoParent.Package getPackage(com.sun.codemodel.JPackage pkg)
           
 com.sun.xml.xsom.XSComponent getSchemaComponent()
          Deprecated. Always return null. Perhaps you are interested in schemaComponent?
 java.util.Map<java.lang.String,java.lang.String> getSchemaLocations()
          Gets XmlSchema.location() found in this context.
 SymbolSpace getSymbolSpace(java.lang.String name)
           
 CNonElement getTypeInfo(NType type)
          Returns a TypeInfo for the given type.
 CNonElement getTypeInfo(Ref<NType,NClass> ref)
          Returns a type information for the given reference.
 java.util.Map<java.lang.String,java.lang.String> getXmlNs(java.lang.String namespaceUri)
          Not implemented in the compile-time model.
 boolean isPackageLevelAnnotations()
           
 void setNameConverter(NameConverter nameConverter)
           
 void setPackageLevelAnnotations(boolean packageLevelAnnotations)
           
 java.util.Map<javax.xml.namespace.QName,TypeUse> typeUses()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schemaComponent

public final com.sun.xml.xsom.XSSchemaSet schemaComponent
If this model was built from XML Schema, this field stores the root object of the parse schema model. Otherwise null.


codeModel

public final com.sun.codemodel.JCodeModel codeModel
This model uses this code model exclusively.


options

public final Options options
Command-line options used for building this model.


serializable

public boolean serializable
True to generate serializable classes.


serialVersionUID

public java.lang.Long serialVersionUID
serial version UID to be generated. null if not to generate serialVersionUID field.


rootClass

public com.sun.codemodel.JClass rootClass
If non-null, all the generated classes should eventually derive from this class.


rootInterface

public com.sun.codemodel.JClass rootInterface
If non-null, all the generated interfaces should eventually derive from this interface.


strategy

public ImplStructureStrategy strategy
Specifies the code generation strategy. Must not be null.


defaultSymbolSpace

public final SymbolSpace defaultSymbolSpace
Default ID/IDREF symbol space. Any ID/IDREF without explicit reference to a symbol space is assumed to use this default symbol space.

Constructor Detail

Model

public Model(Options opts,
             com.sun.codemodel.JCodeModel cm,
             NameConverter nc,
             ClassNameAllocator allocator,
             com.sun.xml.xsom.XSSchemaSet schemaComponent)
Parameters:
nc - Usually this should be set in the constructor, but we do allow this parameter to be initially null, and then set later.
schemaComponent - The source schema model, if this is built from XSD.
Method Detail

setNameConverter

public void setNameConverter(NameConverter nameConverter)

getNameConverter

public final NameConverter getNameConverter()
Gets the name converter that shall be used to parse XML names into Java names.


isPackageLevelAnnotations

public boolean isPackageLevelAnnotations()

setPackageLevelAnnotations

public void setPackageLevelAnnotations(boolean packageLevelAnnotations)

getSymbolSpace

public SymbolSpace getSymbolSpace(java.lang.String name)

generateCode

public Outline generateCode(Options opt,
                            ErrorReceiver receiver)
Fully-generate the source code into the given model.

Returns:
null if there was any errors. Otherwise it returns a valid Outline object, which captures how the model objects are mapped to the generated source code.

Add-ons can use those information to further augment the generated source code.


createTopLevelBindings

public final java.util.Map<javax.xml.namespace.QName,CClassInfo> createTopLevelBindings()
Represents the "top-level binding".

This is used to support the use of a schema inside WSDL. For XML Schema, the top-level binding is a map from global element declarations to its representation class.

For other schema languages, it should follow the appendicies in WSDL (but in practice no one would use WSDL with a schema language other than XML Schema, so it doesn't really matter.)

This needs to be filled by the front-end.


getNavigator

public Navigator<NType,NClass,java.lang.Void,java.lang.Void> getNavigator()
Description copied from interface: TypeInfoSet
Navigator for this model.

Specified by:
getNavigator in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

getTypeInfo

public CNonElement getTypeInfo(NType type)
Description copied from interface: TypeInfoSet
Returns a TypeInfo for the given type.

Specified by:
getTypeInfo in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
null if the specified type cannot be bound by JAXB, or not known to this set.

getAnyTypeInfo

public CBuiltinLeafInfo getAnyTypeInfo()
Description copied from interface: TypeInfoSet
Gets the TypeInfo for the any type.

Specified by:
getAnyTypeInfo in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

getTypeInfo

public CNonElement getTypeInfo(Ref<NType,NClass> ref)
Description copied from interface: TypeInfoSet
Returns a type information for the given reference.

Specified by:
getTypeInfo in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

beans

public java.util.Map<NClass,CClassInfo> beans()
Description copied from interface: TypeInfoSet
Returns all the ClassInfos known to this set.

Specified by:
beans in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

enums

public java.util.Map<NClass,CEnumLeafInfo> enums()
Description copied from interface: TypeInfoSet
Returns all the EnumLeafInfos known to this set.

Specified by:
enums in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

typeUses

public java.util.Map<javax.xml.namespace.QName,TypeUse> typeUses()

arrays

public java.util.Map<NType,? extends CArrayInfo> arrays()
No array mapping generation for XJC.

Specified by:
arrays in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

builtins

public java.util.Map<NType,? extends CBuiltinLeafInfo> builtins()
Description copied from interface: TypeInfoSet
Returns all the BuiltinLeafInfos known to this set.

Specified by:
builtins in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

getClassInfo

public CClassInfo getClassInfo(NClass t)
Description copied from interface: TypeInfoSet
Returns a ClassInfo, ArrayInfo, or LeafInfo for the given bean.

This method is almost like refinement of TypeInfoSet.getTypeInfo(Object) except our C cannot derive from T.

Specified by:
getClassInfo in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
null if the specified type is not bound by JAXB or otherwise unknown to this set.

getElementInfo

public CElementInfo getElementInfo(NClass scope,
                                   javax.xml.namespace.QName name)
Description copied from interface: TypeInfoSet
Returns a ElementInfo for the given element.

Specified by:
getElementInfo in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
scope - if null, return the info about a global element. Otherwise return a local element in the given scope if available, then look for a global element next.

getElementMappings

public java.util.Map<javax.xml.namespace.QName,CElementInfo> getElementMappings(NClass scope)
Description copied from interface: TypeInfoSet
Returns all ElementInfos in the given scope.

Specified by:
getElementMappings in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
scope - if non-null, this method only returns the local element mapping.

getAllElements

public java.lang.Iterable<? extends CElementInfo> getAllElements()
Description copied from interface: TypeInfoSet
Returns all the ElementInfo known to this set.

Specified by:
getAllElements in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

getSchemaComponent

public com.sun.xml.xsom.XSComponent getSchemaComponent()
Deprecated. Always return null. Perhaps you are interested in schemaComponent?

Description copied from interface: CCustomizable
If this model object is built from XML Schema, this property returns a schema component from which the model is built.

Specified by:
getSchemaComponent in interface CCustomizable
Returns:
null if the model is built from sources other than XML Schema (such as DTD.)

getLocator

public org.xml.sax.Locator getLocator()
Deprecated. No line number available for the "root" component.

Description copied from interface: CCustomizable
Gets the source location in the schema from which this model component is created.

Specified by:
getLocator in interface CCustomizable
Returns:
never null.

getCustomizations

public CCustomizations getCustomizations()
Gets the global customizations.

Specified by:
getCustomizations in interface CCustomizable
Returns:
can be an empty list but never be null. The returned list is read-only. Do not modify.
See Also:
Plugin.getCustomizationURIs()

getXmlNs

public java.util.Map<java.lang.String,java.lang.String> getXmlNs(java.lang.String namespaceUri)
Not implemented in the compile-time model.

Specified by:
getXmlNs in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
A map from prefixes to namespace URIs, which should be declared when generating a schema. Could be empty but never null.

getSchemaLocations

public java.util.Map<java.lang.String,java.lang.String> getSchemaLocations()
Description copied from interface: TypeInfoSet
Gets XmlSchema.location() found in this context.

This operation is expected to be only used in schema generator, so it can be slow.

Specified by:
getSchemaLocations in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
A map from namespace URI to the value of the location. If the entry is missing, that means a schema should be generated for that namespace. If the value is "", that means the schema location is implied (<xs:schema namespace="..."/> w/o schemaLocation.)

getElementFormDefault

public javax.xml.bind.annotation.XmlNsForm getElementFormDefault(java.lang.String nsUri)
Description copied from interface: TypeInfoSet
Gets the reasonable XmlNsForm for the given namespace URI.

The spec doesn't define very precisely what the XmlNsForm value for the given namespace would be, so this method is implemented in rather ad-hoc way. It should work as what most people expect for simple cases.

Specified by:
getElementFormDefault in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
never null.

getAttributeFormDefault

public javax.xml.bind.annotation.XmlNsForm getAttributeFormDefault(java.lang.String nsUri)
Description copied from interface: TypeInfoSet
Gets the reasonable XmlNsForm for the given namespace URI.

The spec doesn't define very precisely what the XmlNsForm value for the given namespace would be, so this method is implemented in rather ad-hoc way. It should work as what most people expect for simple cases.

Specified by:
getAttributeFormDefault in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
never null.

dump

public void dump(javax.xml.transform.Result out)
Description copied from interface: TypeInfoSet
Dumps this model into XML. For debug only. TODO: not sure if this actually works. We don't really know what are T,C.

Specified by:
dump in interface TypeInfoSet<NType,NClass,java.lang.Void,java.lang.Void>

getPackage

public CClassInfoParent.Package getPackage(com.sun.codemodel.JPackage pkg)