Search in sources :

Example 1 with AttributeTypeImpl

use of org.geotools.feature.type.AttributeTypeImpl in project hale by halestudio.

the class XmlTypeUtil method configureXsdSimpleType.

/**
 * Configure the given type as XML schema simple type if possible
 *
 * @param type the type to configure
 * @return if the type could be configured as XSD simple type
 */
@SuppressWarnings("unchecked")
private static boolean configureXsdSimpleType(XmlTypeDefinition type) {
    Name typeName = new NameImpl(type.getName().getNamespaceURI(), type.getName().getLocalPart());
    AttributeType ty = xsSchema.get(typeName);
    // special case: ID etc. - assure String binding
    if (ty != null && XS_STRING_TYPES.contains(typeName.getLocalPart())) {
        ty = new AttributeTypeImpl(typeName, java.lang.String.class, false, false, Collections.EMPTY_LIST, ty.getSuper(), null);
    }
    // only enable hasValue if the type is not anyType
    // anyType has special treatment in
    // XmlSchemaReader.setMetadataAndConstraints(TypeDefinition, ...)
    boolean hasValue = !typeName.getLocalPart().equals("anyType");
    if (ty != null) {
        // configure type
        // set binding
        type.setConstraint(Binding.get(ty.getBinding()));
        // simple type flag
        if (hasValue) {
            type.setConstraint(HasValueFlag.ENABLED);
        }
        // not abstract
        type.setConstraint(AbstractFlag.DISABLED);
        // not mappable
        type.setConstraint(MappingRelevantFlag.DISABLED);
        type.setConstraint(MappableFlag.DISABLED);
        type.setLocation(URI.create(XMLConstants.W3C_XML_SCHEMA_NS_URI));
        if (ty.getDescription() != null) {
            type.setDescription(ty.getDescription().toString());
        }
        return true;
    } else {
        return false;
    }
}
Also used : NameImpl(org.geotools.feature.NameImpl) AttributeType(org.opengis.feature.type.AttributeType) AttributeTypeImpl(org.geotools.feature.type.AttributeTypeImpl) QName(javax.xml.namespace.QName) Name(org.opengis.feature.type.Name)

Aggregations

QName (javax.xml.namespace.QName)1 NameImpl (org.geotools.feature.NameImpl)1 AttributeTypeImpl (org.geotools.feature.type.AttributeTypeImpl)1 AttributeType (org.opengis.feature.type.AttributeType)1 Name (org.opengis.feature.type.Name)1