Top Description Fields Constructors Methods
com.sun.tools.xjc.reader.xmlschema

public final Class SimpleTypeBuilder

extends BindingComponent
Class Inheritance
Imports
java.io.StringWriter, java.math.BigInteger, java.text.ParseException, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .List, .Map, .Set, .Stack, com.sun.codemodel.util.Util, jakarta.activation.MimeTypeParseException, jakarta.xml.bind.DatatypeConverter, com.sun.codemodel.JJavaName, org.glassfish.jaxb.core.v2.WellKnownNamespace, com.sun.tools.xjc.ErrorReceiver, com.sun.tools.xjc.model.CBuiltinLeafInfo, .CClassInfo, .CClassInfoParent, .CClassRef, .CEnumConstant, .CEnumLeafInfo, .CNonElement, .Model, .TypeUse, .TypeUseFactory, com.sun.tools.xjc.reader.Const, .Ring, com.sun.tools.xjc.reader.xmlschema.bindinfo.BIConversion, .BIEnum, .BIEnumMember, .BIProperty, .BindInfo, .EnumMemberMode, com.sun.tools.xjc.util.MimeTypeRange, org.glassfish.jaxb.core.v2.runtime.SwaRefAdapterMarker, com.sun.xml.xsom.XSAttributeDecl, .XSComplexType, .XSComponent, .XSElementDecl, .XSFacet, .XSListSimpleType, .XSRestrictionSimpleType, .XSSimpleType, .XSUnionSimpleType, .XSVariety, com.sun.xml.xsom.impl.util.SchemaWriter, com.sun.xml.xsom.visitor.XSSimpleTypeFunction, .XSVisitor, org.xml.sax.Locator, javax.xml.XMLConstants

Builds TypeUse from simple types.

This code consists of two main portions. The compose(XSSimpleType) method and composer forms an outer cycle, which gradually ascends the type inheritance chain until it finds the suitable binding. When it does this initiatingType is set to the type which started binding, so that we can refer to the actual constraint facets and such that are applicable on the type.

For each intermediate type in the chain, the find(XSSimpleType) method is used to find the binding on that type, sine the outer loop is doing the ascending, this method only sees if the current type has some binding available.

There is at least one ugly code that you need to aware of when you are modifying the code. See the documentation about "simple type customization at the point of reference."

Author
Kohsuke Kawaguchi ([email protected])

Field Summary

Modifier and TypeField and Description
private final Set<XSComponent>
acknowledgedXmimeContentTypes

Records what xmime:expectedContentTypes annotations we honored and processed, so that we can later check if the user had these annotations in the places where we didn't anticipate them.

protected final BGMBuilder
public static final Map<String, TypeUse>
builtinConversions

TypeUses for the built-in types.

private static final Set<String>
public final XSSimpleTypeFunction<TypeUse>
private XSSimpleType
initiatingType

The type that was originally passed to this SimpleTypeBuilder#build(XSSimpleType).

private static final BigInteger
private static final BigInteger
private static final BigInteger
private static final BigInteger
private final Model
public final Stack<XSComponent>
refererStack

The component that is refering to the simple type which we are building.

private static Set<XSRestrictionSimpleType>

Constructor Summary

AccessConstructor and Description
public
SimpleTypeBuilder()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
private TypeUse
bindToTypeSafeEnum(XSRestrictionSimpleType type, String
The class name of the type-safe enum. Or null to create a default name.
className
,
String
Additional javadoc that will be added at the beginning of the class, or null if none is necessary.
javadoc
,
Map<String, BIEnumMember>
A map from enumeration values (as String) to BIEnumMember objects. if some of the value names need to be overrided. Cannot be null, but the map may not contain entries for all enumeration values.
members
,
EnumMemberMode mode, Locator
The source location where the above customizations are specified, or null if none is available.
loc
)

Builds a type-safe enum conversion from a simple type with enumeration facets.

public TypeUse
build(XSSimpleType
the simple type to be bound.
type
)

Entry point from outside.

private List<CEnumConstant>
buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[]
if constant names couldn't be generated, return a reference to that enum facet.
errorRef
)

Returns: null if unable to generate names for some of the constants.

public TypeUse
buildDef(XSSimpleType type)

A version of the build(XSSimpleType) method used to bind the definition of a class generated from the given simple type.

public static boolean
canBeMappedToTypeSafeEnum(XSSimpleType type)

Returns true if the given simple type can be mapped to a type-safe enum class.

private CEnumConstant[]

Returns:

if there's a collision, return two CEnumConstants that collided. otherwise return null.
checkMemberNameCollision
(List<CEnumConstant> memberList)

Returns non-null if CEnumConstants have name collisions among them.

private TypeUse
checkRefererCustomization(XSSimpleType type)

Checks if the referer has a conversion customization or not.

pack-priv TypeUse
compose(XSSimpleType t)

Recursively decend the type inheritance chain to find a binding.

private void
detectJavaTypeCustomization()

Detect "javaType" customizations placed directly on simple types, rather than being enclosed by "property" and "baseType" customizations (see sec 6.8.1 of the spec).

private TypeUse

Returns:

null if not (which causes the compose(XSSimpleType) method to do ascending.
find
(XSSimpleType type)

Checks if there's any binding available on the given type.

private EnumMemberMode
public XSComponent
private BIConversion

Returns:

can be null.
getRefererCustomization
()

Returns a javaType customization specified to the referer, if present.

public boolean
private boolean
isRestrictedTo0And1()

Returns true if the initiatingType is restricted to '0' and '1'.

private boolean
isXml(String subType)

Returns true if the specified sub-type is an XML type.

private TypeUse
lookupBinaryTypeBinding()

Decides the way xs:base64Binary binds.

private TypeUse
lookupBuiltin(String typeLocalName)

private BigInteger
private BigInteger
private BigInteger
readFacet(String facetName, int offset)

private boolean
shouldBeMappedToTypeSafeEnumByDefault(XSRestrictionSimpleType type)

Returns true if a type-safe enum should be created from the given simple type by default without an explicit <jaxb:enum> customization.

Inherited from com.sun.tools.xjc.reader.xmlschema.BindingComponent:
getClassSelectorgetErrorReporter

Field Detail

acknowledgedXmimeContentTypesback to summary
private final Set<XSComponent> acknowledgedXmimeContentTypes

Records what xmime:expectedContentTypes annotations we honored and processed, so that we can later check if the user had these annotations in the places where we didn't anticipate them.

builderback to summary
protected final BGMBuilder builder
builtinConversionsback to summary
public static final Map<String, TypeUse> builtinConversions

TypeUses for the built-in types. Read-only.

builtinTypeSafeEnumCapableTypesback to summary
private static final Set<String> builtinTypeSafeEnumCapableTypes
composerback to summary
public final XSSimpleTypeFunction<TypeUse> composer
initiatingTypeback to summary
private XSSimpleType initiatingType

The type that was originally passed to this SimpleTypeBuilder#build(XSSimpleType). Never null.

INT_MAXback to summary
private static final BigInteger INT_MAX
INT_MINback to summary
private static final BigInteger INT_MIN
LONG_MAXback to summary
private static final BigInteger LONG_MAX
LONG_MINback to summary
private static final BigInteger LONG_MIN
modelback to summary
private final Model model
refererStackback to summary
public final Stack<XSComponent> refererStack

The component that is refering to the simple type which we are building. This is ugly but necessary to support the customization of simple types at its point of reference. See my comment at the header of this class for details. UGLY: Implemented as a Stack of XSComponent to fix a bug

reportedEnumMemberSizeWarningsback to summary
private static Set<XSRestrictionSimpleType> reportedEnumMemberSizeWarnings

Constructor Detail

SimpleTypeBuilderback to summary
public SimpleTypeBuilder()

Default constructor.

Method Detail

bindToTypeSafeEnumback to summary
private TypeUse bindToTypeSafeEnum(XSRestrictionSimpleType type, String className, String javadoc, Map<String, BIEnumMember> members, EnumMemberMode mode, Locator loc)

Builds a type-safe enum conversion from a simple type with enumeration facets.

Parameters
className:String

The class name of the type-safe enum. Or null to create a default name.

javadoc:String

Additional javadoc that will be added at the beginning of the class, or null if none is necessary.

members:Map<String, BIEnumMember>

A map from enumeration values (as String) to BIEnumMember objects. if some of the value names need to be overrided. Cannot be null, but the map may not contain entries for all enumeration values.

loc:Locator

The source location where the above customizations are specified, or null if none is available.

buildback to summary
public TypeUse build(XSSimpleType type)

Entry point from outside. Builds a BGM type expression from a simple type schema component.

Parameters
type:XSSimpleType

the simple type to be bound.

buildCEnumConstantsback to summary
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef)
Parameters
errorRef:XSFacet[]

if constant names couldn't be generated, return a reference to that enum facet.

Returns:List<CEnumConstant>

null if unable to generate names for some of the constants.

buildDefback to summary
public TypeUse buildDef(XSSimpleType type)

A version of the build(XSSimpleType) method used to bind the definition of a class generated from the given simple type.

canBeMappedToTypeSafeEnumback to summary
public static boolean canBeMappedToTypeSafeEnum(XSSimpleType type)

Returns true if the given simple type can be mapped to a type-safe enum class.

JAXB spec places a restrictrion as to what type can be mapped to a type-safe enum. This method enforces this constraint.

checkMemberNameCollisionback to summary
private CEnumConstant[] checkMemberNameCollision(List<CEnumConstant> memberList)

Returns non-null if CEnumConstants have name collisions among them.

Returns:CEnumConstant[]

if there's a collision, return two CEnumConstants that collided. otherwise return null.

checkRefererCustomizationback to summary
private TypeUse checkRefererCustomization(XSSimpleType type)

Checks if the referer has a conversion customization or not. If it does, use it to bind this simple type. Otherwise return null;

composeback to summary
pack-priv TypeUse compose(XSSimpleType t)

Recursively decend the type inheritance chain to find a binding.

detectJavaTypeCustomizationback to summary
private void detectJavaTypeCustomization()

Detect "javaType" customizations placed directly on simple types, rather than being enclosed by "property" and "baseType" customizations (see sec 6.8.1 of the spec). Report an error if any exist.

findback to summary
private TypeUse find(XSSimpleType type)

Checks if there's any binding available on the given type.

Returns:TypeUse

null if not (which causes the compose(XSSimpleType) method to do ascending.

getEnumMemberModeback to summary
private EnumMemberMode getEnumMemberMode()
getRefererback to summary
public XSComponent getReferer()
getRefererCustomizationback to summary
private BIConversion getRefererCustomization()

Returns a javaType customization specified to the referer, if present.

Returns:BIConversion

can be null.

isAcknowledgedXmimeContentTypesback to summary
public boolean isAcknowledgedXmimeContentTypes(XSComponent c)
isRestrictedTo0And1back to summary
private boolean isRestrictedTo0And1()

Returns true if the initiatingType is restricted to '0' and '1'. This logic is not complete, but it at least finds the such definition in SOAP @mustUnderstand.

isXmlback to summary
private boolean isXml(String subType)

Returns true if the specified sub-type is an XML type.

lookupBinaryTypeBindingback to summary
private TypeUse lookupBinaryTypeBinding()

Decides the way xs:base64Binary binds. This method checks the expected media type.

lookupBuiltinback to summary
private TypeUse lookupBuiltin(String typeLocalName)
maxback to summary
private BigInteger max(BigInteger a, BigInteger b)
minback to summary
private BigInteger min(BigInteger a, BigInteger b)
readFacetback to summary
private BigInteger readFacet(String facetName, int offset)
shouldBeMappedToTypeSafeEnumByDefaultback to summary
private boolean shouldBeMappedToTypeSafeEnumByDefault(XSRestrictionSimpleType type)

Returns true if a type-safe enum should be created from the given simple type by default without an explicit <jaxb:enum> customization.