Search in sources :

Example 1 with All

use of org.eclipse.persistence.internal.oxm.schema.model.All in project eclipselink by eclipse-ee4j.

the class SchemaGenerator method addToSchemaType.

public void addToSchemaType(TypeInfo ownerTypeInfo, java.util.List<Property> properties, TypeDefParticle compositor, ComplexType type, Schema workingSchema) {
    // If there are no properties we don't want a sequence/choice or all tag written out
    if (properties.size() == 0) {
        type.setAll(null);
        type.setSequence(null);
        type.setChoice(null);
        ownerTypeInfo.setCompositor(null);
        return;
    }
    boolean extAnyAdded = false;
    // generate schema components for each property
    for (Property next : properties) {
        if (next == null) {
            continue;
        }
        Schema currentSchema = workingSchema;
        TypeDefParticle parentCompositor = compositor;
        boolean isChoice = (parentCompositor instanceof Choice);
        ComplexType parentType = type;
        // ignore transient and inverse reference/non-writeable properties
        if (!next.isTransient() && !(next.isInverseReference() && !next.isWriteableInverseReference())) {
            // handle xml extensions
            if (next.isVirtual()) {
                boolean extSchemaAny = false;
                if (ownerTypeInfo.getXmlVirtualAccessMethods().getSchema() != null) {
                    extSchemaAny = ownerTypeInfo.getXmlVirtualAccessMethods().getSchema().equals(XmlVirtualAccessMethodsSchema.ANY);
                }
                if (extSchemaAny && !next.isAttribute()) {
                    if (!extAnyAdded) {
                        addAnyToSchema(next, compositor, true, Constants.ANY_NAMESPACE_ANY);
                        extAnyAdded = true;
                        continue;
                    } else {
                        // any already added
                        continue;
                    }
                } else {
                // proceed, adding the schema element as usual
                }
            }
            // handle transformers
            if (next.isSetXmlTransformation() && next.getXmlTransformation().isSetXmlWriteTransformers()) {
                addTransformerToSchema(next, ownerTypeInfo, compositor, type, workingSchema);
                continue;
            }
            // handle XmlJoinNodes
            if (next.isSetXmlJoinNodes()) {
                addXmlJoinNodesToSchema(next, parentCompositor, currentSchema, parentType);
                continue;
            }
            // deal with xml-path case
            if (next.getXmlPath() != null) {
                // create schema components based on the XmlPath
                AddToSchemaResult xpr = addXPathToSchema(next, parentCompositor, currentSchema, isChoice, type);
                // if the returned object or schema component is null there is nothing to do
                if (xpr == null || ((parentCompositor = xpr.particle) == null && xpr.simpleContentType == null)) {
                    continue;
                }
                // now process the property as per usual, adding to the created schema component
                if (xpr.schema == null) {
                    // no need to generate the attribute in the target schema
                    continue;
                }
                currentSchema = xpr.schema;
                if (parentCompositor == null) {
                    parentType = xpr.simpleContentType;
                } else if (parentCompositor.getOwner() instanceof ComplexType) {
                    parentType = ((ComplexType) parentCompositor.getOwner());
                }
            // deal with the XmlElementWrapper case
            } else if (!isChoice && !next.isMap() && next.isSetXmlElementWrapper()) {
                AddToSchemaResult asr = addXmlElementWrapperToSchema(next, currentSchema, compositor);
                // if returned object is null there is nothing to do
                if (asr == null) {
                    continue;
                }
                // the returned object contains ComplexType and TypeDefParticles to use
                parentType = asr.type;
                parentCompositor = asr.particle;
            }
            // handle mixed content
            if (next.isMixedContent()) {
                parentType.setMixed(true);
            }
            // handle attribute
            if (next.isAttribute() && !next.isAnyAttribute()) {
                addAttributeToSchema(buildAttribute(next, currentSchema), next.getSchemaName(), currentSchema, parentType);
            // handle any attribute
            } else if (next.isAnyAttribute()) {
                addAnyAttributeToSchema(parentType);
            // handle choice
            } else if (next.isChoice()) {
                addChoiceToSchema(next, ownerTypeInfo, parentType, parentCompositor, currentSchema);
            // handle reference
            } else if (next.isReference()) {
                addReferenceToSchema(next, currentSchema, parentCompositor);
            // handle any
            } else if (next.isAny() || next.getVariableAttributeName() != null) {
                addAnyToSchema(next, parentCompositor);
            // add an element
            } else if (!(ownerTypeInfo.getXmlValueProperty() != null && ownerTypeInfo.getXmlValueProperty() == next)) {
                Element element = buildElement(next, parentCompositor instanceof All, currentSchema, ownerTypeInfo);
                addElementToSchema(element, next.getSchemaName().getNamespaceURI(), next.isPositional(), parentCompositor, currentSchema, ownerTypeInfo.getJavaClass().getPackageName());
            }
        }
    }
}
Also used : All(org.eclipse.persistence.internal.oxm.schema.model.All) TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 2 with All

use of org.eclipse.persistence.internal.oxm.schema.model.All in project eclipselink by eclipse-ee4j.

the class SchemaGenerator method createComplexTypeForClass.

private ComplexType createComplexTypeForClass(JavaClass myClass, TypeInfo info) {
    Schema schema = getSchemaForNamespace(info.getClassNamespace());
    ComplexType type = new ComplexType();
    JavaClass superClass = CompilerHelper.getNextMappedSuperClass(myClass, this.typeInfo, this.helper);
    // Handle abstract class
    if (myClass.isAbstract()) {
        type.setAbstractValue(true);
    }
    Extension extension = null;
    if (superClass != null) {
        TypeInfo parentTypeInfo = this.typeInfo.get(superClass.getQualifiedName());
        if (parentTypeInfo != null) {
            extension = new Extension();
            // may need to qualify the type
            String parentPrefix = getPrefixForNamespace(schema, parentTypeInfo.getClassNamespace());
            if (parentPrefix != null) {
                extension.setBaseType(parentPrefix + COLON + parentTypeInfo.getSchemaTypeName());
            } else {
                extension.setBaseType(parentTypeInfo.getSchemaTypeName());
            }
            if (parentTypeInfo.getXmlValueProperty() != null) {
                SimpleContent content = new SimpleContent();
                content.setExtension(extension);
                type.setSimpleContent(content);
                return type;
            } else {
                ComplexContent content = new ComplexContent();
                content.setExtension(extension);
                type.setComplexContent(content);
            }
        }
    }
    TypeDefParticle compositor = null;
    String[] propOrder = null;
    if (info.isSetPropOrder()) {
        propOrder = info.getPropOrder();
    }
    if (propOrder != null && propOrder.length == 0) {
        // requires the extension case to use sequences
        if (info.hasElementRefs()) {
            // generate a sequence to satisfy TCK
            compositor = new Sequence();
            if (extension != null) {
                extension.setSequence((Sequence) compositor);
            } else {
                type.setSequence((Sequence) compositor);
            }
        } else if (extension != null) {
            compositor = new All();
            extension.setAll((All) compositor);
        } else {
            compositor = new All();
            type.setAll((All) compositor);
        }
    } else {
        // generate a sequence to satisfy TCK
        compositor = new Sequence();
        if (extension != null) {
            extension.setSequence((Sequence) compositor);
        } else {
            type.setSequence((Sequence) compositor);
        }
    }
    return type;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) All(org.eclipse.persistence.internal.oxm.schema.model.All) TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexContent(org.eclipse.persistence.internal.oxm.schema.model.ComplexContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 3 with All

use of org.eclipse.persistence.internal.oxm.schema.model.All in project eclipselink by eclipse-ee4j.

the class SchemaGenerator method addXmlJoinNodesToSchema.

/**
 * Convenience method that processes the XmlJoinNodes for a given Property and adds the
 * appropriate components to the schema.
 *
 * @param property the Property contianing one or more XmlJoinNode entries
 * @param compositor the sequence/choice/all that will be added to
 * @param schema the schema currently being built
 * @param type the complex type currently being built
 */
private void addXmlJoinNodesToSchema(Property property, TypeDefParticle compositor, Schema schema, ComplexType type) {
    for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
        // create the XPathFragment(s) for the path
        Field<XMLConversionManager, NamespaceResolver> xfld = new XMLField(xmlJoinNode.getXmlPath());
        xfld.setNamespaceResolver(schema.getNamespaceResolver());
        xfld.initialize();
        // build the schema components for the xml-path
        AddToSchemaResult asr = buildSchemaComponentsForXPath(xfld.getXPathFragment(), new AddToSchemaResult(compositor, schema), false, property);
        // process the last fragment
        TypeDefParticle currentParticle = asr.particle;
        Schema currentSchema = asr.schema;
        if (currentParticle.getOwner() instanceof ComplexType) {
            type = ((ComplexType) currentParticle.getOwner());
        }
        // get a QName for the last part of the xpath - this will be used as the
        // attribute/element name, and also to figure out if a ref is required
        QName schemaName;
        XPathFragment frag = xfld.getLastXPathFragment();
        boolean isAttribute = xmlJoinNode.getXmlPath().contains(ATT);
        // for non-attributes, the last fragment may be 'text()'
        if (!isAttribute) {
            if (frag.nameIsText()) {
                frag = xfld.getXPathFragment();
                while (frag.getNextFragment() != null && !frag.getNextFragment().nameIsText()) {
                    frag = frag.getNextFragment();
                }
            }
        }
        schemaName = new QName(frag.getNamespaceURI(), frag.getLocalName());
        // handle Element/Attribute
        if (isAttribute) {
            addAttributeToSchema(buildAttribute(schemaName, Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE), schemaName, currentSchema, type);
        } else {
            addElementToSchema(buildElement(schemaName.getLocalPart(), Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE, currentParticle instanceof All), schemaName.getNamespaceURI(), false, currentParticle, currentSchema, null);
        }
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) All(org.eclipse.persistence.internal.oxm.schema.model.All) TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) QName(javax.xml.namespace.QName) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

All (org.eclipse.persistence.internal.oxm.schema.model.All)3 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)3 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)3 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)3 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)3 QName (javax.xml.namespace.QName)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)1 Choice (org.eclipse.persistence.internal.oxm.schema.model.Choice)1 ComplexContent (org.eclipse.persistence.internal.oxm.schema.model.ComplexContent)1 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)1 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)1 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)1 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 XmlJoinNode (org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1 XMLField (org.eclipse.persistence.oxm.XMLField)1