use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex 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()));
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex 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);
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex 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);
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.
the class XmlSchemaReader method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// $NON-NLS-1$
progress.begin(Messages.getString("ApacheSchemaProvider.21"), ProgressIndicator.UNKNOWN);
this.reporter = reporter;
XmlSchema xmlSchema = null;
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
// Check if the file is located on web
URI location = getSource().getLocation();
if (location.getHost() == null) {
schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
schemaCol.setBaseUri(findBaseUri(location));
} else if (location.getScheme().equals("bundleresource")) {
// $NON-NLS-1$
schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
// $NON-NLS-1$
schemaCol.setBaseUri(findBaseUri(location) + "/");
} else {
schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
// $NON-NLS-1$
schemaCol.setBaseUri(findBaseUri(location) + "/");
}
InputStream is = null;
// try resolving using (local) Resources
InputSupplier<? extends InputStream> input = Resources.tryResolve(location, Resources.RESOURCE_TYPE_XML_SCHEMA);
if (input != null) {
try {
is = input.getInput();
} catch (Exception e) {
// ignore
}
}
if (is == null) {
is = getSource().getInput();
}
StreamSource ss = new StreamSource(is);
ss.setSystemId(location.toString());
xmlSchema = schemaCol.read(ss, null);
is.close();
String namespace = xmlSchema.getTargetNamespace();
if (namespace == null) {
namespace = XMLConstants.NULL_NS_URI;
}
xmlSchema.setSourceURI(location.toString());
// create index
index = new XmlIndex(namespace, location);
// create group counter
groupCounter = new TObjectIntHashMap<String>();
Set<String> imports = new HashSet<String>();
imports.add(location.toString());
// load XML Schema schema (for base type definitions)
try {
is = XmlSchemaReader.class.getResourceAsStream("/schemas/XMLSchema.xsd");
ss = new StreamSource(is);
schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
schemaCol.setBaseUri(findBaseUri(XmlSchemaReader.class.getResource("/schemas/XMLSchema.xsd").toURI()) + "/");
XmlSchema xsSchema = schemaCol.read(ss, null);
is.close();
xsSchema.setSourceURI("http://www.w3.org/2001/XMLSchema.xsd");
XmlSchemaImport xmlSchemaImport = new XmlSchemaImport();
xmlSchemaImport.setSchema(xsSchema);
// add it to includes as XmlSchemaImport (not XmlSchemaInclude!)
xmlSchema.getIncludes().add(xmlSchemaImport);
} catch (Exception e) {
_log.error("Exception while loading XML Schema schema", e);
}
loadSchema(location.toString(), xmlSchema, imports, progress, true);
groupCounter.clear();
// post processing
applyRelevantElements(index);
applyCustomTypeContent(index);
reporter.setSuccess(true);
return reporter;
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.
the class RootElementPage method updateList.
private void updateList() {
if (// during enable if content not yet created
list != null && getWizard().getProvider() != null) {
// TODO instead of showing all elements allow filtering for elements
// that can hold the type in some form?
SchemaSpace schemas = getWizard().getProvider().getTargetSchema();
XmlIndex index = StreamGmlWriter.getXMLIndex(schemas);
// FIXME use filtered table for selection?
list.setInput(index.getElements().values());
setPageComplete(!list.getSelection().isEmpty());
}
}
Aggregations