Search in sources :

Example 6 with Choice

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

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

Choice (org.eclipse.persistence.internal.oxm.schema.model.Choice)7 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)5 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)5 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 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 XMLChoiceFieldToClassAssociation (org.eclipse.persistence.internal.oxm.XMLChoiceFieldToClassAssociation)1 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)1 Field (org.eclipse.persistence.internal.oxm.mappings.Field)1 All (org.eclipse.persistence.internal.oxm.schema.model.All)1 Any (org.eclipse.persistence.internal.oxm.schema.model.Any)1 AnyAttribute (org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute)1 Attribute (org.eclipse.persistence.internal.oxm.schema.model.Attribute)1 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)1 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)1 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)1 TypeDefParticleOwner (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticleOwner)1