Module org.eclipse.persistence.core
Class SchemaModelGenerator
java.lang.Object
org.eclipse.persistence.internal.oxm.schema.SchemaModelGenerator
INTERNAL:
Purpose:Generate one or more EclipseLink Schema model objects based on a given list of XMLDescriptors.
Responsibilities:
- Return a Map of generated EclipseLink Schema objects based on a given list of XMLDescriptors
This class will create and populate one or more EclipseLink schema model Schema objects for a given list of EclipseLink XMLDescriptors.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSchemaModelGenerator(ConversionManager conversionManager) The default constructor.SchemaModelGenerator(ConversionManager conversionManager, boolean customSwaRefSchema) This constructor should be used with a value of 'true' when the schemaLocation attribute of the import for swaRef should be swaref.xsd. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddNamespacesToWorkingSchema(NamespaceResolver nr, Schema workingSchema) Adds each namespace in the given resolver to the schema.booleanareNamespacesEqual(String ns1, String ns2) Indicates if two namespaces are equal.protected AttributebuildAttribute(DirectMapping mapping, String schemaType) Build and return an Attribute for a given XMLDirectMapping.protected AttributebuildAttribute(XPathFragment frag, String schemaType) Build and return an Attribute for a given XPathFragment.protected ComplexTypebuildComplexType(boolean anonymous, Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Create and return a ComplexType for a given XMLDescriptor.protected ElementbuildElement(String name, String minOccurs, String maxOccurs) Build and return an Element based on a given name, minOccurs and maxOccurs.protected ElementbuildElement(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean simple) Create and return an Element for a given XMLDescriptor.protected ElementbuildElement(XPathFragment frag, String schemaType, String minOccurs, String maxOccurs) Build and return an Element for a given XPathFragment.protected SchemabuildNewSchema(String uri, NamespaceResolver nr, int schemaCount, SchemaModelGeneratorProperties properties) Create and return a new schema for the given namespace.protected SimpleTypebuildNewSimpleType(String name) Create and return a SimpleType with name set to the given name.protected SequencebuildSchemaComponentsForXPath(XPathFragment frag, Sequence seq, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) This method will build element/complexType/sequence components for a given XPath, and return the sequence that the target element of the mapping should be added to.protected SimpleTypebuildSimpleType(Descriptor desc, Schema workingSchema, boolean global) Create and return a SimpleType for a given XMLDescriptor.protected ElementelementExistsInSequence(String elementName, String refString, Sequence seq) Convenience method for determining if an element already exists in a given sequence.generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties) Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, Map<QName, Type> additionalGlobalElements) Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, SchemaModelOutputResolver outputResolver) Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, SchemaModelOutputResolver outputResolver, Map<QName, Type> additionalGlobalElements) Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.protected QNamegetDefaultRootElementAsQName(Descriptor desc, String qualifiedTableName) Return a QName representation of a qualified table name (aka default root element).protected DescriptorgetDescriptorByClass(Class<?> javaClass, List<Descriptor> descriptors) Return the descriptor from the list whose java class matches javaClass.protected DescriptorgetDescriptorByName(String javaClassName, List<Descriptor> descriptors) Return the descriptor from the list whose java class name matches javaClassName.protected SchemagetSchema(String uri, NamespaceResolver nr, HashMap<String, Schema> schemaForNamespace, SchemaModelGeneratorProperties properties) Return the Schema for a given namespace.protected StringgetSchemaTypeForDirectMapping(DirectMapping mapping, Schema workingSchema) Return the schema type for a given mapping's xmlfield.protected StringgetSchemaTypeForElement(Field xmlField, Class<?> attrClass, Schema workingSchema) Return the schema type for a given xmlfield.protected StringgetSchemaTypeString(QName schemaType, Schema workingSchema) Return the schema type as a string for a given QName and Schema.protected XPathFragmentReturn the last fragment before text() in the XPath that a given XPathFragment is part of.protected ElementhandleFragNamespace(XPathFragment frag, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, Element element, String schemaTypeString) This method will generate a global element if required (based in URI and elementFormDefault) and set a reference to it on a given element accordingly.protected ElementhandleFragNamespace(XPathFragment frag, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, Element element, ComplexType ctype, Descriptor refDesc) This method will generate a global element if required (based in URI and elementFormDefault) and set a reference to it on a given element accordingly, or set an anonymous complex type on a given element.protected booleanimportExists(Schema schema, String schemaName) Determines if a given schema contains an import for a given schema name.protected booleanIndicates if a complex type with simple content is to be generated.protected booleanisFragPrimaryKey(XPathFragment frag, DirectMapping mapping) Indicates if a given fragment is a primary key.protected booleanisSimple(Descriptor desc) Determines if a given descriptor contains a direct mapping to "text()" indicating a simple mapping.protected voidprocessAnyMapping(Sequence seq, boolean isCollection) Adds an Any to a given sequence.protected voidprocessChoiceMapping(Map<Field, Class<?>> fieldToClassMap, List<XMLChoiceFieldToClassAssociation> choiceFieldToClassList, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) Process a given XMLChoiceMapping.protected voidprocessDescriptor(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given descriptor.protected voidprocessEnumeration(String schemaTypeString, XPathFragment frag, DirectMapping mapping, Sequence seq, ComplexType ct, Schema workingSchema, CoreConverter converter) Process information contained within an EnumTypeConverter.protected voidprocessMapping(CoreMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given mapping.protected ElementprocessReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) protected voidprocessXMLBinaryDataCollectionMapping(BinaryDataCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLBinaryDataCollectionMapping.protected voidprocessXMLBinaryDataMapping(BinaryDataMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLBinaryDataMapping.protected voidprocessXMLChoiceCollectionMapping(ChoiceCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given XMLChoiceCollectionMapping.protected voidprocessXMLChoiceObjectMapping(ChoiceObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) protected voidprocessXMLCompositeDirectCollectionMapping(DirectCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLCompositeDirectCollectionMapping.protected voidprocessXMLCompositeMapping(CompositeObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean collection) Process a given XML composite mapping - either an XMLCompositeObjectMapping, or an XMLCompositeCollectionMapping.protected voidprocessXMLDirectMapping(DirectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLDirectMapping.protected voidprocessXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) Process a given XMLObjectReferenceMapping.
-
Field Details
-
SCHEMA_FILE_NAME
- See Also:
-
SCHEMA_FILE_EXT
- See Also:
-
TEXT
- See Also:
-
ID
- See Also:
-
IDREF
- See Also:
-
SWAREF_LOCATION
-
-
Constructor Details
-
SchemaModelGenerator
The default constructor. -
SchemaModelGenerator
This constructor should be used with a value of 'true' when the schemaLocation attribute of the import for swaRef should be swaref.xsd. This is useful when the user has a local copy of the swaRef schema and wants to use it when access to external URLs is not available. The default value is: "http://ws-i.org/profiles/basic/1.1/swaref.xsd".
-
-
Method Details
-
generateSchemas
public Map<String,Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, Map<QName, Type> additionalGlobalElements) throws DescriptorExceptionGenerates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors. The descriptors are assumed to have been initialized. One Schema object will be generated per namespace.- Parameters:
descriptorsToProcess- list of XMLDescriptors which will be used to generate Schema objectsproperties- holds a namespace to Properties map containing schema settings, such as elementFormDefaultadditionalGlobalElements- a map of QName-Type entries identifying additional global elements to be added- Returns:
- a map of namespaces to EclipseLink schema model Schema objects
- Throws:
DescriptorException- if the reference descriptor for a composite mapping is not in the list of descriptors- See Also:
-
generateSchemas
public Map<String,Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties) throws DescriptorException Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors. The descriptors are assumed to have been initialized. One Schema object will be generated per namespace.- Parameters:
descriptorsToProcess- list of XMLDescriptors which will be used to generate Schema objectsproperties- holds a namespace to Properties map containing schema settings, such as elementFormDefault- Returns:
- a map of namespaces to EclipseLink schema model Schema objects
- Throws:
DescriptorException- if the reference descriptor for a composite mapping is not in the list of descriptors- See Also:
-
generateSchemas
public Map<String,Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, SchemaModelOutputResolver outputResolver, Map<QName, Type> additionalGlobalElements) throws DescriptorExceptionGenerates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors. The descriptors are assumed to have been initialized. One Schema object will be generated per namespace.- Parameters:
descriptorsToProcess- list of XMLDescriptors which will be used to generate Schema objectsproperties- holds a namespace to Properties map containing schema settings, such as elementFormDefaultadditionalGlobalElements- a map of QName-Type entries identifying additional global elements to be added- Returns:
- a map of namespaces to EclipseLink schema model Schema objects
- Throws:
DescriptorException- if the reference descriptor for a composite mapping is not in the list of descriptors- See Also:
-
generateSchemas
public Map<String,Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties, SchemaModelOutputResolver outputResolver) throws DescriptorException Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors. The descriptors are assumed to have been initialized. One Schema object will be generated per namespace.- Parameters:
descriptorsToProcess- list of XMLDescriptors which will be used to generate Schema objectsproperties- holds a namespace to Properties map containing schema settings, such as elementFormDefault- Returns:
- a map of namespaces to EclipseLink schema model Schema objects
- Throws:
DescriptorException- if the reference descriptor for a composite mapping is not in the list of descriptors- See Also:
-
processDescriptor
protected void processDescriptor(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given descriptor. Global complex types will be generated for based on schema context, and global elements based on default root element. -
getSchema
protected Schema getSchema(String uri, NamespaceResolver nr, HashMap<String, Schema> schemaForNamespace, SchemaModelGeneratorProperties properties) Return the Schema for a given namespace. If one doesn't exist, a new one will be created and returned.- See Also:
-
buildElement
protected Element buildElement(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean simple) Create and return an Element for a given XMLDescriptor. -
buildSimpleType
Create and return a SimpleType for a given XMLDescriptor. -
buildNewSimpleType
Create and return a SimpleType with name set to the given name. -
buildComplexType
protected ComplexType buildComplexType(boolean anonymous, Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Create and return a ComplexType for a given XMLDescriptor. Assumes that the descriptor has a schema context set. -
getSchemaTypeForDirectMapping
Return the schema type for a given mapping's xmlfield. If the field does not have a schema type set, the attribute classification will be used if non-null. Otherwise, ClassConstants.STRING will be returned. -
getSchemaTypeForElement
Return the schema type for a given xmlfield. If the field does not have a schema type set, the attribute classification will be used if non-null. Otherwise, ClassConstants.STRING will be returned. -
getDescriptorByName
Return the descriptor from the list whose java class name matches javaClassName. If none exists null will be returned. -
getDescriptorByClass
Return the descriptor from the list whose java class matches javaClass. If none exists null will be returned. -
processAnyMapping
Adds an Any to a given sequence. If isCollection is true, maxOccurs will be set to unbounded.- See Also:
-
processXMLBinaryDataMapping
protected void processXMLBinaryDataMapping(BinaryDataMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLBinaryDataMapping. -
processXMLBinaryDataCollectionMapping
protected void processXMLBinaryDataCollectionMapping(BinaryDataCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLBinaryDataCollectionMapping. -
processXMLDirectMapping
protected void processXMLDirectMapping(DirectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLDirectMapping. -
processXMLCompositeDirectCollectionMapping
protected void processXMLCompositeDirectCollectionMapping(DirectCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) Process a given XMLCompositeDirectCollectionMapping. -
processXMLCompositeMapping
protected void processXMLCompositeMapping(CompositeObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean collection) Process a given XML composite mapping - either an XMLCompositeObjectMapping, or an XMLCompositeCollectionMapping. For XMLCompositeDirectCollectionMappings the processXMLCompositeDirectCollectionMapping method should be used. -
processXMLChoiceCollectionMapping
protected void processXMLChoiceCollectionMapping(ChoiceCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given XMLChoiceCollectionMapping. -
processXMLChoiceObjectMapping
protected void processXMLChoiceObjectMapping(ChoiceObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) -
processChoiceMapping
protected void processChoiceMapping(Map<Field, Class<?>> fieldToClassMap, List<XMLChoiceFieldToClassAssociation> choiceFieldToClassList, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) Process a given XMLChoiceMapping. -
processXMLObjectReferenceMapping
protected void processXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) Process a given XMLObjectReferenceMapping. In the case of an XMLCollectionReferenceMapping, i.e. the isCollection flag is set to true, maxOccurs will be set to 'unbounded' on any source elements -
processMapping
protected void processMapping(CoreMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) Process a given mapping. -
handleFragNamespace
protected Element handleFragNamespace(XPathFragment frag, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, Element element, String schemaTypeString) This method will generate a global element if required (based in URI and elementFormDefault) and set a reference to it on a given element accordingly. This method will typically be used for direct mappings. -
handleFragNamespace
protected Element handleFragNamespace(XPathFragment frag, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, Element element, ComplexType ctype, Descriptor refDesc) This method will generate a global element if required (based in URI and elementFormDefault) and set a reference to it on a given element accordingly, or set an anonymous complex type on a given element. This method will typically be used by composite mappings. -
getTargetXPathFragment
Return the last fragment before text() in the XPath that a given XPathFragment is part of. -
buildSchemaComponentsForXPath
protected Sequence buildSchemaComponentsForXPath(XPathFragment frag, Sequence seq, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) This method will build element/complexType/sequence components for a given XPath, and return the sequence that the target element of the mapping should be added to. For example, if the XPath was "contact-info/address/street/text()", street would be the target. This method defers processing of the target path element to the calling method, allowing for differences in handling, such as direct mappings versus composite mappings, etc. -
buildAttribute
Build and return an Attribute for a given XMLDirectMapping. -
buildAttribute
Build and return an Attribute for a given XPathFragment. -
buildElement
protected Element buildElement(XPathFragment frag, String schemaType, String minOccurs, String maxOccurs) Build and return an Element for a given XPathFragment. -
buildElement
Build and return an Element based on a given name, minOccurs and maxOccurs. -
areNamespacesEqual
Indicates if two namespaces are equal. The result is TRUE if the two URI strings are equal according to the equals() method, if one is null and the other is "", or both are null. -
getSchemaTypeString
Return the schema type as a string for a given QName and Schema. The schema's namespace resolver will be used to determine the prefix (if any) to use. -
addNamespacesToWorkingSchema
Adds each namespace in the given resolver to the schema. -
buildNewSchema
protected Schema buildNewSchema(String uri, NamespaceResolver nr, int schemaCount, SchemaModelGeneratorProperties properties) Create and return a new schema for the given namespace. ElementFormDefault and AttributeFormDefault can be set via SchemaModelGeneratorProperties object. The namespace resolver's default namespace will be set if non-null. -
importExists
Determines if a given schema contains an import for a given schema name. -
getDefaultRootElementAsQName
Return a QName representation of a qualified table name (aka default root element). The given descriptor's namespace resolver will be used to determine the correct prefix - if any - to be used. -
processReferenceDescriptor
protected Element processReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) -
elementExistsInSequence
Convenience method for determining if an element already exists in a given sequence. If an element exists whose name is equal to 'elementName' true is returned. False otherwise. -
isSimple
Determines if a given descriptor contains a direct mapping to "text()" indicating a simple mapping. In this case, a simple type or complex type with simple content will be generated -
isComplexTypeWithSimpleContentRequired
Indicates if a complex type with simple content is to be generated. This is true when the given descriptor has more than one mapping. It is assumed that isSimple(desc) will return true for the given descriptor, and that the descriptor will contain at most one direct with a 'text()' xpath, and any additional mappings are attribute mappings. -
processEnumeration
protected void processEnumeration(String schemaTypeString, XPathFragment frag, DirectMapping mapping, Sequence seq, ComplexType ct, Schema workingSchema, CoreConverter converter) Process information contained within an EnumTypeConverter. This will generate a simple type containing enumeration info. -
isFragPrimaryKey
Indicates if a given fragment is a primary key.
-