Java Code Examples for org.apache.ws.commons.schema.XmlSchema#setNamespaceContext()
The following examples show how to use
org.apache.ws.commons.schema.XmlSchema#setNamespaceContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXBSchemaInitializer.java From cxf with Apache License 2.0 | 6 votes |
private SchemaInfo createSchemaIfNeeded(String namespace, NamespaceMap nsMap) { SchemaInfo schemaInfo = serviceInfo.getSchema(namespace); if (schemaInfo == null) { XmlSchema xmlSchema = schemas.newXmlSchemaInCollection(namespace); if (qualifiedSchemas) { xmlSchema.setElementFormDefault(XmlSchemaForm.QUALIFIED); } xmlSchema.setNamespaceContext(nsMap); schemaInfo = new SchemaInfo(namespace); schemaInfo.setSchema(xmlSchema); serviceInfo.addSchema(schemaInfo); } return schemaInfo; }
Example 2
Source File: Cob2Xsd.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
/** * Create an empty XML Schema. * <p/> * If no targetNamespace, make sure there is no default namespace otherwise * our complex types would be considered part of that default namespace * (usually XML Schema namespace). * * @param encoding the character set used to encode this XML Schema * @param targetNamespace the target namespace to use (null for no namespace) * @return a new empty XML schema using the model */ protected XmlSchema createXmlSchema(final String encoding, final String targetNamespace) { XmlSchema xsd = new XmlSchema(targetNamespace, new XmlSchemaCollection()); if (targetNamespace != null) { xsd.setElementFormDefault(XmlSchemaForm.QUALIFIED); } xsd.setAttributeFormDefault(null); xsd.setInputEncoding(encoding); if (targetNamespace == null) { NamespaceMap prefixmap = new NamespaceMap(); NamespacePrefixList npl = xsd.getNamespaceContext(); if (npl == null) { prefixmap.add("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI); } else { for (int i = 0; i < npl.getDeclaredPrefixes().length; i++) { String prefix = npl.getDeclaredPrefixes()[i]; String namespace = npl.getNamespaceURI(prefix); if (namespace.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) { if (prefix.equals("")) { prefix = "xsd"; } } prefixmap.add(prefix, namespace); } } xsd.setNamespaceContext(prefixmap); } return xsd; }
Example 3
Source File: AbstractAegisTest.java From cxf with Apache License 2.0 | 5 votes |
protected XmlSchema newXmlSchema(String targetNamespace) { XmlSchema s = new XmlSchema(); s.setTargetNamespace(targetNamespace); NamespaceMap xmlsNamespaceMap = new NamespaceMap(); s.setNamespaceContext(xmlsNamespaceMap); // tns: is conventional, and besides we have unit tests that are hardcoded to it. xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, targetNamespace); // ditto for xsd: instead of just namespace= for the schema schema. xmlsNamespaceMap.add("xsd", Constants.URI_2001_SCHEMA_XSD); return s; }
Example 4
Source File: JAXBSchemaInitializer.java From cxf with Apache License 2.0 | 5 votes |
private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) { XmlSchemaElement el = null; SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI()); if (schemaInfo != null) { el = schemaInfo.getElementByQName(qn); if (el == null) { createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo); } else if (!typeName.equals(el.getSchemaTypeName())) { throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG, qn, typeName, el.getSchemaTypeName())); } return; } XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI()); if (qualifiedSchemas) { schema.setElementFormDefault(XmlSchemaForm.QUALIFIED); } schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false); schemaInfo.setSchema(schema); el = createXsElement(schema, part, typeName, schemaInfo); NamespaceMap nsMap = new NamespaceMap(); nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace()); nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); schema.setNamespaceContext(nsMap); serviceInfo.addSchema(schemaInfo); }
Example 5
Source File: ImportRepairTest.java From cxf with Apache License 2.0 | 5 votes |
private XmlSchema newSchema(String uri) { XmlSchema schema = collection.newXmlSchemaInCollection(uri); NamespaceMap map = new NamespaceMap(); map.add("", XMLConstants.W3C_XML_SCHEMA_NS_URI); schema.setNamespaceContext(map); return schema; }
Example 6
Source File: ReflectionServiceFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo, String namespaceURI, boolean qualified) { for (SchemaInfo s : serviceInfo.getSchemas()) { if (s.getNamespaceURI().equals(namespaceURI)) { return s; } } SchemaInfo schemaInfo = new SchemaInfo(namespaceURI); SchemaCollection col = serviceInfo.getXmlSchemaCollection(); XmlSchema schema = col.getSchemaByTargetNamespace(namespaceURI); if (schema != null) { schemaInfo.setSchema(schema); serviceInfo.addSchema(schemaInfo); return schemaInfo; } schema = col.newXmlSchemaInCollection(namespaceURI); if (qualified) { schema.setElementFormDefault(XmlSchemaForm.QUALIFIED); } schemaInfo.setSchema(schema); Map<String, String> explicitNamespaceMappings = this.getDataBinding().getDeclaredNamespaceMappings(); if (explicitNamespaceMappings == null) { explicitNamespaceMappings = Collections.emptyMap(); } NamespaceMap nsMap = new NamespaceMap(); for (Map.Entry<String, String> mapping : explicitNamespaceMappings.entrySet()) { nsMap.add(mapping.getValue(), mapping.getKey()); } if (!explicitNamespaceMappings.containsKey(WSDLConstants.NS_SCHEMA_XSD)) { nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); } if (!explicitNamespaceMappings.containsKey(serviceInfo.getTargetNamespace())) { nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, serviceInfo.getTargetNamespace()); } schema.setNamespaceContext(nsMap); serviceInfo.addSchema(schemaInfo); return schemaInfo; }
Example 7
Source File: SchemaInfo.java From cxf with Apache License 2.0 | 4 votes |
/** * Build and return a DOM tree for this schema. * @return a DOM Element representation of the schema */ public synchronized Element getElement() { // if someone recently used this DOM tree, take advantage. Element element = cachedElement == null ? null : cachedElement.get(); if (element != null) { return element; } if (getSchema() == null) { throw new RuntimeException("No XmlSchema in SchemaInfo"); } XmlSchema sch = getSchema(); synchronized (sch) { XmlSchema schAgain = getSchema(); // XML Schema blows up when the context is null as opposed to empty. // Some unit tests really want to see 'tns:'. if (schAgain.getNamespaceContext() == null) { NamespaceMap nsMap = new NamespaceMap(); nsMap.add("xsd", Constants.URI_2001_SCHEMA_XSD); nsMap.add("tns", schAgain.getTargetNamespace()); schAgain.setNamespaceContext(nsMap); } Document serializedSchema; try { serializedSchema = schAgain.getSchemaDocument(); } catch (XmlSchemaSerializerException e) { throw new RuntimeException("Error serializing Xml Schema", e); } element = serializedSchema.getDocumentElement(); cachedElement = new SoftReference<>(element); } // A problem can occur with the ibm jdk when the XmlSchema // object is serialized. The xmlns declaration gets incorrectly // set to the same value as the targetNamespace attribute. // The aegis databinding tests demonstrate this particularly. if (element.getPrefix() == null && !Constants.URI_2001_SCHEMA_XSD.equals(element.getAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE))) { Attr attr = element.getOwnerDocument() .createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE); attr.setValue(Constants.URI_2001_SCHEMA_XSD); element.setAttributeNodeNS(attr); } return element; }