Search in sources :

Example 1 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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 2 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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 3 with DefaultTypeDefinition

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

the class SQLSchemaReader method addTableType.

/**
 * Create the type definition for a query.
 *
 * @param query the SQL query
 * @param namespace the namespace for the type
 * @param types the schema to add the type to
 * @param connection the database connection
 * @param reporter the reporter
 * @param typename the name to use for the type
 *
 * @return the type definition for the given table
 */
private TypeDefinition addTableType(String query, String namespace, DefaultSchema types, Connection connection, IOReporter reporter, String typename) {
    QName typeName = new QName(namespace, unquote(typename));
    // check for existing type
    TypeDefinition existingType = types.getType(typeName);
    if (existingType != null)
        return existingType;
    // create new type
    DefaultTypeDefinition type = new DefaultTypeDefinition(typeName);
    // set SQL query as description
    type.setDescription(query);
    type.setConstraint(new SQLQuery(query));
    // configure type
    type.setConstraint(MappableFlag.ENABLED);
    type.setConstraint(MappingRelevantFlag.ENABLED);
    type.setConstraint(HasValueFlag.DISABLED);
    types.addType(type);
    return type;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) QName(javax.xml.namespace.QName) SQLQuery(eu.esdihumboldt.hale.io.jdbc.constraints.SQLQuery) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 4 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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
 * @param index the XML index
 */
public static void setMetadata(AbstractDefinition<?> definition, XmlSchemaAnnotated annotated, String schemaLocation, XmlIndex index) {
    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);
        }
        if (definition instanceof ChildDefinition<?>) {
            handleAppInfoTargetElement(appInfo, (ChildDefinition<?>) definition, index);
        }
    }
    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) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) XmlAppInfo(eu.esdihumboldt.hale.io.xsd.constraint.XmlAppInfo) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Example 5 with DefaultTypeDefinition

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

the class ComplexContentHasValue method isEnabled.

@Override
public boolean isEnabled() {
    if (!initialized) {
        // evaluate on first access (because we access other constraints and
        // structural information)
        // check if type is mixed
        boolean mixed = typeDef.getConstraint(XmlMixedFlag.class).isEnabled();
        if (mixed) {
            hasValue = true;
        } else {
            DefaultTypeDefinition superType = typeDef.getSuperType();
            if (superType != null && superType.getConstraint(HasValueFlag.class).isEnabled()) {
                // if the parent type allows values (e.g. anyType)
                // check if there are element (or group) children
                boolean nonAttributeChildren = typeDef.getChildren().stream().anyMatch(e -> e.asGroup() != null || !e.asProperty().getConstraint(XmlAttributeFlag.class).isEnabled());
                hasValue = !nonAttributeChildren;
            }
        }
        initialized = true;
    }
    return hasValue;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) XmlMixedFlag(eu.esdihumboldt.hale.io.xsd.constraint.XmlMixedFlag)

Aggregations

DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)28 QName (javax.xml.namespace.QName)23 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)18 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)7 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)5 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 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)3 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2