Search in sources :

Example 11 with Attribute

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

the class SchemaModelGenerator method processXMLDirectMapping.

/**
 * Process a given XMLDirectMapping.
 */
protected void processXMLDirectMapping(DirectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = (Field) mapping.getField();
    XPathFragment frag = xmlField.getXPathFragment();
    if (frag.isSelfFragment()) {
        // do nothing;
        return;
    }
    // Handle ID
    boolean isPk = isFragPrimaryKey(frag, mapping);
    String schemaTypeString = null;
    if (isPk) {
        schemaTypeString = Constants.SCHEMA_PREFIX + Constants.COLON + ID;
    } else {
        schemaTypeString = getSchemaTypeForDirectMapping(mapping, workingSchema);
    }
    // Handle enumerations
    Class<?> attributeClassification = mapping.getAttributeClassification();
    if (attributeClassification != null && Enum.class.isAssignableFrom(attributeClassification)) {
        CoreConverter converter = mapping.getConverter();
        if (converter != null && converter instanceof EnumTypeConverter) {
            processEnumeration(schemaTypeString, frag, mapping, seq, ct, workingSchema, converter);
            return;
        }
    }
    if (frag.isAttribute()) {
        Attribute attr = buildAttribute(mapping, schemaTypeString);
        if (xmlField.isRequired()) {
            attr.setUse(Attribute.REQUIRED);
        }
        ct.getOrderedAttributes().add(attr);
    } else {
        seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
        frag = getTargetXPathFragment(frag);
        Element elem = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), seq);
        if (elem == null) {
            if (frag.getNamespaceURI() != null) {
                elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString);
            } else {
                elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
            }
            if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
                elem.setNillable(true);
            }
            if (xmlField.isRequired()) {
                elem.setMinOccurs("1");
            }
            seq.addElement(elem);
        }
    }
}
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) EnumTypeConverter(org.eclipse.persistence.mappings.converters.EnumTypeConverter) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter)

Example 12 with Attribute

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

the class SchemaGenerator method createGlobalAttribute.

/**
 * Create a global attribute.  An import is added if necessary.  This method
 * will typically be called when processing an XPath and a prefixed path
 * element is encountered tha requires an attribute ref.
 */
public Attribute createGlobalAttribute(XPathFragment frag, Schema workingSchema, Schema fragSchema, Property prop) {
    Attribute gAttribute = new Attribute();
    gAttribute.setName(frag.getLocalName());
    gAttribute.setType(getQualifiedTypeName(prop, fragSchema));
    fragSchema.getTopLevelAttributes().put(gAttribute.getName(), gAttribute);
    addImportIfRequired(workingSchema, fragSchema, frag.getNamespaceURI());
    return gAttribute;
}
Also used : AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute)

Example 13 with Attribute

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

the class SDOTypesGenerator method processGlobalItem.

private void processGlobalItem(String targetNamespace, String defaultNamespace, String qualifiedName) {
    if (rootSchema == null) {
        return;
    }
    String localName = null;
    int index = qualifiedName.indexOf(':');
    if (index != -1) {
        localName = qualifiedName.substring(index + 1, qualifiedName.length());
    } else {
        localName = qualifiedName;
    }
    SimpleType simpleType = rootSchema.getTopLevelSimpleTypes().get(localName);
    if (simpleType == null) {
        ComplexType complexType = rootSchema.getTopLevelComplexTypes().get(localName);
        if (complexType == null) {
            Element element = rootSchema.getTopLevelElements().get(localName);
            if (element == null) {
                Attribute attribute = rootSchema.getTopLevelAttributes().get(localName);
                if (attribute != null) {
                    processGlobalAttribute(targetNamespace, defaultNamespace, attribute);
                }
            } else {
                processGlobalElement(targetNamespace, defaultNamespace, element);
            }
        } else {
            processGlobalComplexType(targetNamespace, defaultNamespace, complexType);
        }
    } else {
        processGlobalSimpleType(targetNamespace, defaultNamespace, simpleType);
    }
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 14 with Attribute

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

the class SDOTypesGenerator method processGlobalAttribute.

private void processGlobalAttribute(String targetNamespace, String defaultNamespace, Attribute attribute) {
    if (attribute.getName() != null) {
        QName qname = new QName(targetNamespace, attribute.getName());
        Attribute processed = processedAttributes.get(qname);
        if (processed == null) {
            SDOType attributeType = processAttribute(targetNamespace, defaultNamespace, null, attribute, true);
            processedAttributes.put(qname, attribute);
            if (null != attributeType && !getGeneratedTypes().containsKey(attributeType.getQName())) {
                getGeneratedTypes().put(attributeType.getQName(), attributeType);
                anonymousTypes.remove(attributeType);
            }
        }
    } else {
        processAttribute(targetNamespace, defaultNamespace, null, attribute, true);
    }
}
Also used : Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) QName(javax.xml.namespace.QName) SDOType(org.eclipse.persistence.sdo.SDOType)

Example 15 with Attribute

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

the class SDOTypesGenerator method processAttributes.

private void processAttributes(String targetNamespace, String defaultNamespace, SDOType owningType, java.util.List attributes) {
    if (attributes == null) {
        return;
    }
    for (int i = 0; i < attributes.size(); i++) {
        Attribute nextAttribute = (Attribute) attributes.get(i);
        processAttribute(targetNamespace, defaultNamespace, owningType, nextAttribute, false);
    }
}
Also used : Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute)

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