Search in sources :

Example 1 with XmlAttributeReferenceProperty

use of eu.esdihumboldt.hale.io.xsd.reader.internal.XmlAttributeReferenceProperty in project hale by halestudio.

the class XmlSchemaReader method createAttribute.

private void createAttribute(XmlSchemaAttribute attribute, DefinitionGroup declaringGroup, String schemaLocation, String schemaNamespace) {
    // create attributes
    QName typeName = attribute.getSchemaTypeName();
    if (typeName != null) {
        QName attributeName = determineAttributeName(attribute, schemaNamespace);
        // resolve type by name
        XmlTypeDefinition type = getTypeForAttribute(typeName, declaringGroup, attributeName);
        // create property
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(attributeName, declaringGroup, type);
        // set metadata and constraints
        setMetadataAndConstraints(property, attribute, schemaLocation);
    } else if (attribute.getSchemaType() != null) {
        XmlSchemaSimpleType simpleType = attribute.getSchemaType();
        // create an anonymous type
        QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + attribute.getName(), // $NON-NLS-2$
        "AnonymousType");
        AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
        configureSimpleType(anonymousType, simpleType, schemaLocation);
        // create property
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(determineAttributeName(attribute, schemaNamespace), declaringGroup, anonymousType);
        // set metadata and constraints
        setMetadataAndConstraints(property, attribute, schemaLocation);
    } else if (attribute.getRefName() != null) {
        // <attribute ref="REF_NAME" />
        // reference to a named attribute
        QName attName = attribute.getRefName();
        XmlAttributeReferenceProperty property = new XmlAttributeReferenceProperty(attName, declaringGroup, this.index, attName);
        // set metadata and constraints
        setMetadataAndConstraints(property, attribute, schemaLocation);
    } else {
        /*
			 * Attribute with no type given has anySimpleType, see
			 * "http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#cAttribute_Declarations"
			 */
        // resolve type by name
        XmlTypeDefinition type = index.getOrCreateType(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anySimpleType"));
        // create property
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(determineAttributeName(attribute, schemaNamespace), declaringGroup, type);
        // set metadata and constraints
        setMetadataAndConstraints(property, attribute, schemaLocation);
    }
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) AnonymousXmlType(eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType) XmlAttributeReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlAttributeReferenceProperty)

Aggregations

DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)1 AnonymousXmlType (eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType)1 XmlAttributeReferenceProperty (eu.esdihumboldt.hale.io.xsd.reader.internal.XmlAttributeReferenceProperty)1 XmlTypeDefinition (eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition)1 QName (javax.xml.namespace.QName)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1