Search in sources :

Example 6 with XmlSchemaAppInfo

use of org.apache.ws.commons.schema.XmlSchemaAppInfo 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)

Example 7 with XmlSchemaAppInfo

use of org.apache.ws.commons.schema.XmlSchemaAppInfo in project cxf by apache.

the class ObjectReferenceVisitor method isDuplicateReference.

private void isDuplicateReference(QName referenceName, QName bindingName, Scope refScope, XmlSchemaType wsaType, AST node) {
    XmlSchema refSchema;
    if (!mapper.isDefaultMapping()) {
        String tns = mapper.map(refScope.getParent());
        String refSchemaFileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + refScope.getParent().toString("_") + ".xsd";
        refSchema = manager.getXmlSchema(tns);
        if (refSchema == null) {
            refSchema = manager.createXmlSchema(tns, wsdlVisitor.getSchemas());
        }
        addWSAddressingImport(refSchema);
        manager.addXmlSchemaImport(schema, refSchema, refSchemaFileName);
    } else {
        refSchema = schema;
    }
    // we have, then there is no need to add it to the schema again.
    if (!isReferenceSchemaTypeDefined(referenceName, refSchema)) {
        // We need to add a new element definition to the schema section of our WSDL.
        // For custom endpoint types, this should contain an annotation which points
        // to the binding which will be used for this endpoint type.
        XmlSchemaElement refElement = new XmlSchemaElement(schema, true);
        refElement.setName(referenceName.getLocalPart());
        refElement.setSchemaType(wsaType);
        refElement.setSchemaTypeName(wsaType.getQName());
        // Create an annotation which contains the CORBA binding for the element
        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
        XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.newDocument();
            Element el = doc.createElement("appinfo");
            el.setTextContent("corba:binding=" + bindingName.getLocalPart());
            // TODO: This is correct but the appinfo markup is never added to the
            // schema.  Investigate.
            appInfo.setMarkup(el.getChildNodes());
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException("[ObjectReferenceVisitor: error creating endpoint schema]");
        }
        annotation.getItems().add(appInfo);
        refElement.setAnnotation(annotation);
    }
}
Also used : XmlSchemaAnnotation(org.apache.ws.commons.schema.XmlSchemaAnnotation) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmlSchema(org.apache.ws.commons.schema.XmlSchema) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Aggregations

XmlSchemaAppInfo (org.apache.ws.commons.schema.XmlSchemaAppInfo)7 QName (javax.xml.namespace.QName)4 Node (org.w3c.dom.Node)4 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)3 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 XmlSchemaAnnotation (org.apache.ws.commons.schema.XmlSchemaAnnotation)3 XmlSchemaAnnotationItem (org.apache.ws.commons.schema.XmlSchemaAnnotationItem)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 NodeList (org.w3c.dom.NodeList)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)2 XmlAppInfo (eu.esdihumboldt.hale.io.xsd.constraint.XmlAppInfo)2 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)2 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)2 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)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 Binding (javax.wsdl.Binding)1