use of eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.ElementReferenceProperty in project hale by halestudio.
the class XmlSchemaReader method handleAppInfoTargetElement.
/**
* Handle reference information in XML Schema AppInfo.
*
* @param appInfos the list of AppInfos
* @param definition the property the infos are associated to
* @param index the XML index
*/
private static void handleAppInfoTargetElement(List<XmlSchemaAppInfo> appInfos, ChildDefinition<?> definition, XmlIndex index) {
Set<QName> elementNames = null;
for (final XmlSchemaAppInfo appInfo : appInfos) {
for (int i = 0; i < appInfo.getMarkup().getLength(); i++) {
final Node item = appInfo.getMarkup().item(i);
if ("targetElement".equals(item.getNodeName())) {
// TODO also check for GML namespace?
final String target = item.getTextContent();
String[] parts = target.split(":");
QName elementName = null;
if (parts.length == 1) {
elementName = new QName(parts[0]);
} else if (parts.length == 2) {
Map<String, String> namespaces = index.getPrefixes().inverse();
String ns = namespaces.get(parts[0]);
elementName = new QName(ns, parts[1]);
}
if (elementName != null) {
if (elementNames == null) {
elementNames = new HashSet<>();
}
elementNames.add(elementName);
}
}
}
}
if (elementNames != null) {
// TODO take from existing reference
List<QName> valuePath = null;
// property, if any?
ElementReferenceProperty constraint = new ElementReferenceProperty(index, valuePath, elementNames);
if (definition instanceof DefaultPropertyDefinition) {
((DefaultPropertyDefinition) definition).setConstraint(constraint);
} else if (definition instanceof DefaultGroupPropertyDefinition) {
((DefaultPropertyDefinition) definition).setConstraint(constraint);
}
}
}
Aggregations