📄 schemautils.java
字号:
for (int j = 0; j < children.getLength(); j++) { Node kid = children.item(j); if (isXSDNode(kid, "element")) { ElementDecl elem = processChildElementNode(kid, symbolTable); if (elem != null) { v.add(elem); } } } return v; } /** * Invoked by getContainedElementDeclarations to get the child element type * and child element name for a child element node. * <p/> * If the specified node represents a supported JAX-RPC child element, * we return an ElementDecl containing the child element name and type. * * @param elementNode * @param symbolTable * @return */ private static ElementDecl processChildElementNode(Node elementNode, SymbolTable symbolTable) { // Get the name qnames. QName nodeName = Utils.getNodeNameQName(elementNode); BooleanHolder forElement = new BooleanHolder(); String comments = null; comments = getAnnotationDocumentation(elementNode); // The type qname is used to locate the TypeEntry, which is then // used to retrieve the proper java name of the type. QName nodeType = Utils.getTypeQName(elementNode, forElement, false); TypeEntry type = symbolTable.getTypeEntry(nodeType, forElement.value); // An element inside a complex type is either qualified or unqualified. // If the ref= attribute is used, the name of the ref'd element is used // (which must be a root element). If the ref= attribute is not // used, the name of the element is unqualified. if (!forElement.value) { // check the Form (or elementFormDefault) attribute of this node to // determine if it should be namespace quailfied or not. String form = Utils.getAttribute(elementNode, "form"); if ((form != null) && form.equals("unqualified")) { // Unqualified nodeName nodeName = Utils.findQName("", nodeName.getLocalPart()); } else if (form == null) { // check elementFormDefault on schema element String def = Utils.getScopedAttribute(elementNode, "elementFormDefault"); if ((def == null) || def.equals("unqualified")) { // Unqualified nodeName nodeName = Utils.findQName("", nodeName.getLocalPart()); } } } if (type != null) { ElementDecl elem = new ElementDecl(type, nodeName); elem.setDocumentation(comments); String minOccurs = Utils.getAttribute(elementNode, "minOccurs"); if ((minOccurs != null) && minOccurs.equals("0")) { elem.setMinOccursIs0(true); } String maxOccurs = Utils.getAttribute(elementNode, "maxOccurs"); if (maxOccurs != null) { if (maxOccurs.equals("unbounded")) { elem.setMaxOccursIsUnbounded(true); } else if(maxOccurs.equals("1")) { elem.setMaxOccursIsExactlyOne(true); } } else { elem.setMaxOccursIsExactlyOne(true); } elem.setNillable( JavaUtils.isTrueExplicitly( Utils.getAttribute(elementNode, "nillable"))); String useValue = Utils.getAttribute(elementNode, "use"); if (useValue != null) { elem.setOptional(useValue.equalsIgnoreCase("optional")); } return elem; } return null; } /** * Returns the WSDL2Java QName for the anonymous type of the element * or null. * * @param node * @return */ public static QName getElementAnonQName(Node node) { 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") || isXSDNode(kid, "simpleType")) { return Utils.getNodeNameQName(kid); } } } return null; } /** * Returns the WSDL2Java QName for the anonymous type of the attribute * or null. * * @param node * @return */ public static QName getAttributeAnonQName(Node node) { if (isXSDNode(node, "attribute")) { NodeList children = node.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { Node kid = children.item(j); if (isXSDNode(kid, "complexType") || isXSDNode(kid, "simpleType")) { return Utils.getNodeNameQName(kid); } } } return null; } /** * If the specified node is a simple type or contains simpleContent, return true * * @param node * @return */ public static boolean isSimpleTypeOrSimpleContent(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(); for (int j = 0; j < children.getLength(); j++) { Node kid = children.item(j); if (isXSDNode(kid, "complexType")) { node = kid; break; } else if (isXSDNode(kid, "simpleType")) { return true; } } } // Expecting a schema complexType or simpleType if (isXSDNode(node, "simpleType")) { return true; } 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; for (int j = 0; j < children.getLength(); j++) { Node kid = children.item(j); if (isXSDNode(kid, "complexContent")) { complexContent = kid; break; } else if (isXSDNode(kid, "simpleContent")) { simpleContent = kid; } } if (complexContent != null) { return false; } if (simpleContent != null) { return true; } } return false; } /** * Test whether <tt>node</tt> is not null, belongs to the XML * Schema namespace, and has a localName that matches * <tt>schemaLocalName</tt> * <p/> * This can be used to determine that a given Node defines a * schema "complexType" "element" and so forth. * * @param node a <code>Node</code> value * @param schemaLocalName a <code>String</code> value * @return true if the node is matches the name in the schema namespace. */ private static boolean isXSDNode(Node node, String schemaLocalName) { if (node == null) { return false; } String localName = node.getLocalName(); if (localName == null) { return false; } return (localName.equals(schemaLocalName) && Constants.isSchemaXSD(node.getNamespaceURI())); } /** * Look for the base type of node iff node is a complex type that has been * derived by restriction; otherwise return null. * * @param node * @param symbolTable * @return */ public static TypeEntry getComplexElementRestrictionBase(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(); Node complexNode = null; for (int j = 0; (j < children.getLength()) && (complexNode == null); j++) { if (isXSDNode(children.item(j), "complexType")) { complexNode = children.item(j); node = complexNode; } } } // Expecting a schema complexType if (isXSDNode(node, "complexType")) { // Under the complexType there could be should be a complexContent & // restriction elements if this is a derived type. NodeList children = node.getChildNodes(); Node content = null; Node restriction = null; for (int j = 0; (j < children.getLength()) && (content == null); j++) { Node kid = children.item(j); if (isXSDNode(kid, "complexContent") || isXSDNode(kid, "simpleContent")) { content = kid; } } if (content != null) { children = content.getChildNodes(); for (int j = 0; (j < children.getLength()) && (restriction == null); j++) { Node kid = children.item(j); if (isXSDNode(kid, "restriction")) { restriction = kid; } } } if (restriction == null) { return null; } else { // Get the QName of the extension base QName restrictionType = Utils.getTypeQName(restriction, new BooleanHolder(), false); if (restrictionType == null) { return null; } else { // Return associated Type return symbolTable.getType(restrictionType); } } } else { return null; } } /** * If the specified node represents a supported JAX-RPC complexType/element * which extends another complexType. The Type of the base is returned. * * @param node * @param symbolTable * @return */ public static TypeEntry getComplexElementExtensionBase(Node node, SymbolTable symbolTable) { if (node == null) { return null; } TypeEntry cached = (TypeEntry) symbolTable.node2ExtensionBase.get(node); if (cached != null) { return cached; // cache hit } // If the node kind is an element, dive into it. if (isXSDNode(node, "element")) { NodeList children = node.getChildNodes(); Node complexNode = null; for (int j = 0; (j < children.getLength()) && (complexNode == null); j++) { if (isXSDNode(children.item(j), "complexType")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -