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));
}
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());
}
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;
}
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));
}
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;
}
Aggregations