Search in sources :

Example 1 with Sequence

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

the class SchemaGenerator method buildSchemaComponentsForXPath.

/**
 * This method will build element/complexType/typedefparticle components for a given xml-path,
 * and return an XmlPathResult instance containg the sequence that the target should be added
 * to, as well as the current schema - which could be different than the working schema used
 * before calling this method in the case of a prefixed path element from a different namespace.
 * Regarding the path 'target', if the xml-path was "contact-info/address/street", "street"
 * would be the target.  In this case the sequence containing the "address" element would be
 * set in the XmlPathResult to be returned.
 *
 * The exception case is an 'any', where we want to process the last path element before
 * returning - this is necessary due to the fact that an Any will be added to the sequence
 * in place of the last path element by the calling method.
 */
private AddToSchemaResult buildSchemaComponentsForXPath(XPathFragment frag, AddToSchemaResult xpr, boolean isChoice, Property next) {
    boolean isAny = next.isAny() || next.isAnyAttribute();
    TypeDefParticle currentParticle = xpr.particle;
    Schema workingSchema = xpr.schema;
    // each nested choice on a collection will be unbounded
    boolean isUnbounded = false;
    if (currentParticle != null) {
        isUnbounded = (currentParticle.getMaxOccurs() != null && currentParticle.getMaxOccurs() == Occurs.UNBOUNDED);
    }
    // don't process the last frag; that will be handled by the calling method if necessary
    // note that we may need to process the last frag if it has a namespace or is an 'any'
    boolean lastFrag = (frag.getNextFragment() == null || frag.getNextFragment().nameIsText());
    // if the element is already in the sequence we don't want the calling method to add a second one
    if (lastFrag && (elementExistsInParticle(frag.getLocalName(), frag.getShortName(), currentParticle) != null)) {
        xpr.particle = null;
        return xpr;
    }
    // if the current element exists, use it; otherwise create a new one
    Element currentElement = elementExistsInParticle(frag.getLocalName(), frag.getShortName(), currentParticle);
    boolean currentElementExists = (currentElement != null);
    if (!currentElementExists) {
        currentElement = new Element();
        // don't set the element name yet, as it may end up being a ref
        ComplexType cType = new ComplexType();
        TypeDefParticle particle = null;
        if (isChoice) {
            particle = new Choice();
            if (isUnbounded) {
                particle.setMaxOccurs(Occurs.UNBOUNDED);
            }
        } else {
            XPathFragment nextFragment = frag.getNextFragment();
            if (frag.containsIndex() || frag.getPredicate() != null || (!next.isXmlList() && null != nextFragment && nextFragment.isAttribute() && helper.isCollectionType(next.getType()))) {
                currentElement.setMaxOccurs(Occurs.UNBOUNDED);
            }
            particle = new Sequence();
        }
        cType.setTypeDefParticle(particle);
        currentElement.setComplexType(cType);
    } else {
        // if the current element already exists, we may need to change it's type
        XPathFragment nextFrag = frag.getNextFragment();
        if (nextFrag != null && nextFrag.isAttribute()) {
            if (currentElement.getType() != null && currentElement.getComplexType() == null) {
                // there's already a text mapping to this element, so
                // attributes can be added by making it complex with
                // simple content.
                SimpleType type = currentElement.getSimpleType();
                if (type != null) {
                    ComplexType cType = new ComplexType();
                    cType.setSimpleContent(new SimpleContent());
                    Extension extension = new Extension();
                    extension.setBaseType(type.getRestriction().getBaseType());
                    cType.getSimpleContent().setExtension(extension);
                    currentElement.setSimpleType(null);
                    currentElement.setComplexType(cType);
                } else {
                    String eType = currentElement.getType();
                    ComplexType cType = new ComplexType();
                    SimpleContent sContent = new SimpleContent();
                    Extension extension = new Extension();
                    extension.setBaseType(eType);
                    sContent.setExtension(extension);
                    cType.setSimpleContent(sContent);
                    currentElement.setType(null);
                    currentElement.setComplexType(cType);
                }
            }
        }
    }
    // may need to create a ref, depending on the namespace
    Element globalElement = null;
    String fragUri = frag.getNamespaceURI();
    if (fragUri != null) {
        Schema fragSchema = getSchemaForNamespace(fragUri);
        String targetNS = workingSchema.getTargetNamespace();
        // handle Attribute case
        if (frag.isAttribute()) {
            if (fragSchema == null || (fragSchema.isAttributeFormDefault() && !fragUri.equals(targetNS)) || (!fragSchema.isAttributeFormDefault() && fragUri.length() > 0)) {
                // if fragSchema is null, just generate the ref
                if (fragSchema != null) {
                    Attribute globalAttribute = null;
                    globalAttribute = fragSchema.getTopLevelAttributes().get(frag.getLocalName());
                    if (globalAttribute == null) {
                        globalAttribute = createGlobalAttribute(frag, workingSchema, fragSchema, next);
                    }
                } else {
                    // may need to add an import
                    addImportIfRequired(workingSchema, null, fragUri);
                }
                // add the attribute ref to the current element
                String attributeRefName;
                if (fragUri.equals(targetNS)) {
                    String prefix = fragSchema.getNamespaceResolver().resolveNamespaceURI(fragUri);
                    attributeRefName = prefix + COLON + frag.getLocalName();
                } else {
                    attributeRefName = frag.getShortName();
                }
                TypeDefParticleOwner type;
                if (currentParticle != null) {
                    type = currentParticle.getOwner();
                } else {
                    type = xpr.simpleContentType;
                }
                if (type instanceof ComplexType) {
                    createRefAttribute(attributeRefName, (ComplexType) type);
                }
                // set the frag's schema as it may be different than the current schema
                xpr.schema = fragSchema;
                // ref case - indicate to the calling method that there's nothing to do
                xpr.particle = null;
            }
            // since we are dealing with an attribute, we are on the last fragment; return
            return xpr;
        }
        // here we are dealing with an Element
        if ((fragSchema.isElementFormDefault() && !fragUri.equals(targetNS)) || (!fragSchema.isElementFormDefault() && fragUri.length() > 0)) {
            // must generate a global element and create a reference to it
            // if the global element exists, use it; otherwise create a new one
            globalElement = fragSchema.getTopLevelElements().get(frag.getLocalName());
            if (globalElement == null) {
                globalElement = createGlobalElement(frag, workingSchema, fragSchema, isChoice, isUnbounded, next, (lastFrag && !isAny));
            }
            // if the current element doesn't exist set a ref and add it to the sequence
            if (!currentElementExists) {
                // use prefix from the working schema's resolver - add prefix/uri pair if necessary
                String fragPrefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(fragUri);
                if (fragPrefix == null) {
                    fragPrefix = workingSchema.getNamespaceResolver().generatePrefix(frag.getPrefix());
                    workingSchema.getNamespaceResolver().put(fragPrefix, fragUri);
                }
                currentElement = createRefElement(fragPrefix + COLON + frag.getLocalName(), currentParticle);
                if (frag.containsIndex() || frag.getPredicate() != null || helper.isCollectionType(next.getType())) {
                    currentElement.setMaxOccurs(Occurs.UNBOUNDED);
                }
                currentElementExists = true;
            }
            // set the frag's schema as it may be different than the current schema
            xpr.schema = fragSchema;
            // at this point, if we are dealing with the last fragment we will need to return
            if (lastFrag) {
                // add a second one...unless we're dealing with an 'any'
                if (isAny) {
                    // set the particle that the 'any' will be added to by the calling method
                    xpr.particle = globalElement.getComplexType().getTypeDefParticle();
                    return xpr;
                }
                // ref case - indicate to the calling method that there's nothing to do
                xpr.particle = null;
                return xpr;
            }
            // make the global element current
            currentElement = globalElement;
        }
    }
    if (!lastFrag || (lastFrag && isAny)) {
        // 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());
            Integer minOccurs = next.getMinOccurs();
            if (minOccurs != null)
                currentElement.setMinOccurs(String.valueOf(minOccurs));
            else
                currentElement.setMinOccurs(Occurs.ZERO);
            currentParticle.addElement(currentElement);
        }
        // set the correct particle to use/return
        if (currentElement.getComplexType() != null) {
            if (currentElement.getComplexType().getTypeDefParticle() == null) {
                // complexType with simple-content
                xpr.simpleContentType = currentElement.getComplexType();
                xpr.particle = null;
            } else {
                xpr.particle = currentElement.getComplexType().getTypeDefParticle();
            }
        } else {
            // If there's no complex type, we're building the path through an element with
            // a simple type. In order to build the path through this
            // element, switch to a complex type with simple content.
            SimpleType type = currentElement.getSimpleType();
            if (type != null) {
                ComplexType cType = new ComplexType();
                cType.setSimpleContent(new SimpleContent());
                Extension extension = new Extension();
                extension.setBaseType(type.getRestriction().getBaseType());
                cType.getSimpleContent().setExtension(extension);
                currentElement.setSimpleType(null);
                currentElement.setComplexType(cType);
                xpr.particle = null;
                xpr.simpleContentType = cType;
            } else {
                String eType = currentElement.getType();
                ComplexType cType = new ComplexType();
                SimpleContent sContent = new SimpleContent();
                Extension extension = new Extension();
                extension.setBaseType(eType);
                sContent.setExtension(extension);
                cType.setSimpleContent(sContent);
                currentElement.setType(null);
                currentElement.setComplexType(cType);
                xpr.particle = null;
                xpr.simpleContentType = cType;
            }
        }
    }
    // if we're on the last fragment, we're done
    if (lastFrag) {
        return xpr;
    }
    // call back into this method to process the next path element
    return buildSchemaComponentsForXPath(frag.getNextFragment(), xpr, isChoice, next);
}
Also used : TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) 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) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) TypeDefParticleOwner(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticleOwner) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 2 with Sequence

use of org.eclipse.persistence.internal.oxm.schema.model.Sequence 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 Sequence

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

the class SchemaGenerator method addAnyToSchema.

/**
 * Convenience method for processing an any 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 isCollection if true will be unbounded
 * @param anyNamespace value for the Any's namespace attribute
 */
private void addAnyToSchema(Property property, TypeDefParticle compositor, boolean isCollection, String anyNamespace) {
    Any any = new Any();
    any.setNamespace(anyNamespace);
    if (property.isLax()) {
        any.setProcessContents(Any.LAX);
    } else {
        any.setProcessContents(SKIP);
    }
    if (isCollection) {
        any.setMinOccurs(Occurs.ZERO);
        any.setMaxOccurs(Occurs.UNBOUNDED);
    }
    if (compositor instanceof Sequence) {
        ((Sequence) compositor).addAny(any);
    } else if (compositor instanceof Choice) {
        ((Choice) compositor).addAny(any);
    }
}
Also used : Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) Any(org.eclipse.persistence.internal.oxm.schema.model.Any)

Example 4 with Sequence

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

the class SchemaGenerator method addXmlElementWrapperToSchema.

/**
 * Convenience method for processing an XmlElementWrapper for a given property. Required schema
 * components will be generated and set accordingly.
 *
 * @param property the property containing an XmlElementWrapper
 * @param schema the schema currently being generated
 * @param compositor sequence/choice/all that the generated wrapper Element will be added to
 * @return AddToSchemaResult containing current ComplexType and TypeDefParticle
 */
private AddToSchemaResult addXmlElementWrapperToSchema(Property property, Schema schema, TypeDefParticle compositor) {
    XmlElementWrapper wrapper = property.getXmlElementWrapper();
    Element wrapperElement = new Element();
    String name = wrapper.getName();
    // handle nillable
    wrapperElement.setNillable(wrapper.isNillable());
    // namespace in not the target or ##default, create a ref with min/max = 1
    String wrapperNS = wrapper.getNamespace();
    if (!wrapperNS.equals(XMLProcessor.DEFAULT) && !wrapperNS.equals(schema.getTargetNamespace())) {
        wrapperElement.setMinOccurs(Occurs.ONE);
        wrapperElement.setMaxOccurs(Occurs.ONE);
        String prefix = getOrGeneratePrefixForNamespace(wrapperNS, schema);
        wrapperElement.setRef(prefix + COLON + name);
        compositor.addElement(wrapperElement);
        // assume that the element exists and does not need to be created
        return null;
    }
    wrapperElement.setName(name);
    if (wrapper.isRequired()) {
        wrapperElement.setMinOccurs(Occurs.ONE);
    } else {
        wrapperElement.setMinOccurs(Occurs.ZERO);
    }
    if (!wrapperNS.equals(XMLProcessor.DEFAULT)) {
        String lookupNamespace = schema.getTargetNamespace();
        if (lookupNamespace == null) {
            lookupNamespace = EMPTY_STRING;
        }
        NamespaceInfo namespaceInfo = getNamespaceInfoForNamespace(lookupNamespace);
        boolean isElementFormQualified = false;
        if (namespaceInfo != null) {
            isElementFormQualified = namespaceInfo.isElementFormQualified();
        }
        shouldAddRefAndSetForm(wrapperElement, wrapperNS, lookupNamespace, isElementFormQualified, true);
    }
    compositor.addElement(wrapperElement);
    ComplexType wrapperType = new ComplexType();
    Sequence wrapperSequence = new Sequence();
    wrapperType.setSequence(wrapperSequence);
    wrapperElement.setComplexType(wrapperType);
    return new AddToSchemaResult(wrapperSequence, wrapperType);
}
Also used : 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) XmlElementWrapper(org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper)

Example 5 with Sequence

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

the class Util method addSimpleXMLFormat.

/*
      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        >
        <xsd:complexType name="simple-xml-format">
          <xsd:sequence>
            <xsd:any minOccurs="0"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:schema>
    */
public static void addSimpleXMLFormat(Schema schema) {
    ComplexType anyType = new ComplexType();
    anyType.setName(DEFAULT_SIMPLE_XML_FORMAT_TAG);
    Sequence anySequence = new Sequence();
    Any any = new Any();
    any.setMinOccurs("0");
    anySequence.addAny(any);
    anyType.setSequence(anySequence);
    schema.addTopLevelComplexTypes(anyType);
}
Also used : Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Any(org.eclipse.persistence.internal.oxm.schema.model.Any)

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