Search in sources :

Example 6 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_types_cycle.

/**
 * Test reading a simple XML schema that uses several custom named types and
 * has a cycle.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_types_cycle() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-types-cycle.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    assertNotNull(shiporder);
    TypeDefinition type = shiporder.getType();
    assertEquals(5, type.getChildren().size());
    // contained shiporder element
    PropertyDefinition s2 = type.getChild(new QName(ns, "shiporder")).asProperty();
    assertNotNull(s2);
    assertEquals(type, s2.getPropertyType());
}
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) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 7 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_types_reverse.

/**
 * Test reading a simple XML schema that uses several custom named types.
 * The types are referenced before they are declared.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_types_reverse() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-types-r.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    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 8 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement 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 9 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_one.

/**
 * Test reading a simple XML schema that contains one big element. Focuses
 * on structure, simple type bindings and cardinalities.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_one() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-one.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    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 10 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class XmlElementsFactory method store.

@Override
public Value store(XmlElements constraint, TypeReferenceBuilder refBuilder) throws Exception {
    Collection<? extends XmlElement> elements = constraint.getElements();
    if (elements == null) {
        return null;
    }
    ValueList result = new ValueList();
    for (XmlElement element : elements) {
        result.add(elementToValue(element, refBuilder));
    }
    return result.toValue();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Aggregations

XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)37 QName (javax.xml.namespace.QName)23 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)12 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)11 URI (java.net.URI)11 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)4 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 File (java.io.File)3 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)2