Package org.apache.ws.commons.schema.utils

Examples of org.apache.ws.commons.schema.utils.NamespacePrefixList


                if (value.indexOf(":") > -1 && !nodeName.startsWith("xmlns")) {
                    String prefix = value.substring(0, value.indexOf(":"));
                    String oldNamespace;
                    if ((oldNamespace = (String) namespaces.get(prefix)) != null) {
                        value = value.substring(value.indexOf(":") + 1);
                        NamespacePrefixList ctx = schema.getNamespaceContext();
                        String[] prefixes = ctx.getDeclaredPrefixes();
                        for (int j = 0;  j < prefixes.length;  j++) {
                            String pref = prefixes[j];
                            String uri = ctx.getNamespaceURI(pref);
                            if (uri.equals(oldNamespace)) {
                                value = prefix + ":" + value;
                            }
                        }
                    }
View Full Code Here


                    String prefix = value.substring(0, value.indexOf(":"));
                    String oldNamespace;
                    oldNamespace = namespaces.get(prefix);
                    if (oldNamespace != null) {
                        value = value.substring(value.indexOf(":") + 1);
                        NamespacePrefixList ctx = schema.getNamespaceContext();
                        String[] prefixes = ctx.getDeclaredPrefixes();
                        for (String pref : prefixes) {
                            String uri = ctx.getNamespaceURI(pref);
                            if (uri.equals(oldNamespace)) {
                                value = prefix + ":" + value;
                            }
                        }
                    }
View Full Code Here

    /**
     * Set up <schema> namespaces appropriately and append that attr
     * into specified element
     */
    private Element setupNamespaces(Document schemaDocs, XmlSchema schemaObj) {
        NamespacePrefixList ctx = schemaObj.getNamespaceContext();
        if (ctx != null) {
            xsdPrefix = ctx.getPrefix(XSD_NAMESPACE);
        } else {
            xsdPrefix = null;
        }

        if (xsdPrefix == null) {
            //find a prefix to use
            xsdPrefix = "";
            if (ctx != null && ctx.getNamespaceURI(xsdPrefix) != null) {
                xsdPrefix = "xsd";
            }
            int count = 0;
            while (ctx != null && ctx.getNamespaceURI(xsdPrefix) != null) {
                xsdPrefix = "xsd" + ++count;
            }
        }
        schemaObj.setSchemaNamespacePrefix(xsdPrefix);


        Element schemaEl = createNewElement(schemaDocs, "schema",
                                            schemaObj.getSchemaNamespacePrefix(), XmlSchema.SCHEMA_NS);

        if (ctx != null) {
            String[] prefixes = ctx.getDeclaredPrefixes();
            for (int i = 0;  i < prefixes.length;  i++) {
                String prefix = prefixes[i];
                String uri = ctx.getNamespaceURI(prefix);
                if (uri != null && prefix != null) {
                    if ("".equals(prefix) || !schemaNamespace.containsKey(uri)) {
                        schemaNamespace.put(uri, prefix);
                    }
                    prefix = (prefix.length() > 0) ? "xmlns:" + prefix : "xmlns";
View Full Code Here

   * Extract the element declarations from the given schema.
   */
  private void buildElementDeclarations(XmlSchema schemaDef, String schemaTns, URI typeSystemURI) {
       
      XmlSchemaObjectTable elementTable = schemaDef.getElements();
        NamespacePrefixList prefixes = schemaDef.getNamespaceContext();
      Iterator qnames = elementTable.getNames();
      while (qnames.hasNext()) {
          QName xseQN = (QName) qnames.next();
            if(fDesc.getElementDeclaration(xseQN) != null) {
                //The Description already contains this Element Declaration.
                continue;
                //This check is necessary because the XmlSchema.equals method, which gets used
                //to evaluate fSchemas.contains(..), cannot detect the equivalence of a schema
                //that is xs:imported within <wsdl:types> and also xs:imported within by
                //an inlined schema within the same <wsdl:types> element.
                //Error case is result.xsd in the W3C WSDL 2.0 test case SparqlQuerySimplified-1G.
                //This check may be necessary anyway, because if the document assertion Schema-1073
                //is violated, we don't want the duplicate schema components in the component model.
                //TODO check that this behaviour is correct (eliminating duplicates)
            }
            QName edQN = xseQN;
            if(xseQN.getNamespaceURI() == null && schemaTns != null) {
                //this is how XmlSchema represents tns for chameleon xs:includes,
                //so replace it with the including schema's tns.
                edQN = new QName(schemaTns, xseQN.getLocalPart(), xseQN.getPrefix());
            }
            if(edQN.getPrefix() == "" || edQN.getPrefix() == null) {
                //if a prefix has been declared for this NS uri, include it in the qname
                String pfx = prefixes.getPrefix(edQN.getNamespaceURI());
                if(pfx != null) {
                    edQN = new QName(edQN.getNamespaceURI(), edQN.getLocalPart(), pfx);
                }
            }
          if(schemaTns == null || schemaTns.equals(edQN.getNamespaceURI())) //TODO test with schema imports, may be incorrect.
View Full Code Here

   * Extract the type definitions from the given schema.
   */
  private void buildTypeDefinitions(XmlSchema schemaDef, String schemaTns, URI typeSystemURI) {
       
      XmlSchemaObjectTable typeTable = schemaDef.getSchemaTypes();
        NamespacePrefixList prefixes = schemaDef.getNamespaceContext();
      Iterator qnames = typeTable.getNames();
      while (qnames.hasNext()) {
          QName xstQN = (QName) qnames.next();
           
            if(SchemaConstants.NS_STRING_SCHEMA.equals(schemaTns) &&
               !SchemaConstants.LIST_Q_BUILT_IN_TYPES.contains(xstQN)) {
                //XML Schema namespace is implicitly imported to get built-in types...we don't want non-built-in types.
                //TODO detect if the XML Schema NS has been explicitly imported (if so, we want ALL type defs)
                continue;
            }
           
            if(fDesc.getTypeDefinition(xstQN) != null) {
                //The Description already contains this Type Definition.
                continue;
                //The same comments apply here as stated in the buildElementDeclarations method.
                //TODO check that this behaviour is correct (per assertion Schema-1073).
            }
            QName tdQN = xstQN;
            if(xstQN.getNamespaceURI() == null && schemaTns != null) {
                //this is how XmlSchema represents tns for chameleon xs:includes,
                //so replace it with the including schema's tns.
                tdQN = new QName(schemaTns, xstQN.getLocalPart(), xstQN.getPrefix());
            }
            if(tdQN.getPrefix() == emptyString || tdQN.getPrefix() == null) {
                //if a prefix has been declared for this NS uri, include it in the qname
                String pfx = prefixes.getPrefix(tdQN.getNamespaceURI());
                if(pfx != null) {
                    tdQN = new QName(tdQN.getNamespaceURI(), tdQN.getLocalPart(), pfx);
                }
            }
          if (schemaTns == null || schemaTns.equals(tdQN.getNamespaceURI()))
View Full Code Here

    public String getSchemaTargetNameSpace() {
        return schemaTargetNameSpace;
    }

    protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) {
        NamespacePrefixList map = xmlSchema.getNamespaceContext();
        if (map == null ||
                ((map instanceof NamespaceMap) && ((NamespaceMap) map).values() == null) ||
                schemaTypeName == null) {
            return;
        }
View Full Code Here

public class XMLSerializerTest {
    @Test
    public void test() throws Exception {
        XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
        XmlSchema xmlSchema = new XmlSchema("", xmlSchemaCollection);
        NamespacePrefixList ctx = NodeNamespaceContext.getNamespaceContext(xmlSchema.getSchemaDocument());
        xmlSchema.setNamespaceContext(ctx);
        xmlSchema.getSchemaDocument();
    }
View Full Code Here

    }

    private XmlSchema addNameSpaces(int i) {
        XmlSchema schema = (XmlSchema) schemaList.get(i);
        NamespaceMap map = (NamespaceMap) namespaceMap.clone();
        NamespacePrefixList namespaceContext = schema.getNamespaceContext();
        String prefixes[] = namespaceContext.getDeclaredPrefixes();
        for (int j = 0; j < prefixes.length; j++) {
            String prefix = prefixes[j];
            map.add(prefix, namespaceContext.getNamespaceURI(prefix));
        }
        schema.setNamespaceContext(map);
        return schema;
    }
View Full Code Here

    public String getSchemaTargetNameSpace() {
        return schemaTargetNameSpace;
    }

    protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) {
        NamespacePrefixList map = xmlSchema.getNamespaceContext();
        if (map instanceof NamespaceMap && !((NamespaceMap) map).values().
                contains(schemaTypeName.getNamespaceURI())) {
            XmlSchemaImport importElement = new XmlSchemaImport();
            importElement.setNamespace(schemaTypeName.getNamespaceURI());
            xmlSchema.getItems().add(importElement);
View Full Code Here

        // we need an import for every namespace except the main one.
        String schemaNamespace = schemaInfo.getNamespaceURI();
        Map<String, String> queryPrefixMap = new HashMap<String, String>();
        queryPrefixMap.put("xs", WSDLConstants.NS_SCHEMA_XSD);
        XPathUtils xpu = new XPathUtils(queryPrefixMap);
        NamespacePrefixList schemaPrefixes = schemaInfo.getSchema().getNamespaceContext();
        for (String prefix : schemaPrefixes.getDeclaredPrefixes()) {
            String namespace = schemaPrefixes.getNamespaceURI(prefix);
            if (!namespace.equals(schemaNamespace)
                && !namespace.equals(WSDLConstants.NS_SCHEMA_XSD)
                && !xpu.isExist("xs:import[@namespace='" + namespace + "']",
                                 schemaElement,
                                 XPathConstants.NODE)) {
View Full Code Here

TOP

Related Classes of org.apache.ws.commons.schema.utils.NamespacePrefixList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.