⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schemautils.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.wsdl.symbolTable;import org.apache.axis.Constants;import org.apache.axis.AxisProperties;import org.apache.axis.i18n.Messages;import org.apache.axis.utils.JavaUtils;import org.w3c.dom.DOMException;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import javax.xml.namespace.QName;import javax.xml.rpc.holders.BooleanHolder;import javax.xml.rpc.holders.IntHolder;import javax.xml.rpc.holders.BooleanHolder;import javax.xml.rpc.holders.QNameHolder;import java.util.Arrays;import java.util.HashSet;import java.util.Set;import java.util.StringTokenizer;import java.util.Vector;import java.io.IOException;/** * This class contains static utility methods specifically for schema type queries. * * @author Rich Scheuerle  (scheu@us.ibm.com) */public class SchemaUtils {    /** Field VALUE_QNAME */    static final QName VALUE_QNAME = Utils.findQName("", "_value");    /**     * This method checks mixed=true attribute is set either on     * complexType or complexContent element.     */    public static boolean isMixed(Node node) {        // Expecting a schema complexType        if (isXSDNode(node, "complexType")) {            String mixed = ((Element)node).getAttribute("mixed");            if (mixed != null && mixed.length() > 0) {                return ("true".equalsIgnoreCase(mixed) ||                        "1".equals(mixed));            }            // Under the complexType there could be complexContent with            // mixed="true"            NodeList children = node.getChildNodes();            for (int j = 0; j < children.getLength(); j++) {                Node kid = children.item(j);                if (isXSDNode(kid, "complexContent")) {                    mixed = ((Element)kid).getAttribute("mixed");                    return ("true".equalsIgnoreCase(mixed) ||                            "1".equals(mixed));                }            }        }        return false;    }    public static Node getUnionNode(Node node) {        // Expecting a schema complexType        if (isXSDNode(node, "simpleType")) {            // Under the simpleType there could be union            NodeList children = node.getChildNodes();            for (int j = 0; j < children.getLength(); j++) {                Node kid = children.item(j);                if (isXSDNode(kid, "union")) {                    return kid;                }            }        }        return null;    }    public static Node getListNode(Node node) {        // Expecting a schema simpleType        if (isXSDNode(node, "simpleType")) {            // Under the simpleType there could be list            NodeList children = node.getChildNodes();            for (int j = 0; j < children.getLength(); j++) {                Node kid = children.item(j);                if (isXSDNode(kid, "list")) {                    return kid;                }            }        }        return null;    }    public static boolean isSimpleTypeWithUnion(Node node) {        return (getUnionNode(node) != null);    }  /**   * This method checks out if the given node satisfies the 3rd condition   * of the "wrapper" style:   * such an element (a wrapper) must be of a complex type defined using the   * xsd:sequence compositor and containing only elements declarations.   * (excerpt from JAX-RPC spec 1.1 Maintenanace Review 2 Chapter 6 Section 4.1.)   *   * @param node   * @return   */  public static boolean isWrappedType(Node node) {    if (node == null) {      return false;    }    // If the node kind is an element, dive into it.    if (isXSDNode(node, "element")) {      NodeList children = node.getChildNodes();      boolean hasComplexType = false;      for (int j = 0; j < children.getLength(); j++) {        Node kid = children.item(j);        if (isXSDNode(kid, "complexType")) {          node = kid;          hasComplexType = true;          break;        }      }      if (!hasComplexType) {        return false;      }    }    // Expecting a schema complexType    if (isXSDNode(node, "complexType")) {      // Under the complexType there could be complexContent/simpleContent      // and extension elements if this is a derived type.      // A wrapper element must be complex-typed.      NodeList children = node.getChildNodes();      for (int j = 0; j < children.getLength(); j++) {        Node kid = children.item(j);        if (isXSDNode(kid, "complexContent")) {          return false;        } else if (isXSDNode(kid, "simpleContent")) {          return false;        }      }      // Under the complexType there may be choice, sequence, group and/or all nodes.      // (There may be other #text nodes, which we will ignore).      // The complex type of a wrapper element must have only sequence      // and again element declarations in the sequence.      children = node.getChildNodes();      int len =  children.getLength();      for (int j = 0; j < len; j++) {          Node kid = children.item(j);          String localName = kid.getLocalName();          if (localName != null &&              Constants.isSchemaXSD(kid.getNamespaceURI())) {              if (localName.equals("sequence")) {                  Node sequenceNode = kid;                  NodeList sequenceChildren = sequenceNode.getChildNodes();                  int sequenceLen = sequenceChildren.getLength();                  for (int k = 0; k < sequenceLen; k++) {                      Node sequenceKid = sequenceChildren.item(k);                      String sequenceLocalName = sequenceKid.getLocalName();                      if (sequenceLocalName != null &&                          Constants.isSchemaXSD(sequenceKid.getNamespaceURI())) {                          // allow choice with element children                          if (sequenceLocalName.equals("choice")) {                              Node choiceNode = sequenceKid;                              NodeList choiceChildren = choiceNode.getChildNodes();                              int choiceLen = choiceChildren.getLength();                              for (int l = 0; l < choiceLen; l++) {                                  Node choiceKid = choiceChildren.item(l);                                  String choiceLocalName = choiceKid.getLocalName();                                  if (choiceLocalName != null &&                                      Constants.isSchemaXSD(choiceKid.getNamespaceURI())) {                                      if (!choiceLocalName.equals("element")) {                                          return false;                                      }                                  }                              }                          }                          else                          if (!sequenceLocalName.equals("element")) {                              return false;                          }                      }                  }                  return true;              } else {                  return false;              }          }      }    }    // allows void type    return true;  }    /**     * If the specified node represents a supported JAX-RPC complexType or     * simpleType, a Vector is returned which contains ElementDecls for the     * child element names.     * If the element is a simpleType, an ElementDecls is built representing     * the restricted type with the special name "value".     * If the element is a complexType which has simpleContent, an ElementDecl     * is built representing the extended type with the special name "value".     * This method does not return attribute names and types     * (use the getContainedAttributeTypes)     * If the specified node is not a supported     * JAX-RPC complexType/simpleType/element null is returned.     *     * @param node     * @param symbolTable     * @return     */    public static Vector getContainedElementDeclarations(Node node,                                                         SymbolTable symbolTable) {        if (node == null) {            return null;        }        // If the node kind is an element, dive into it.        if (isXSDNode(node, "element")) {            NodeList children = node.getChildNodes();            for (int j = 0; j < children.getLength(); j++) {                Node kid = children.item(j);                if (isXSDNode(kid, "complexType")) {                    node = kid;                    break;                }            }        }        // Expecting a schema complexType or simpleType        if (isXSDNode(node, "complexType")) {            // Under the complexType there could be complexContent/simpleContent            // and extension elements if this is a derived type.  Skip over these.            NodeList children = node.getChildNodes();            Node complexContent = null;            Node simpleContent = null;            Node extension = null;            for (int j = 0; j < children.getLength(); j++) {                Node kid = children.item(j);                if (isXSDNode(kid, "complexContent")) {                    complexContent = kid;                    break;    // REMIND: should this be here or on either branch?                } else if (isXSDNode(kid, "simpleContent")) {                    simpleContent = kid;                }            }            if (complexContent != null) {                children = complexContent.getChildNodes();                for (int j = 0;                     (j < children.getLength()) && (extension == null);                     j++) {                    Node kid = children.item(j);                    if (isXSDNode(kid, "extension")                            || isXSDNode(kid, "restriction")) {                        extension = kid;                    }                }            }            if (simpleContent != null) {                children = simpleContent.getChildNodes();                int len =  children.getLength();                for (int j = 0;                     (j < len) && (extension == null);                     j++) {                    Node kid = children.item(j);                    String localName = kid.getLocalName();                    if ((localName != null)                        && (localName.equals("extension") || localName.equals("restriction"))                        && Constants.isSchemaXSD(kid.getNamespaceURI())) {                        // get the type of the extension/restriction from the "base" attribute                        QName extendsOrRestrictsTypeName =                                Utils.getTypeQName(children.item(j),                                        new BooleanHolder(), false);                        TypeEntry extendsOrRestrictsType =                            symbolTable.getTypeEntry(extendsOrRestrictsTypeName,                                                    false);                        // If this type extends a simple type, then add the                        // special "value" ElementDecl, else this type is                        // extending another simpleContent type and will                        // already have a "value".                        if (extendsOrRestrictsType == null ||                            extendsOrRestrictsType.isBaseType())                        {                        // Return an element declaration with a fixed name                        // ("value") and the correct type.                        Vector v = new Vector();                            ElementDecl elem =                                new ElementDecl(extendsOrRestrictsType,                                    VALUE_QNAME);                        v.add(elem);                        return v;                    }                        else                        {                            // There can't be any other elements in a                            // simpleContent node.                            return null;                        }                    }                }            }            if (extension != null) {                node = extension;    // Skip over complexContent and extension            }            // Under the complexType there may be choice, sequence, group and/or all nodes.            // (There may be other #text nodes, which we will ignore).            children = node.getChildNodes();            Vector v = new Vector();            int len = children.getLength();            for (int j = 0; j < len; j++) {                Node kid = children.item(j);                String localName = kid.getLocalName();                if (localName != null &&                    Constants.isSchemaXSD(kid.getNamespaceURI())) {                    if (localName.equals("sequence")) {                        v.addAll(processSequenceNode(kid, symbolTable));                    } else if (localName.equals("all")) {                        v.addAll(processAllNode(kid, symbolTable));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -