Search in sources :

Example 16 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class XmlSchemaReader method createPropertyFromElement.

/**
 * Create a property from an element
 *
 * @param element the schema element
 * @param declaringGroup the definition of the declaring group
 * @param schemaLocation the schema location
 * @param schemaNamespace the schema namespace
 */
private void createPropertyFromElement(XmlSchemaElement element, DefinitionGroup declaringGroup, String schemaLocation, String schemaNamespace) {
    if (element.getSchemaTypeName() != null) {
        // element referencing a type
        // <element name="ELEMENT_NAME" type="SCHEMA_TYPE_NAME" />
        QName elementName = element.getQName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(elementName, substitutionGroup, index.getOrCreateType(element.getSchemaTypeName()));
        // set metadata and constraints
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    } else if (element.getRefName() != null) {
        // references another element
        // <element ref="REF_NAME" />
        QName elementName = element.getRefName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        XmlElementReferenceProperty property = new XmlElementReferenceProperty(elementName, substitutionGroup, index, elementName);
        // set metadata and constraints FIXME can the constraints be set at
        // this point? or must the property determine them from the
        // SchemaElement?
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    } else if (element.getSchemaType() != null) {
        // definition
        if (element.getSchemaType() instanceof XmlSchemaComplexType) {
            // <element ...>
            // <complexType>
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) element.getSchemaType();
            XmlSchemaContentModel model = complexType.getContentModel();
            if (model != null) {
                XmlSchemaContent content = model.getContent();
                QName superTypeName = null;
                if (content instanceof XmlSchemaComplexContentExtension || content instanceof XmlSchemaComplexContentRestriction) {
                    // <complexContent>
                    // <extension base="..."> / <restriction ...>
                    String nameExt;
                    if (content instanceof XmlSchemaComplexContentExtension) {
                        superTypeName = ((XmlSchemaComplexContentExtension) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Extension";
                    } else {
                        superTypeName = ((XmlSchemaComplexContentRestriction) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Restriction";
                    }
                    if (superTypeName != null) {
                        // try to get the type definition of the super type
                        XmlTypeDefinition superType = index.getOrCreateType(superTypeName);
                        // create an anonymous type that extends the super
                        // type
                        QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
                        superTypeName.getLocalPart() + nameExt);
                        AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                        anonymousType.setSuperType(superType);
                        // set metadata and constraints
                        setMetadataAndConstraints(anonymousType, complexType, schemaLocation);
                        // add properties to the anonymous type
                        createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                        // create a property with the anonymous type
                        DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                        // set metadata and constraints
                        setMetadataAndConstraints(property, element, schemaLocation);
                    } else {
                        reporter.error(new IOMessageImpl("Could not determine super type for complex content", null, content.getLineNumber(), content.getLinePosition()));
                    }
                // </extension> / </restriction>
                // </complexContent>
                } else if (content instanceof XmlSchemaSimpleContentExtension || content instanceof XmlSchemaSimpleContentRestriction) {
                    // <simpleContent>
                    // <extension base="..."> / <restriction ...>
                    String nameExt;
                    if (content instanceof XmlSchemaSimpleContentExtension) {
                        superTypeName = ((XmlSchemaSimpleContentExtension) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Extension";
                    } else {
                        superTypeName = ((XmlSchemaSimpleContentRestriction) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Restriction";
                    }
                    if (superTypeName != null) {
                        // try to get the type definition of the super type
                        XmlTypeDefinition superType = index.getOrCreateType(superTypeName);
                        // create an anonymous type that extends the super
                        // type
                        QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
                        superTypeName.getLocalPart() + nameExt);
                        AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                        anonymousType.setSuperType(superType);
                        // set metadata and constraints
                        setMetadata(anonymousType, complexType, schemaLocation);
                        anonymousType.setConstraint(HasValueFlag.ENABLED);
                        // set no binding, inherit it from the super type
                        // XXX is this ok?
                        // add properties to the anonymous type
                        createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                        // create a property with the anonymous type
                        DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                        // set metadata and constraints
                        setMetadataAndConstraints(property, element, schemaLocation);
                    } else {
                        reporter.error(new IOMessageImpl("Could not determine super type for simple content", null, content.getLineNumber(), content.getLinePosition()));
                    }
                // </extension>
                // </simpleContent>
                }
            } else {
                // this where we get when there is an anonymous complex type
                // as property type
                // create an anonymous type
                QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), "AnonymousType");
                // create anonymous type with no super type
                AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                // set metadata and constraints
                setMetadataAndConstraints(anonymousType, complexType, schemaLocation);
                // add properties to the anonymous type
                createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                // create a property with the anonymous type
                DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                // set metadata and constraints
                setMetadataAndConstraints(property, element, schemaLocation);
            }
        // </complexType>
        // </element>
        } else if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            // simple schema type
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) element.getSchemaType();
            // create an anonymous type
            QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
            "AnonymousType");
            AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
            configureSimpleType(anonymousType, simpleType, schemaLocation);
            // create a property with the anonymous type
            DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
            // set metadata and constraints
            setMetadataAndConstraints(property, element, schemaLocation);
        }
    } else {
        // <element name="..." />
        // no type defined
        reporter.warn(new IOMessageImpl("Element definition without an associated type: {0}", null, element.getLineNumber(), element.getLinePosition(), element.getQName()));
        // assuming xsd:anyType as default type
        QName elementName = element.getQName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(elementName, substitutionGroup, index.getOrCreateType(XmlTypeUtil.NAME_ANY_TYPE));
        // set metadata and constraints
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    }
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) QName(javax.xml.namespace.QName) AnonymousXmlType(eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) XmlElementReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlElementReferenceProperty) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction) SubstitutionGroupProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.SubstitutionGroupProperty) XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 17 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class PatternTest method createCurveType.

private TypeDefinition createCurveType() {
    // create the curve type
    DefaultTypeDefinition curve = new DefaultTypeDefinition(new QName(GML_NS, "CurveType"));
    XmlElement curveElement = new XmlElement(CURVE_ELEMENT, curve, null);
    curve.getConstraint(XmlElements.class).addElement(curveElement);
    // create the segments property for curve
    TypeDefinition segArray = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "CurveSegmentArrayPropertyType"));
    new DefaultPropertyDefinition(new QName("segments"), curve, segArray);
    // create the AbstractCurveSegement property for segArray
    DefaultTypeDefinition absSeg = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "AbstractCurveSegementType"));
    absSeg.setConstraint(AbstractFlag.ENABLED);
    new DefaultPropertyDefinition(new QName("AbstractCurveSegment"), segArray, absSeg);
    // add dummy sub-type
    DefaultTypeDefinition subtype = new DefaultTypeDefinition(new QName("somespace", // $NON-NLS-1$ //$NON-NLS-2$
    "SomeSegmentType"));
    subtype.setSuperType(absSeg);
    // create the LineStringSegmentType sub-type
    DefaultTypeDefinition lineSeg = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "LineStringSegmentType"));
    lineSeg.setSuperType(absSeg);
    XmlElement lineSegElement = new XmlElement(new QName(GML_NS, "LineStringSegment"), lineSeg, new QName(GML_NS, "AbstractCurveSegment"));
    lineSeg.getConstraint(XmlElements.class).addElement(lineSegElement);
    return curve;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Example 18 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class CSVSchemaReader method loadFromSource.

@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    // $NON-NLS-1$
    progress.begin("Load CSV schema", ProgressIndicator.UNKNOWN);
    String namespace = CSVFileIO.CSVFILE_NS;
    DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
    CSVReader reader = CSVUtil.readFirst(this);
    try {
        // initializes the first line of the table (names of the columns)
        firstLine = reader.readNext();
        // create type definition
        String typename = getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class);
        if (typename == null || typename.isEmpty()) {
            reporter.setSuccess(false);
            reporter.error(new IOMessageImpl("No Typename was set", null));
            return null;
        }
        DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(typename));
        // constraints on main type
        type.setConstraint(MappingRelevantFlag.ENABLED);
        type.setConstraint(MappableFlag.ENABLED);
        type.setConstraint(HasValueFlag.DISABLED);
        type.setConstraint(AbstractFlag.DISABLED);
        // set metadata for main type
        type.setLocation(getSource().getLocation());
        StringBuffer defaultPropertyTypeBuffer = new StringBuffer();
        String[] comboSelections;
        if (getParameter(PARAM_PROPERTYTYPE).isEmpty()) {
            for (int i = 0; i < firstLine.length; i++) {
                defaultPropertyTypeBuffer.append("java.lang.String");
                defaultPropertyTypeBuffer.append(",");
            }
            defaultPropertyTypeBuffer.deleteCharAt(defaultPropertyTypeBuffer.lastIndexOf(","));
            String combs = defaultPropertyTypeBuffer.toString();
            comboSelections = combs.split(",");
        } else {
            comboSelections = getParameter(PARAM_PROPERTYTYPE).as(String.class).split(",");
        }
        String[] properties;
        if (getParameter(PARAM_PROPERTY).isEmpty()) {
            properties = firstLine;
        } else {
            properties = getParameter(PARAM_PROPERTY).as(String.class).split(",");
        }
        // than the entries in the first line
        if ((firstLine.length != properties.length && properties.length != 0) || (firstLine.length != comboSelections.length && comboSelections.length != 0)) {
            fail("Not the same number of entries for property names, property types and words in the first line of the file");
        }
        for (int i = 0; i < comboSelections.length; i++) {
            PropertyType propertyType;
            propertyType = PropertyTypeExtension.getInstance().getFactory(comboSelections[i]).createExtensionObject();
            DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(properties[i]), type, propertyType.getTypeDefinition());
            // set constraints on property
            // property.setConstraint(NillableFlag.DISABLED); // nillable
            // nillable FIXME
            property.setConstraint(NillableFlag.ENABLED);
            // should be
            // configurable
            // per field
            // (see also
            // CSVInstanceReader)
            // cardinality
            property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
            // set metadata for property
            property.setLocation(getSource().getLocation());
        }
        boolean skip = Arrays.equals(properties, firstLine);
        type.setConstraint(new CSVConfiguration(CSVUtil.getSep(this), CSVUtil.getQuote(this), CSVUtil.getEscape(this), skip));
        schema.addType(type);
    } catch (Exception ex) {
        reporter.error(new IOMessageImpl("Cannot load csv schema", ex));
        reporter.setSuccess(false);
        return null;
    }
    reporter.setSuccess(true);
    return schema;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) CSVReader(au.com.bytecode.opencsv.CSVReader) QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) PropertyType(eu.esdihumboldt.hale.io.csv.PropertyType) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Example 19 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class FilterTest method simpleFilterTestECQL.

@Test
public void simpleFilterTestECQL() throws CQLException {
    DefaultTypeDefinition stringType = new DefaultTypeDefinition(new QName("StringType"));
    stringType.setConstraint(Binding.get(String.class));
    DefaultTypeDefinition personDef = new DefaultTypeDefinition(new QName("PersonType"));
    personDef.addChild(new DefaultPropertyDefinition(new QName("Name"), personDef, stringType));
    DefaultTypeDefinition autoDef = new DefaultTypeDefinition(new QName("AutoType"));
    autoDef.addChild(new DefaultPropertyDefinition(new QName("Name"), autoDef, stringType));
    autoDef.addChild(new DefaultPropertyDefinition(new QName("Besitzer"), autoDef, personDef));
    MutableInstance auto = new DefaultInstance(autoDef, null);
    auto.addProperty(new QName("Name"), "Mein Porsche");
    MutableInstance ich = new DefaultInstance(personDef, null);
    ich.addProperty(new QName("Name"), "Ich");
    auto.addProperty(new QName("Besitzer"), ich);
    Filter filter;
    filter = new FilterGeoECqlImpl("Name = 'Mein Porsche'");
    assertTrue(filter.match(auto));
    Filter filter1 = new FilterGeoECqlImpl("Name like '%Porsche%'");
    assertTrue(filter1.match(auto));
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) QName(javax.xml.namespace.QName) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Test(org.junit.Test)

Example 20 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class Retype method doStructuralRename.

private MutableInstance doStructuralRename(FamilyInstance source, TypeDefinition targetType, boolean ignoreNamespaces, boolean copyGeometries, TransformationLog log) {
    // create a dummy child definition for the structural rename
    PropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName("dummyProp"), new DefaultTypeDefinition(new QName("dummyType")), targetType);
    Object result = Rename.structuralRename(source, dummyProp, ignoreNamespaces, getInstanceFactory(), copyGeometries);
    if (result instanceof MutableInstance) {
        return ((MutableInstance) result);
    } else {
        log.error(log.createMessage("Structural rename in type transformation failed", null));
        return null;
    }
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Aggregations

DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)20 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)18 QName (javax.xml.namespace.QName)18 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 IOException (java.io.IOException)4 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)3 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)3 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)2 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)2 PropertyType (eu.esdihumboldt.hale.io.csv.PropertyType)2 SQLArray (eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)2 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)2 AnonymousXmlType (eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType)2