Search in sources :

Example 6 with Sequence

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

the class SchemaModelGenerator method buildSchemaComponentsForXPath.

/**
 * 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.
 */
protected Sequence buildSchemaComponentsForXPath(XPathFragment frag, Sequence seq, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    // the mapping will handle processing of the target fragment; return the sequence it will be added to
    if (frag.getNextFragment() == null || frag.getNextFragment().nameIsText()) {
        return seq;
    }
    Sequence currentSequence = seq;
    // if the current element exists, use it; otherwise create a new one
    Element currentElement = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), currentSequence);
    boolean currentElementExists = (currentElement != null);
    if (currentElement == null) {
        currentElement = new Element();
        // don't set the element name yet, as it may end up being a ref
        ComplexType cType = new ComplexType();
        Sequence sequence = new Sequence();
        cType.setSequence(sequence);
        currentElement.setComplexType(cType);
    }
    Element globalElement = null;
    String fragUri = frag.getNamespaceURI();
    if (fragUri != null) {
        Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
        String targetNS = workingSchema.getTargetNamespace();
        if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
            // must generate a global element are create a reference to it
            // if the global element exists, use it; otherwise create a new one
            globalElement = s.getTopLevelElements().get(frag.getLocalName());
            if (globalElement == null) {
                globalElement = new Element();
                globalElement.setName(frag.getLocalName());
                ComplexType gCType = new ComplexType();
                Sequence gSequence = new Sequence();
                gCType.setSequence(gSequence);
                globalElement.setComplexType(gCType);
                s.addTopLevelElement(globalElement);
            }
            // if the current element doesn't exist set a ref and add it to the sequence
            if (!currentElementExists) {
                // ref won't have a complex type
                currentElement.setComplexType(null);
                currentElement.setRef(frag.getShortName());
                currentSequence.addElement(currentElement);
                currentElementExists = true;
            }
            // make the global element current
            currentElement = globalElement;
        }
    }
    // if we didn't process a global element, and the current element isn't already in the sequence, add it
    if (!currentElementExists && globalElement == null) {
        currentElement.setName(frag.getLocalName());
        currentSequence.addElement(currentElement);
    }
    // set the correct sequence to use/return
    currentSequence = currentElement.getComplexType().getSequence();
    // don't process the last element in the path - let the calling mapping process it
    frag = frag.getNextFragment();
    if (frag.getNextFragment() != null && !frag.getNextFragment().nameIsText()) {
        Element childElt = buildElement(frag, null, Occurs.ZERO, null);
        currentSequence.addElement(childElt);
    }
    // call back into this method to process the next path element
    return buildSchemaComponentsForXPath(frag, currentSequence, schemaForNamespace, workingSchema, properties);
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 7 with Sequence

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

the class SchemaModelGenerator method buildComplexType.

/**
 * Create and return a ComplexType for a given XMLDescriptor.  Assumes that the descriptor has a schema context
 * set.
 */
protected ComplexType buildComplexType(boolean anonymous, Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    if (!anonymous) {
        ct.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
    }
    CoreInheritancePolicy inheritancePolicy = desc.getInheritancePolicyOrNull();
    Extension extension = null;
    if (inheritancePolicy != null && inheritancePolicy.getParentClass() != null) {
        extension = new Extension();
        extension.setBaseType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
        ComplexContent complexContent = new ComplexContent();
        complexContent.setExtension(extension);
        ct.setComplexContent(complexContent);
    }
    Sequence seq = new Sequence();
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        processMapping(mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
    }
    if (extension != null) {
        extension.setSequence(seq);
    } else {
        ct.setSequence(seq);
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) CoreInheritancePolicy(org.eclipse.persistence.core.descriptors.CoreInheritancePolicy) ComplexContent(org.eclipse.persistence.internal.oxm.schema.model.ComplexContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Example 8 with Sequence

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

the class SchemaGenerator method createGlobalElement.

/**
 * Create a global element.  An import is added if necessary.  This method
 * will typically be called when processing an XPath and a prefixed path
 * element is encountered the requires an element ref.
 *
 * @param frag XPathFragment which wil lbe used to create the global element
 * @param workingSchema current schema
 * @param fragSchema frag's schema
 * @param isChoice indicates if we need to construct a choice
 * @param isUnbounded maxOccurs setting for choice
 * @param prop property which owns the xml-path
 * @param shouldSetType if this is the last fragment in the xml-path and not an 'any', we should set the type
 */
public Element createGlobalElement(XPathFragment frag, Schema workingSchema, Schema fragSchema, boolean isChoice, boolean isUnbounded, Property prop, boolean shouldSetType) {
    Element gElement = new Element();
    gElement.setName(frag.getLocalName());
    if (shouldSetType) {
        gElement.setType(getQualifiedTypeName(prop, fragSchema));
    } else {
        ComplexType gCType = new ComplexType();
        TypeDefParticle particle;
        if (isChoice) {
            particle = new Choice();
            if (isUnbounded) {
                particle.setMaxOccurs(Occurs.UNBOUNDED);
            }
        } else {
            particle = new Sequence();
        }
        gCType.setTypeDefParticle(particle);
        gElement.setComplexType(gCType);
    }
    fragSchema.addTopLevelElement(gElement);
    addImportIfRequired(workingSchema, fragSchema, frag.getNamespaceURI());
    return gElement;
}
Also used : TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 9 with Sequence

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

the class SchemaGenerator method addReferenceToSchema.

/**
 * Convenience method for processing a reference property. Required
 * schema components will be generated and set accordingly.
 *
 * @param property the choice property to be processed
 * @param compositor the sequence/choice/all to modify
 * @param schema the schema being built
 */
private void addReferenceToSchema(Property property, Schema schema, TypeDefParticle compositor) {
    java.util.List<ElementDeclaration> referencedElements = property.getReferencedElements();
    if (referencedElements.size() == 1 && !property.isAny()) {
        // if only a single reference, just add the element.
        Element element = new Element();
        ElementDeclaration decl = referencedElements.get(0);
        String localName = decl.getElementName().getLocalPart();
        String prefix = getPrefixForNamespace(schema, decl.getElementName().getNamespaceURI());
        if (decl.getScopeClass() == GLOBAL.class) {
            if (prefix == null || prefix.equals(EMPTY_STRING)) {
                element.setRef(localName);
            } else {
                element.setRef(prefix + COLON + localName);
            }
        } else {
            element.setType(getTypeName(property, decl.getJavaType(), schema));
            element.setName(localName);
        }
        if (property.getGenericType() != null) {
            element.setMinOccurs(Occurs.ZERO);
            element.setMaxOccurs(Occurs.UNBOUNDED);
        } else if (!property.isRequired()) {
            element.setMinOccurs(Occurs.ZERO);
        }
        compositor.addElement(element);
    } else {
        // otherwise, add a choice of referenced elements.
        Choice choice = new Choice();
        if (property.getGenericType() != null) {
            choice.setMaxOccurs(Occurs.UNBOUNDED);
        }
        if (!property.isRequired()) {
            choice.setMinOccurs(Occurs.ZERO);
        }
        for (ElementDeclaration elementDecl : referencedElements) {
            Element element = new Element();
            String localName = elementDecl.getElementName().getLocalPart();
            String prefix = getPrefixForNamespace(schema, elementDecl.getElementName().getNamespaceURI());
            if (elementDecl.getScopeClass() == GLOBAL.class) {
                if (prefix == null || prefix.equals(EMPTY_STRING)) {
                    element.setRef(localName);
                } else {
                    element.setRef(prefix + COLON + localName);
                }
            } else {
                Schema referencedSchema = getSchemaForNamespace(elementDecl.getElementName().getNamespaceURI());
                element.setType(getTypeName(property, elementDecl.getJavaType(), referencedSchema));
                element.setName(localName);
            }
            choice.addElement(element);
        }
        // handle XmlAnyElement case
        if (property.isAny()) {
            addAnyToSchema(property, choice, false);
        }
        if (compositor instanceof Sequence) {
            ((Sequence) compositor).addChoice(choice);
        } else if (compositor instanceof Choice) {
            ((Choice) compositor).addChoice(choice);
        }
    }
}
Also used : Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence)

Example 10 with Sequence

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

the class SchemaGenerator method addChoiceToSchema.

/**
 * Convenience method for processing a choice property. Required
 * schema components will be generated and set accordingly.
 *
 * @param property the choice property to be processed
 * @param typeInfo the TypeInfo that the given property belongs to
 * @param type the ComplexType which compositor(s) should be added to
 * @param compositor the sequence/choice/all to modify
 * @param schema the schema being built
 */
private void addChoiceToSchema(Property property, TypeInfo typeInfo, ComplexType type, TypeDefParticle compositor, Schema schema) {
    Choice choice = new Choice();
    if (property.getGenericType() != null) {
        choice.setMaxOccurs(Occurs.UNBOUNDED);
    }
    ArrayList<Property> choiceProperties = (ArrayList<Property>) property.getChoiceProperties();
    addToSchemaType(typeInfo, choiceProperties, choice, type, schema);
    if (compositor instanceof Sequence) {
        ((Sequence) compositor).addChoice(choice);
    } else if (compositor instanceof Choice) {
        ((Choice) compositor).addChoice(choice);
    }
}
Also used : Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) ArrayList(java.util.ArrayList) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence)

Aggregations

Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)12 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)9 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)7 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)6 Choice (org.eclipse.persistence.internal.oxm.schema.model.Choice)5 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)4 Any (org.eclipse.persistence.internal.oxm.schema.model.Any)3 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)3 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)3 QName (javax.xml.namespace.QName)2 ComplexContent (org.eclipse.persistence.internal.oxm.schema.model.ComplexContent)2 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 BindingOperation (javax.wsdl.BindingOperation)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)1 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)1 CoreInheritancePolicy (org.eclipse.persistence.core.descriptors.CoreInheritancePolicy)1