Search in sources :

Example 1 with ElementReferenceProperty

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);
        }
    }
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) XmlElementReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlElementReferenceProperty) ElementReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.ElementReferenceProperty) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) Map(java.util.Map) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) HashMap(java.util.HashMap) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Aggregations

DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)1 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)1 XmlElementReferenceProperty (eu.esdihumboldt.hale.io.xsd.reader.internal.XmlElementReferenceProperty)1 ElementReferenceProperty (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.ElementReferenceProperty)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 XmlSchemaAppInfo (org.apache.ws.commons.schema.XmlSchemaAppInfo)1 Node (org.w3c.dom.Node)1