Search in sources :

Example 71 with TypeDefinition

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

the class XsltGenerator method writeContainerFragment.

/**
 * Write the container fragment.
 *
 * @param templateFile the file to write to
 * @param groupedResults the result variable names grouped by associated
 *            target type
 * @param targetElements an empty map that is populated with variable names
 *            mapped to target element names
 * @throws IOException if an error occurs writing the template
 * @throws XMLStreamException if an error occurs writing XML content to the
 *             template
 */
private void writeContainerFragment(File templateFile, Multimap<TypeDefinition, String> groupedResults, Map<String, QName> targetElements) throws XMLStreamException, IOException {
    XMLStreamWriter writer = XslTransformationUtil.setupXMLWriter(new BufferedOutputStream(new FileOutputStream(templateFile)), prefixes);
    try {
        // write container
        GmlWriterUtil.writeStartElement(writer, targetContainer.getName());
        // generate an eventual required identifier on the container
        GmlWriterUtil.writeRequiredID(writer, targetContainer.getType(), null, false);
        writeContainerIntro(writer, context);
        // cache definition paths
        Map<TypeDefinition, DefinitionPath> paths = new HashMap<TypeDefinition, DefinitionPath>();
        Descent lastDescent = null;
        for (Entry<TypeDefinition, String> entry : groupedResults.entries()) {
            TypeDefinition type = entry.getKey();
            // get stored definition path for the type
            DefinitionPath defPath;
            if (paths.containsKey(type)) {
                // get the stored path, may be null
                defPath = paths.get(type);
            } else {
                // determine a valid definition path in the container
                defPath = findMemberAttribute(targetContainer, type);
                // store path (may be null)
                paths.put(type, defPath);
            }
            if (defPath != null) {
                // insert xsl:for-each at the appropriate position in
                // the path
                defPath = pathInsertForEach(defPath, entry.getValue(), targetElements);
                lastDescent = Descent.descend(writer, defPath, lastDescent, false, true);
                // write single target instance from variable
                GmlWriterUtil.writeEmptyElement(writer, new QName(NS_URI_XSL, "copy-of"));
                writer.writeAttribute("select", ".");
            } else {
                reporter.warn(new IOMessageImpl(MessageFormat.format("No compatible member attribute for type {0} found in root element {1}, one instance was skipped", type.getDisplayName(), targetContainer.getName().getLocalPart()), null));
            }
        }
        if (lastDescent != null) {
            lastDescent.close();
        }
        // end container
        writer.writeEndElement();
    } finally {
        writer.close();
    }
}
Also used : HashMap(java.util.HashMap) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) FileOutputStream(java.io.FileOutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath) BufferedOutputStream(java.io.BufferedOutputStream) Descent(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.Descent) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 72 with TypeDefinition

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

the class GeotoolsFilterToXPath method visit.

/**
 * @see org.opengis.filter.expression.ExpressionVisitor#visit(org.opengis.filter.expression.PropertyName,
 *      java.lang.Object)
 */
@Override
public Object visit(PropertyName expression, Object buffer) {
    StringBuffer result = asStringBuffer(buffer);
    TypeDefinition rootType = typeDef;
    String path = expression.getPropertyName();
    boolean propertyModeValue = true;
    if (propertyFilter) {
        // value directly referenced
        if ("value".equals(path)) {
            // means we reference the current context
            // XXX is this correct?
            result.append('.');
            return result;
        } else if (path.startsWith("parent/")) {
            rootType = parentType;
            propertyModeValue = false;
            // remove prefix from path
            path = path.substring(7);
        } else if (path.startsWith("value/")) {
            // remove prefix from path
            path = path.substring(6);
        }
    }
    List<List<QName>> paths = PropertyResolver.getQueryPaths(rootType, DataSet.SOURCE, path);
    // TODO what about no / multiple paths
    List<QName> qnames = paths.get(0);
    if (propertyFilter && !propertyModeValue) {
        // parent mode, we have to prepend the reference to the parent
        result.append("../");
    }
    Definition<?> parent = rootType;
    boolean first = true;
    for (int i = 0; i < qnames.size(); i++) {
        // get the element qualified name
        QName segment = qnames.get(i);
        // get the associated definition
        ChildDefinition<?> def = DefinitionUtil.getChild(parent, segment);
        if (def.asProperty() != null) {
            if (first) {
                first = false;
            } else {
                result.append('/');
            }
            if (def.asProperty().getConstraint(XmlAttributeFlag.class).isEnabled()) {
                // attributes need to be marked w/ @
                result.append('@');
            }
            // add the qualified name
            result.append(qNameToXPathSegment(segment));
        }
        parent = def;
    }
    return result;
}
Also used : QName(javax.xml.namespace.QName) List(java.util.List) XmlAttributeFlag(eu.esdihumboldt.hale.io.xsd.constraint.XmlAttributeFlag) Disjoint(org.opengis.filter.spatial.Disjoint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 73 with TypeDefinition

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

the class FeatureChainingComplexTypeTest method testBackAndForth.

/**
 * Tests converting a feature chaining configuration to DOM and back.
 */
@Test
public void testBackAndForth() {
    FeatureChaining testConf = new FeatureChaining();
    TypeDefinition fakeType = new DefaultTypeDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeType"));
    PropertyDefinition fakeProperty0 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0PropertyType")));
    PropertyDefinition fakeProperty1 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0Type")));
    List<ChildContext> path0 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1) });
    ChainConfiguration chain0 = new ChainConfiguration();
    chain0.setChainIndex(0);
    chain0.setPrevChainIndex(-1);
    chain0.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path0, SchemaSpaceID.TARGET, null));
    PropertyDefinition fakeProperty2 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1PropertyType")));
    PropertyDefinition fakeProperty3 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1Type")));
    List<ChildContext> path1 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1), new ChildContext(fakeProperty2), new ChildContext(fakeProperty3) });
    ChainConfiguration chain1 = new ChainConfiguration();
    chain1.setChainIndex(1);
    chain1.setPrevChainIndex(0);
    chain1.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path1, SchemaSpaceID.TARGET, null));
    chain1.setMappingName("fakeMapping");
    testConf.putChain("test-join", 0, chain0);
    testConf.putChain("test-join", 1, chain1);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(testConf);
    // convert back
    FeatureChaining converted = HaleIO.getComplexValue(fragment, FeatureChaining.class, null);
    assertNotNull(converted);
    assertFalse(converted.equals(testConf));
    Map<String, JoinConfiguration> joins = converted.getJoins();
    assertNotNull(joins);
    assertEquals(1, joins.size());
    JoinConfiguration join = joins.get("test-join");
    assertNotNull(join);
    assertEquals(2, join.getChains().size());
    ChainConfiguration convChain0 = join.getChain(0);
    assertNotNull(convChain0);
    assertEquals(0, convChain0.getChainIndex());
    assertEquals(-1, convChain0.getPrevChainIndex());
    assertTrue(convChain0.getMappingName() == null);
    PropertyType convPropertyType0 = convChain0.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType0);
    assertEquals("FakeType", convPropertyType0.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getType().getNs());
    assertEquals(2, convPropertyType0.getChild().size());
    assertEquals("fakeProperty0", convPropertyType0.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType0.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(1).getNs());
    ChainConfiguration convChain1 = join.getChain(1);
    assertNotNull(convChain1);
    assertEquals(1, convChain1.getChainIndex());
    assertEquals(0, convChain1.getPrevChainIndex());
    assertEquals("fakeMapping", convChain1.getMappingName());
    PropertyType convPropertyType1 = convChain1.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType1);
    assertEquals("FakeType", convPropertyType1.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getType().getNs());
    assertEquals(4, convPropertyType1.getChild().size());
    assertEquals("fakeProperty0", convPropertyType1.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType1.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(1).getNs());
    assertEquals("fakeProperty1", convPropertyType1.getChild().get(2).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(2).getNs());
    assertEquals("FakeNestedType1", convPropertyType1.getChild().get(3).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(3).getNs());
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Test(org.junit.Test)

Example 74 with TypeDefinition

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

the class AppSchemaMappingUtils method findOwningFeatureTypeIndex.

private static int findOwningFeatureTypeIndex(List<ChildContext> propertyPath) {
    for (int i = propertyPath.size() - 1; i >= 0; i--) {
        ChildContext childContext = propertyPath.get(i);
        TypeDefinition parentType = childContext.getChild().getParentType();
        if (isFeatureType(parentType)) {
            return i;
        }
    }
    return -1;
}
Also used : ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 75 with TypeDefinition

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

the class AppSchemaMappingUtils method findOwningTypeIndex.

private static int findOwningTypeIndex(List<ChildContext> propertyPath, Collection<? extends TypeDefinition> allowedTypes) {
    for (int i = propertyPath.size() - 1; i >= 0; i--) {
        ChildContext childContext = propertyPath.get(i);
        TypeDefinition parentType = childContext.getChild().getParentType();
        if (allowedTypes.contains(parentType)) {
            return i;
        }
    }
    return -1;
}
Also used : ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12