Search in sources :

Example 11 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_definitive_attributegroup.

/**
 * Test reading a simple XML schema that uses an attribute group and an
 * attribute with xs:date type.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_attributegroup() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/attributegroup.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // ShirtType
    TypeDefinition type = schema.getType(new QName("ShirtType"));
    assertNotNull(type);
    // not there any more because it is flattened away
    // // IdentifierGroup
    // GroupPropertyDefinition group = type.getChild(new QName("IdentifierGroup")).asGroup();
    // assertNotNull(group);
    // // not a choice
    // assertFalse(group.getConstraint(ChoiceFlag.class).isEnabled());
    // id
    PropertyDefinition id = type.getChild(new QName("id")).asProperty();
    assertNotNull(id);
    // property type must be a simple type
    assertTrue(id.getPropertyType().getConstraint(HasValueFlag.class).isEnabled());
    // binding must be string
    assertEquals(String.class, id.getPropertyType().getConstraint(Binding.class).getBinding());
    // required
    Cardinality cc = id.getConstraint(Cardinality.class);
    assertEquals(1, cc.getMinOccurs());
    assertEquals(1, cc.getMaxOccurs());
    // version
    PropertyDefinition version = type.getChild(new QName("version")).asProperty();
    assertNotNull(version);
    // property type must be a simple type
    assertTrue(version.getPropertyType().getConstraint(HasValueFlag.class).isEnabled());
    // effDate
    PropertyDefinition effDate = type.getChild(new QName("effDate")).asProperty();
    assertNotNull(effDate);
    // binding must be compatible to Date
    assertTrue(Date.class.isAssignableFrom(effDate.getPropertyType().getConstraint(Binding.class).getBinding()));
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) URI(java.net.URI) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 12 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_unqualified.

/**
 * Test reading a simple XML schema that contains one big element and where
 * elementFormDefault/attributeFromDefault is set to unqualified and no
 * target namespace is set. Focuses on structure, simple type bindings and
 * cardinalities.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_unqualified() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-unqualified.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = XMLConstants.NULL_NS_URI;
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    // XXX use null namespace XXX not sure how to work with unqualified form
    // FIXME target namespace no effect?! should the target namespace always
    // be injected?
    testShiporderStructure(shiporder, ns);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 13 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_divided.

/**
 * Test reading a simple XML schema that contains several elements
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_divided() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-divided.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // element count
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(12, elements.size());
    // shiporder element
    XmlElement shiporder = schema.getElements().get(new QName(ns, "shiporder"));
    testShiporderStructure(shiporder, ns);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 14 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class GmlInstanceCollectionTest method loadInstances.

private GmlInstanceCollection loadInstances(URI schemaLocation, URI xmlLocation, boolean restrictToFeatures, boolean ignoreNamespace) throws IOException, IOProviderConfigurationException {
    SchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(null);
    reader.setSource(new DefaultInputSupplier(schemaLocation));
    IOReport schemaReport = reader.execute(null);
    assertTrue(schemaReport.isSuccess());
    Schema sourceSchema = reader.getSchema();
    return new GmlInstanceCollection(new DefaultInputSupplier(xmlLocation), sourceSchema, restrictToFeatures, false, true, ignoreNamespace, null, reader);
}
Also used : SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 15 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class SpatiaLiteInstanceReader method loadConfiguration.

@Override
public void loadConfiguration(Map<String, Value> configuration) {
    super.loadConfiguration(configuration);
    Value source = configuration.get(PARAM_SOURCE);
    if (source != null && !source.isEmpty()) {
        setSource(new DefaultInputSupplier(URI.create(source.as(String.class))));
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Value(eu.esdihumboldt.hale.common.core.io.Value)

Aggregations

DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)73 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)34 URI (java.net.URI)30 Test (org.junit.Test)21 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)15 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)15 IOException (java.io.IOException)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)11 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)10 QName (javax.xml.namespace.QName)10 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)9 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 File (java.io.File)6