Search in sources :

Example 1 with DefaultPropertyDefinition

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

the class ShapeSchemaReader method loadFromSource.

@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    // $NON-NLS-1$
    progress.begin(Messages.getString("ShapeSchemaProvider.1"), ProgressIndicator.UNKNOWN);
    // DataStore store = new ShapefileDataStoreFactory().createDataStore(location.toURL());
    // DataStore store = FileDataStoreFinder.getDataStore(getSource().getLocation().toURL());
    ShapefileDataStore store = new ShapefileDataStore(getSource().getLocation().toURL());
    store.setCharset(getCharset());
    // TODO namespace from configuration parameter?!
    String namespace = ShapefileConstants.SHAPEFILE_NS;
    DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
    // $NON-NLS-1$
    progress.setCurrentTask(Messages.getString("ShapeSchemaProvider.2"));
    // create type for augmented filename property
    QName filenameTypeName = new QName(SHAPEFILE_AUGMENT_NS, "filenameType");
    TypeDefinition filenameType = null;
    if (getSharedTypes() != null) {
        filenameType = getSharedTypes().getType(filenameTypeName);
    }
    if (filenameType == null) {
        DefaultTypeDefinition fnt = new DefaultTypeDefinition(filenameTypeName);
        fnt.setConstraint(MappableFlag.DISABLED);
        fnt.setConstraint(MappingRelevantFlag.DISABLED);
        fnt.setConstraint(Binding.get(String.class));
        fnt.setConstraint(HasValueFlag.ENABLED);
        filenameType = fnt;
    }
    // build type definitions based on Schema extracted by geotools
    for (Name name : store.getNames()) {
        SimpleFeatureType sft = store.getSchema(name);
        try {
            // create type definition
            DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(namespace, sft.getName().getLocalPart()));
            // constraints on main type
            type.setConstraint(MappingRelevantFlag.ENABLED);
            type.setConstraint(MappableFlag.ENABLED);
            type.setConstraint(HasValueFlag.DISABLED);
            type.setConstraint(AbstractFlag.DISABLED);
            type.setConstraint(Binding.get(Instance.class));
            for (AttributeDescriptor ad : sft.getAttributeDescriptors()) {
                DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(ad.getLocalName()), type, getTypeFromAttributeType(ad.getType(), schema, namespace));
                // set constraints on property
                // nillable
                property.setConstraint(NillableFlag.get(ad.isNillable()));
                // cardinality
                property.setConstraint(Cardinality.get(ad.getMinOccurs(), ad.getMaxOccurs()));
                // set metadata
                property.setLocation(getSource().getLocation());
            }
            // add additional filename property
            // String filename = sft.getName().getLocalPart();
            DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(SHAPEFILE_AUGMENT_NS, AUGMENTED_PROPERTY_FILENAME), type, filenameType);
            property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
            property.setConstraint(NillableFlag.ENABLED);
            schema.addType(type);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        progress.setCurrentTask(MessageFormat.format(// $NON-NLS-1$
        Messages.getString("ShapeSchemaProvider.7"), sft.getTypeName()));
    }
    reporter.setSuccess(true);
    return schema;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Name(org.opengis.feature.type.Name) QName(javax.xml.namespace.QName) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Example 2 with DefaultPropertyDefinition

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

the class XLSSchemaReader method loadFromSource.

@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    sheetNum = getParameter(InstanceTableIOConstants.SHEET_INDEX).as(int.class, 0);
    progress.begin("Load XLS/XLSX schema", ProgressIndicator.UNKNOWN);
    String namespace = "http://www.esdi-humboldt.eu/hale/xls";
    DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
    AnalyseXLSSchemaTable analyser;
    try {
        analyser = new AnalyseXLSSchemaTable(getSource().getLocation(), sheetNum);
        header = analyser.getHeader();
        // 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 < header.size(); 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 = header.toArray(new String[0]);
        } else {
            properties = getParameter(PARAM_PROPERTY).as(String.class).split(",");
        }
        // than the entries in the first line
        if ((header.size() != properties.length && properties.length != 0) || (header.size() != 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 = PropertyTypeExtension.getInstance().getFactory(comboSelections[i]).createExtensionObject();
            DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(properties[i]), type, propertyType.getTypeDefinition());
            configureProperty(property);
        }
        boolean skip = Arrays.equals(properties, header.toArray(new String[0]));
        type.setConstraint(new CSVConfiguration(CSVUtil.getSep(this), CSVUtil.getQuote(this), CSVUtil.getEscape(this), skip));
        schema.addType(type);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Cannot load xls/xlsx schema", e));
        reporter.setSuccess(false);
        return null;
    }
    reporter.setSuccess(true);
    return schema;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) AnalyseXLSSchemaTable(eu.esdihumboldt.hale.io.xls.AnalyseXLSSchemaTable) 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) CSVConfiguration(eu.esdihumboldt.hale.io.csv.reader.internal.CSVConfiguration) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Example 3 with DefaultPropertyDefinition

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

the class XmlSchemaReader method setMetadata.

/**
 * Set the metadata for a definition
 *
 * @param definition the definition
 * @param annotated the XML annotated object
 * @param schemaLocation the schema location
 */
public static void setMetadata(AbstractDefinition<?> definition, XmlSchemaAnnotated annotated, String schemaLocation) {
    definition.setDescription(XMLSchemaIO.getDescription(annotated));
    List<XmlSchemaAppInfo> appInfo = XMLSchemaIO.getAppInfo(annotated);
    if (appInfo != null) {
        XmlAppInfo constraint = new XmlAppInfo(appInfo);
        if (definition instanceof DefaultPropertyDefinition) {
            ((DefaultPropertyDefinition) definition).setConstraint(constraint);
        } else if (definition instanceof DefaultGroupPropertyDefinition) {
            ((DefaultGroupPropertyDefinition) definition).setConstraint(constraint);
        } else if (definition instanceof DefaultTypeDefinition) {
            ((DefaultTypeDefinition) definition).setConstraint(constraint);
        }
    }
    definition.setLocation(createLocationURI(schemaLocation, annotated));
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) XmlAppInfo(eu.esdihumboldt.hale.io.xsd.constraint.XmlAppInfo) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Example 4 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition 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)

Example 5 with DefaultPropertyDefinition

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

the class PropertyFunctionScriptPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            // create a dummy type with the variables as children
            DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
            DefaultCustomPropertyFunction cf = getWizard().getUnfinishedFunction();
            int index = 0;
            for (EntityDefinition variable : getVariables()) {
                DefaultCustomPropertyFunctionEntity source = cf.getSources().get(index);
                if (variable.getDefinition() instanceof PropertyDefinition) {
                    PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
                    TypeDefinition propertyType;
                    boolean useInstanceValue = CustomGroovyTransformation.useInstanceVariableForSource(source);
                    if (useInstanceValue) {
                        // use instance type
                        propertyType = prop.getPropertyType();
                    } else {
                        // use dummy type with only the
                        // binding/HasValueFlag copied
                        DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
                        propertyType = crippledType;
                    }
                    DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(source.getName()), dummy, propertyType);
                    // number of times
                    if (source.isEager())
                        dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
                }
                index++;
            }
            return Collections.singleton(dummy);
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            DefaultCustomPropertyFunctionEntity target = getWizard().getUnfinishedFunction().getTarget();
            if (target != null) {
                return Collections.singleton(createDummyType(target));
            }
            return Collections.emptyList();
        }
    });
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) DefaultCustomPropertyFunctionEntity(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunctionEntity) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

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