Class SchemaModelGenerator


  • public class SchemaModelGenerator
    extends java.lang.Object
    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:
    Schema, XMLDescriptor
    • Constructor Detail

      • SchemaModelGenerator

        public SchemaModelGenerator​(ConversionManager conversionManager)
        The default constructor.
      • SchemaModelGenerator

        public 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. 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 Detail

      • generateSchemas

        public java.util.Map<java.lang.String,​Schema> generateSchemas​(java.util.List<Descriptor> descriptorsToProcess,
                                                                            SchemaModelGeneratorProperties properties,
                                                                            java.util.Map<javax.xml.namespace.QName,​java.lang.reflect.Type> additionalGlobalElements)
                                                                     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 objects
        properties - holds a namespace to Properties map containing schema settings, such as elementFormDefault
        additionalGlobalElements - 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:
        Schema
      • generateSchemas

        public java.util.Map<java.lang.String,​Schema> generateSchemas​(java.util.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 objects
        properties - 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:
        Schema
      • generateSchemas

        public java.util.Map<java.lang.String,​Schema> generateSchemas​(java.util.List<Descriptor> descriptorsToProcess,
                                                                            SchemaModelGeneratorProperties properties,
                                                                            SchemaModelOutputResolver outputResolver,
                                                                            java.util.Map<javax.xml.namespace.QName,​java.lang.reflect.Type> additionalGlobalElements)
                                                                     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 objects
        properties - holds a namespace to Properties map containing schema settings, such as elementFormDefault
        additionalGlobalElements - 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:
        Schema
      • generateSchemas

        public java.util.Map<java.lang.String,​Schema> generateSchemas​(java.util.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 objects
        properties - 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:
        Schema
      • processDescriptor

        protected void processDescriptor​(Descriptor desc,
                                         java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                         Schema workingSchema,
                                         SchemaModelGeneratorProperties properties,
                                         java.util.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.
        Parameters:
        desc -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
      • getSchema

        protected Schema getSchema​(java.lang.String uri,
                                   NamespaceResolver nr,
                                   java.util.HashMap<java.lang.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.
        Parameters:
        uri -
        nr -
        schemaForNamespace -
        properties -
        Returns:
        See Also:
        Schema
      • buildElement

        protected Element buildElement​(Descriptor desc,
                                       java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                       Schema workingSchema,
                                       SchemaModelGeneratorProperties properties,
                                       java.util.List<Descriptor> descriptors,
                                       boolean simple)
        Create and return an Element for a given XMLDescriptor.
        Parameters:
        desc -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        simple -
        Returns:
      • buildSimpleType

        protected SimpleType buildSimpleType​(Descriptor desc,
                                             Schema workingSchema,
                                             boolean global)
        Create and return a SimpleType for a given XMLDescriptor.
        Parameters:
        desc -
        workingSchema -
        Returns:
      • buildNewSimpleType

        protected SimpleType buildNewSimpleType​(java.lang.String name)
        Create and return a SimpleType with name set to the given name.
        Parameters:
        name -
        Returns:
      • buildComplexType

        protected ComplexType buildComplexType​(boolean anonymous,
                                               Descriptor desc,
                                               java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                               Schema workingSchema,
                                               SchemaModelGeneratorProperties properties,
                                               java.util.List<Descriptor> descriptors)
        Create and return a ComplexType for a given XMLDescriptor. Assumes that the descriptor has a schema context set.
        Parameters:
        anonymous -
        desc -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        Returns:
      • getSchemaTypeForDirectMapping

        protected java.lang.String getSchemaTypeForDirectMapping​(DirectMapping mapping,
                                                                 Schema workingSchema)
        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.
        Parameters:
        mapping -
        workingSchema -
        Returns:
      • getSchemaTypeForElement

        protected java.lang.String getSchemaTypeForElement​(Field xmlField,
                                                           java.lang.Class attrClass,
                                                           Schema workingSchema)
        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.
        Parameters:
        xmlField -
        attrClass -
        workingSchema -
        Returns:
      • getDescriptorByName

        protected Descriptor getDescriptorByName​(java.lang.String javaClassName,
                                                 java.util.List<Descriptor> descriptors)
        Return the descriptor from the list whose java class name matches javaClassName. If none exists null will be returned.
        Parameters:
        javaClassName -
        descriptors -
        Returns:
      • getDescriptorByClass

        protected Descriptor getDescriptorByClass​(java.lang.Class javaClass,
                                                  java.util.List<Descriptor> descriptors)
        Return the descriptor from the list whose java class matches javaClass. If none exists null will be returned.
        Parameters:
        javaClass -
        descriptors -
        Returns:
      • processAnyMapping

        protected void processAnyMapping​(Sequence seq,
                                         boolean isCollection)
        Adds an Any to a given sequence. If isCollection is true, maxOccurs will be set to unbounded.
        Parameters:
        seq -
        isCollection -
        See Also:
        Any, Occurs.UNBOUNDED
      • processXMLCompositeMapping

        protected void processXMLCompositeMapping​(CompositeObjectMapping mapping,
                                                  Sequence seq,
                                                  ComplexType ct,
                                                  java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                                  Schema workingSchema,
                                                  SchemaModelGeneratorProperties properties,
                                                  java.util.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.
        Parameters:
        mapping -
        seq -
        ct -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        collection -
      • processXMLChoiceCollectionMapping

        protected void processXMLChoiceCollectionMapping​(ChoiceCollectionMapping mapping,
                                                         Sequence seq,
                                                         ComplexType ct,
                                                         java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                                         Schema workingSchema,
                                                         SchemaModelGeneratorProperties properties,
                                                         java.util.List<Descriptor> descriptors)
        Process a given XMLChoiceCollectionMapping.
        Parameters:
        mapping -
        seq -
        ct -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
      • processChoiceMapping

        protected void processChoiceMapping​(java.util.Map<Field,​java.lang.Class> fieldToClassMap,
                                            java.util.List<XMLChoiceFieldToClassAssociation> choiceFieldToClassList,
                                            Sequence seq,
                                            ComplexType ct,
                                            java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                            Schema workingSchema,
                                            SchemaModelGeneratorProperties properties,
                                            java.util.List<Descriptor> descriptors,
                                            boolean isCollection)
        Process a given XMLChoiceMapping.
        Parameters:
        fieldToClassMap -
        choiceFieldToClassList -
        seq -
        ct -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        isCollection -
      • processXMLObjectReferenceMapping

        protected void processXMLObjectReferenceMapping​(ObjectReferenceMapping mapping,
                                                        Sequence seq,
                                                        ComplexType ct,
                                                        java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                                        Schema workingSchema,
                                                        SchemaModelGeneratorProperties properties,
                                                        java.util.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
        Parameters:
        mapping -
        seq -
        ct -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        isCollection -
      • handleFragNamespace

        protected Element handleFragNamespace​(XPathFragment frag,
                                              java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                              Schema workingSchema,
                                              SchemaModelGeneratorProperties properties,
                                              Element element,
                                              java.lang.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.
        Parameters:
        frag -
        schemaForNamespace -
        workingSchema -
        properties -
        element -
        schemaTypeString -
        Returns:
      • handleFragNamespace

        protected Element handleFragNamespace​(XPathFragment frag,
                                              java.util.HashMap<java.lang.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.
        Parameters:
        frag -
        schemaForNamespace -
        workingSchema -
        properties -
        element -
        ctype -
        refDesc -
      • getTargetXPathFragment

        protected XPathFragment getTargetXPathFragment​(XPathFragment frag)
        Return the last fragment before text() in the XPath that a given XPathFragment is part of.
        Parameters:
        frag -
        Returns:
      • buildSchemaComponentsForXPath

        protected Sequence buildSchemaComponentsForXPath​(XPathFragment frag,
                                                         Sequence seq,
                                                         java.util.HashMap<java.lang.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.
        Parameters:
        frag -
        seq -
        Returns:
      • buildAttribute

        protected Attribute buildAttribute​(DirectMapping mapping,
                                           java.lang.String schemaType)
        Build and return an Attribute for a given XMLDirectMapping.
        Parameters:
        mapping -
        schemaType -
        Returns:
      • buildAttribute

        protected Attribute buildAttribute​(XPathFragment frag,
                                           java.lang.String schemaType)
        Build and return an Attribute for a given XPathFragment.
        Parameters:
        mapping -
        schemaType -
        Returns:
      • buildElement

        protected Element buildElement​(XPathFragment frag,
                                       java.lang.String schemaType,
                                       java.lang.String minOccurs,
                                       java.lang.String maxOccurs)
        Build and return an Element for a given XPathFragment.
        Parameters:
        frag -
        schemaType -
        minOccurs -
        maxOccurs -
        Returns:
      • buildElement

        protected Element buildElement​(java.lang.String name,
                                       java.lang.String minOccurs,
                                       java.lang.String maxOccurs)
        Build and return an Element based on a given name, minOccurs and maxOccurs.
        Parameters:
        name -
        minOccurs -
        maxOccurs -
        Returns:
      • areNamespacesEqual

        public boolean areNamespacesEqual​(java.lang.String ns1,
                                          java.lang.String ns2)
        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.
        Parameters:
        uri -
        defaultNS -
        Returns:
      • getSchemaTypeString

        protected java.lang.String getSchemaTypeString​(javax.xml.namespace.QName schemaType,
                                                       Schema workingSchema)
        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.
        Parameters:
        schemaType -
        workingSchema -
        Returns:
      • addNamespacesToWorkingSchema

        protected void addNamespacesToWorkingSchema​(NamespaceResolver nr,
                                                    Schema workingSchema)
        Adds each namespace in the given resolver to the schema.
        Parameters:
        nr -
        workingSchema -
      • buildNewSchema

        protected Schema buildNewSchema​(java.lang.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.
        Parameters:
        uri -
        nr -
        schemaCount -
        properties -
        Returns:
      • importExists

        protected boolean importExists​(Schema schema,
                                       java.lang.String schemaName)
        Determines if a given schema contains an import for a given schema name.
        Parameters:
        schema -
        schemaName -
        Returns:
      • getDefaultRootElementAsQName

        protected javax.xml.namespace.QName getDefaultRootElementAsQName​(Descriptor desc,
                                                                         java.lang.String qualifiedTableName)
        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.
        Parameters:
        desc -
        qualifiedTableName -
        Returns:
      • processReferenceDescriptor

        protected Element processReferenceDescriptor​(Element element,
                                                     Descriptor refDesc,
                                                     java.util.HashMap<java.lang.String,​Schema> schemaForNamespace,
                                                     Schema workingSchema,
                                                     SchemaModelGeneratorProperties properties,
                                                     java.util.List<Descriptor> descriptors,
                                                     Field field,
                                                     boolean isCollection)
        Parameters:
        element -
        refDesc -
        schemaForNamespace -
        workingSchema -
        properties -
        descriptors -
        field -
        isCollection -
        Returns:
      • elementExistsInSequence

        protected Element elementExistsInSequence​(java.lang.String elementName,
                                                  java.lang.String refString,
                                                  Sequence seq)
        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.
        Parameters:
        elementName -
        seq -
        Returns:
      • isSimple

        protected boolean isSimple​(Descriptor desc)
        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
        Parameters:
        desc -
        Returns:
      • isComplexTypeWithSimpleContentRequired

        protected boolean isComplexTypeWithSimpleContentRequired​(Descriptor desc)
        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.
        Parameters:
        desc -
        Returns:
      • processEnumeration

        protected void processEnumeration​(java.lang.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.
        Parameters:
        schemaTypeString -
        frag -
        mapping -
        seq -
        ct -
        workingSchema -
        converter -
      • isFragPrimaryKey

        protected boolean isFragPrimaryKey​(XPathFragment frag,
                                           DirectMapping mapping)
        Indicates if a given fragment is a primary key.
        Parameters:
        frag -
        mapping -
        Returns: