Search in sources :

Example 6 with Attribute

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

the class SchemaModelGenerator method processXMLObjectReferenceMapping.

/**
 * 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
 */
protected void processXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
    String tgtClassName = mapping.getReferenceClassName();
    Descriptor tgtDesc = getDescriptorByName(tgtClassName, descriptors);
    if (tgtDesc == null) {
        throw DescriptorException.descriptorIsMissing(tgtClassName, (DatabaseMapping) mapping);
    }
    // get the target mapping(s) to determine the appropriate type(s)
    String schemaTypeString = null;
    Map<Field, Field> associations = mapping.getSourceToTargetKeyFieldAssociations();
    for (Entry<Field, Field> entry : associations.entrySet()) {
        Field tgtField = entry.getValue();
        Vector mappings = tgtDesc.getMappings();
        // schemaTypeString = Constants.SCHEMA_PREFIX + COLON + IDREF;
        for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements(); ) {
            Mapping nextMapping = (Mapping) mappingsNum.nextElement();
            if (nextMapping.getField() != null && nextMapping.getField() instanceof Field) {
                Field xFld = (Field) nextMapping.getField();
                if (xFld == tgtField) {
                    schemaTypeString = getSchemaTypeForElement(tgtField, nextMapping.getAttributeClassification(), workingSchema);
                }
            }
        }
        if (schemaTypeString == null) {
            schemaTypeString = getSchemaTypeString(Constants.STRING_QNAME, workingSchema);
        }
        XPathFragment frag = entry.getKey().getXPathFragment();
        if (frag.isAttribute()) {
            Attribute attr = buildAttribute(frag, schemaTypeString);
            ct.getOrderedAttributes().add(attr);
        } else {
            Element elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
            if (isCollection) {
                elem.setMaxOccurs(Occurs.UNBOUNDED);
            }
            seq.addElement(elem);
        }
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Enumeration(java.util.Enumeration) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) Vector(java.util.Vector)

Example 7 with Attribute

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

the class SchemaModelGenerator method buildAttribute.

/**
 * Build and return an Attribute for a given XPathFragment.
 */
protected Attribute buildAttribute(XPathFragment frag, String schemaType) {
    Attribute attr = new Attribute();
    attr.setName(frag.getShortName());
    attr.setType(schemaType);
    return attr;
}
Also used : AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute)

Example 8 with Attribute

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

the class SchemaModelGenerator method buildComplexTypeWithSimpleContent.

/**
 * Create and return a ComplexType containing simple content for a given XMLDescriptor.  Assumes
 * that the descriptor has a schema context set.
 */
private ComplexType buildComplexTypeWithSimpleContent(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    SimpleContent sc = new SimpleContent();
    Extension extension = new Extension();
    sc.setExtension(extension);
    ct.setSimpleContent(sc);
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        Field xFld = (Field) mapping.getField();
        if (xFld.getXPath().equals(TEXT)) {
            extension.setBaseType(getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema));
        } else if (xFld.getXPathFragment().isAttribute()) {
            String schemaTypeString = getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema);
            Attribute attr = buildAttribute((DirectMapping) mapping, schemaTypeString);
            extension.getOrderedAttributes().add(attr);
        }
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) Field(org.eclipse.persistence.internal.oxm.mappings.Field) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Example 9 with Attribute

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

the class SchemaModelGenerator method buildAttribute.

/**
 * Build and return an Attribute for a given XMLDirectMapping.
 */
protected Attribute buildAttribute(DirectMapping mapping, String schemaType) {
    XPathFragment frag = ((Field) mapping.getField()).getXPathFragment();
    Attribute attr = new Attribute();
    attr.setName(frag.getShortName());
    attr.setType(schemaType);
    return attr;
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 10 with Attribute

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

the class SchemaModelGenerator method processEnumeration.

/**
 * Process information contained within an EnumTypeConverter.  This will generate a simple
 * type containing enumeration info.
 */
protected void processEnumeration(String schemaTypeString, XPathFragment frag, DirectMapping mapping, Sequence seq, ComplexType ct, Schema workingSchema, CoreConverter converter) {
    Element elem = null;
    Attribute attr = null;
    if (frag.isAttribute()) {
        attr = buildAttribute(mapping, schemaTypeString);
    } else {
        elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
    }
    Collection<String> fieldValues = ((EnumTypeConverter) converter).getAttributeToFieldValues().values();
    List<String> facets = new ArrayList<>(fieldValues);
    Restriction restriction = new Restriction();
    restriction.setEnumerationFacets(facets);
    SimpleType st = new SimpleType();
    st.setRestriction(restriction);
    if (frag.isAttribute()) {
        attr.setSimpleType(st);
        ct.getOrderedAttributes().add(attr);
    } else {
        elem.setSimpleType(st);
        seq.addElement(elem);
    }
}
Also used : Restriction(org.eclipse.persistence.internal.oxm.schema.model.Restriction) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ArrayList(java.util.ArrayList)

Aggregations

Attribute (org.eclipse.persistence.internal.oxm.schema.model.Attribute)16 AnyAttribute (org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute)12 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)5 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)4 Field (org.eclipse.persistence.internal.oxm.mappings.Field)4 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)4 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)3 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 QName (javax.xml.namespace.QName)2 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)2 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)2 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)2 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)2 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)2 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)2 Enumeration (java.util.Enumeration)1 List (java.util.List)1 CoreConverter (org.eclipse.persistence.core.mappings.converters.CoreConverter)1 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)1