📄 schemautils.java
字号:
complexNode = children.item(j); node = complexNode; } } } // Expecting a schema complexType if (isXSDNode(node, "complexType")) { // Under the complexType there could be should be a complexContent & // extension elements if this is a derived type. NodeList children = node.getChildNodes(); Node content = null; Node extension = 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()) && (extension == null); j++) { Node kid = children.item(j); if (isXSDNode(kid, "extension")) { extension = kid; } } } if (extension == null) { cached = null; } else { // Get the QName of the extension base QName extendsType = Utils.getTypeQName(extension, new BooleanHolder(), false); if (extendsType == null) { cached = null; } else { // Return associated Type cached = symbolTable.getType(extendsType); } } } symbolTable.node2ExtensionBase.put(node, cached); return cached; } /** * If the specified node represents a 'normal' non-enumeration simpleType, * the QName of the simpleType base is returned. * * @param node * @return */ public static QName getSimpleTypeBase(Node node) { QName[] qname = getContainedSimpleTypes(node); if ((qname != null) && (qname.length > 0)) { return qname[0]; } return null; } /** * Method getContainedSimpleTypes * * @param node * @return */ public static QName[] getContainedSimpleTypes(Node node) { QName[] baseQNames = null; 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++) { if (isXSDNode(children.item(j), "simpleType")) { node = children.item(j); break; } } } // Get the node kind, expecting a schema simpleType if (isXSDNode(node, "simpleType")) { // Under the simpleType there should be a restriction. // (There may be other #text nodes, which we will ignore). NodeList children = node.getChildNodes(); Node restrictionNode = null; Node unionNode = null; for (int j = 0; (j < children.getLength()) && (restrictionNode == null); j++) { if (isXSDNode(children.item(j), "restriction")) { restrictionNode = children.item(j); } else if (isXSDNode(children.item(j), "union")) { unionNode = children.item(j); } } // The restriction node indicates the type being restricted // (the base attribute contains this type). if (restrictionNode != null) { baseQNames = new QName[1]; baseQNames[0] = Utils.getTypeQName(restrictionNode, new BooleanHolder(), false); } if (unionNode != null) { baseQNames = Utils.getMemberTypeQNames(unionNode); } // Look for enumeration elements underneath the restriction node if ((baseQNames != null) && (restrictionNode != null) && (unionNode != null)) { NodeList enums = restrictionNode.getChildNodes(); for (int i = 0; i < enums.getLength(); i++) { if (isXSDNode(enums.item(i), "enumeration")) { // Found an enumeration, this isn't a // 'normal' simple type. return null; } } } } return baseQNames; } /** * Returns the contained restriction or extension node underneath * the specified node. Returns null if not found * * @param node * @return */ public static Node getRestrictionOrExtensionNode(Node node) { Node re = null; if (node == null) { return re; } // 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 n = children.item(j); if (isXSDNode(n, "simpleType") || isXSDNode(n, "complexType") || isXSDNode(n, "simpleContent")) { node = n; break; } } } // Get the node kind, expecting a schema simpleType if (isXSDNode(node, "simpleType") || isXSDNode(node, "complexType")) { // Under the complexType there could be a complexContent. NodeList children = node.getChildNodes(); Node complexContent = null; if (node.getLocalName().equals("complexType")) { for (int j = 0; (j < children.getLength()) && (complexContent == null); j++) { Node kid = children.item(j); if (isXSDNode(kid, "complexContent") || isXSDNode(kid, "simpleContent")) { complexContent = kid; } } node = complexContent; } // Now get the extension or restriction node if (node != null) { children = node.getChildNodes(); for (int j = 0; (j < children.getLength()) && (re == null); j++) { Node kid = children.item(j); if (isXSDNode(kid, "extension") || isXSDNode(kid, "restriction")) { re = kid; } } } } return re; } /** * If the specified node represents an array encoding of one of the following * forms, then return the qname repesenting the element type of the array. * * @param node is the node * @param dims is the output value that contains the number of dimensions if return is not null * @param itemQName will end up containing the "inner" QName for a * wrapped literal array * @return QName or null */ public static QName getArrayComponentQName(Node node, IntHolder dims, BooleanHolder underlTypeNillable, QNameHolder itemQName, BooleanHolder forElement, SymbolTable symbolTable) { dims.value = 1; // assume 1 dimension underlTypeNillable.value = false; // assume underlying type is not nillable QName qName = getCollectionComponentQName(node, itemQName, forElement, symbolTable); if (qName == null) { qName = getArrayComponentQName_JAXRPC(node, dims, underlTypeNillable, symbolTable); } return qName; } /** * If the specified node represents an element that references a collection * then return the qname repesenting the component of the collection. * <p/> * <xsd:element name="alias" type="xsd:string" maxOccurs="unbounded"/> * returns qname for"xsd:string" * <p/> * <xsd:complexType> * <xsd:sequence> * <xsd:element name="alias" type="xsd:string" maxOccurs="unbounded"/> * </xsd:sequence> * </xsd:complexType> * returns qname for"xsd:string" * <p/> * <xsd:element ref="alias" maxOccurs="unbounded"/> * returns qname for "alias" * * @param node is the Node * @return QName of the compoent of the collection */ public static QName getCollectionComponentQName(Node node, QNameHolder itemQName, BooleanHolder forElement, SymbolTable symbolTable) { // If we're going to turn "wrapped" arrays into types such that // <complexType><sequence> // <element name="foo" type="xs:string" maxOccurs="unbounded"/> // </sequence></complexType> // becomes just "String []", we need to keep track of the inner // element name "foo" in metadata... This flag indicates whether to // do so. boolean storeComponentQName = false; if (node == null) { return null; } if (itemQName != null && isXSDNode(node, "complexType")) { // If this complexType is a sequence of exactly one element // we will continue processing below using that element, and // let the type checking logic determine if this is an array // or not. Node sequence = SchemaUtils.getChildByName(node, "sequence"); if (sequence == null) { return null; } NodeList children = sequence.getChildNodes(); Node element = null; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { if (element == null) { element = children.item(i); } else { return null; } } } if (element == null) { return null; } // OK, exactly one element child of <sequence>, // continue the processing using that element ... node = element; storeComponentQName = true; try { symbolTable.createTypeFromRef(node); } catch (IOException e) { throw new RuntimeException(Messages.getMessage("exception01",e.toString())); } } // If the node kind is an element, dive to get its type. if (isXSDNode(node, "element")) { // Compare the componentQName with the name of the // full name. If different, return componentQName QName componentTypeQName = Utils.getTypeQName(node, forElement, true); if (componentTypeQName != null) { QName fullQName = Utils.getTypeQName(node, forElement, false); if (!componentTypeQName.equals(fullQName)) { if (storeComponentQName) { String name = Utils.getAttribute(node, "name"); if (name != null) { // check elementFormDefault on schema element String def = Utils.getScopedAttribute(node, "elementFormDefault"); String namespace = ""; if ((def != null) && def.equals("qualified")) { namespace = Utils.getScopedAttribute(node, "targetNamespace"); } itemQName.value = new QName(namespace, name); } } return componentTypeQName; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -