📄 symboltable.java
字号:
for (int i = 0; i < importKeys.length; ++i) { Vector v = (Vector) imports.get(importKeys[i]); for (int j = 0; j < v.size(); ++j) { Import imp = (Import) v.get(j); if (!importedFiles.contains(imp.getLocationURI())) { importedFiles.add(imp.getLocationURI()); URL url = getURL(context, imp.getLocationURI()); populate(url, imp.getDefinition(), XMLUtils.newDocument(url.toString()), url.toString()); } } } } populateMessages(def); populatePortTypes(def); populateBindings(def); populateServices(def); } } // populate /** * This is essentially a call to "new URL(contextURL, spec)" with extra handling in case spec is * a file. * * @param contextURL * @param spec * @return * @throws IOException */ private static URL getURL(URL contextURL, String spec) throws IOException { // First, fix the slashes as windows filenames may have backslashes // in them, but the URL class wont do the right thing when we later // process this URL as the contextURL. String path = spec.replace('\\', '/'); // See if we have a good URL. URL url = null; try { // first, try to treat spec as a full URL url = new URL(contextURL, path); // if we are deail with files in both cases, create a url // by using the directory of the context URL. if ((contextURL != null) && url.getProtocol().equals("file") && contextURL.getProtocol().equals("file")) { url = getFileURL(contextURL, path); } } catch (MalformedURLException me) { // try treating is as a file pathname url = getFileURL(contextURL, path); } // Everything is OK with this URL, although a file url constructed // above may not exist. This will be caught later when the URL is // accessed. return url; } // getURL /** * Method getFileURL * * @param contextURL * @param path * @return * @throws IOException */ private static URL getFileURL(URL contextURL, String path) throws IOException { if (contextURL != null) { // get the parent directory of the contextURL, and append // the spec string to the end. String contextFileName = contextURL.getFile(); URL parent = null; File parentFile = new File(contextFileName).getParentFile(); if ( parentFile != null ) { parent = parentFile.toURL(); } if (parent != null) { return new URL(parent, path); } } return new URL("file", "", path); } // getFileURL /** * Recursively find all xsd:import'ed objects and call populate for each one. * * @param context * @param node * @throws IOException * @throws ParserConfigurationException * @throws SAXException * @throws WSDLException */ private void lookForImports(URL context, Node node) throws IOException, ParserConfigurationException, SAXException, WSDLException { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ("import".equals(child.getLocalName())) { NamedNodeMap attributes = child.getAttributes(); Node namespace = attributes.getNamedItem("namespace"); // skip XSD import of soap encoding if ((namespace != null) && isKnownNamespace(namespace.getNodeValue())) { continue; } Node importFile = attributes.getNamedItem("schemaLocation"); if (importFile != null) { URL url = getURL(context, importFile.getNodeValue()); if (!importedFiles.contains(url)) { importedFiles.add(url); String filename = url.toString(); populate(url, null, XMLUtils.newDocument(filename), filename); } } } lookForImports(context, child); } } // lookForImports /** * Check if this is a known namespace (soap-enc or schema xsd or schema xsi or xml) * * @param namespace * @return true if this is a know namespace. */ public boolean isKnownNamespace(String namespace) { if (Constants.isSOAP_ENC(namespace)) { return true; } if (Constants.isSchemaXSD(namespace)) { return true; } if (Constants.isSchemaXSI(namespace)) { return true; } if (namespace.equals(Constants.NS_URI_XML)) { return true; } return false; } /** * Populate the symbol table with all of the Types from the Document. * * @param context * @param doc * @throws IOException * @throws SAXException * @throws WSDLException * @throws ParserConfigurationException */ public void populateTypes(URL context, Document doc) throws IOException, SAXException, WSDLException, ParserConfigurationException { addTypes(context, doc, ABOVE_SCHEMA_LEVEL); } // populateTypes /** * Utility method which walks the Document and creates Type objects for * each complexType, simpleType, attributeGroup or element referenced or defined. * <p/> * What goes into the symbol table? In general, only the top-level types * (ie., those just below * the schema tag). But base types and references can * appear below the top level. So anything * at the top level is added to the symbol table, * plus non-Element types (ie, base and refd) * that appear deep within other types. */ private static final int ABOVE_SCHEMA_LEVEL = -1; /** Field SCHEMA_LEVEL */ private static final int SCHEMA_LEVEL = 0; /** * Method addTypes * * @param context * @param node * @param level * @throws IOException * @throws ParserConfigurationException * @throws WSDLException * @throws SAXException */ private void addTypes(URL context, Node node, int level) throws IOException, ParserConfigurationException, WSDLException, SAXException { if (node == null) { return; } // Get the kind of node (complexType, wsdl:part, etc.) String localPart = node.getLocalName(); if (localPart != null) { boolean isXSD = Constants.isSchemaXSD(node.getNamespaceURI()); if (((isXSD && localPart.equals("complexType")) || localPart.equals("simpleType"))) { // If an extension or restriction is present, // create a type for the reference Node re = SchemaUtils.getRestrictionOrExtensionNode(node); if ((re != null) && (Utils.getAttribute(re, "base") != null)) { createTypeFromRef(re); } Node list = SchemaUtils.getListNode(node); if (list != null && Utils.getAttribute(list,"itemType") != null) { createTypeFromRef(list); } Node union = SchemaUtils.getUnionNode(node); if (union != null) { QName [] memberTypes = Utils.getMemberTypeQNames(union); if (memberTypes != null) { for (int i=0;i<memberTypes.length;i++) { if (SchemaUtils.isSimpleSchemaType(memberTypes[i]) && getType(memberTypes[i]) == null) { symbolTablePut(new BaseType(memberTypes[i])); } } } } // This is a definition of a complex type. // Create a Type. createTypeFromDef(node, false, false); } else if (isXSD && localPart.equals("element")) { // Create a type entry for the referenced type createTypeFromRef(node); // If an extension or restriction is present, // create a type for the reference Node re = SchemaUtils.getRestrictionOrExtensionNode(node); if ((re != null) && (Utils.getAttribute(re, "base") != null)) { createTypeFromRef(re); } // Create a type representing an element. (This may // seem like overkill, but is necessary to support ref= // and element=. createTypeFromDef(node, true, level > SCHEMA_LEVEL); } else if (isXSD && localPart.equals("attributeGroup")) { // bug 23145: support attributeGroup (Brook Richan) // Create a type entry for the referenced type createTypeFromRef(node); // Create a type representing an attributeGroup. createTypeFromDef(node, false, level > SCHEMA_LEVEL); } else if (isXSD && localPart.equals("group")) { // Create a type entry for the referenced type createTypeFromRef(node); // Create a type representing an group createTypeFromDef(node, false, level > SCHEMA_LEVEL); } else if (isXSD && localPart.equals("attribute")) { // Create a type entry for the referenced type BooleanHolder forElement = new BooleanHolder(); QName refQName = Utils.getTypeQName(node, forElement, false); if ((refQName != null) && !forElement.value) { createTypeFromRef(node); // Get the symbol table entry and make sure it is a simple // type if (refQName != null) { TypeEntry refType = getTypeEntry(refQName, false); if ((refType != null) && (refType instanceof Undefined)) { // Don't know what the type is. // It better be simple so set it as simple refType.setSimpleType(true); } else if ((refType == null) || (!(refType instanceof BaseType) && !refType.isSimpleType())) { // Problem if not simple throw new IOException( Messages.getMessage( "AttrNotSimpleType01", refQName.toString())); } } } createTypeFromDef(node, true, level > SCHEMA_LEVEL); } else if (isXSD && localPart.equals("any")) { // Map xsd:any element to special xsd:any "type" if (getType(Constants.XSD_ANY) == null) { Type type = new BaseType(Constants.XSD_ANY); symbolTablePut(type); } } else if (localPart.equals("part") && Constants.isWSDL(node.getNamespaceURI())) { // This is a wsdl part. Create an TypeEntry representing the reference createTypeFromRef(node); } else if (isXSD && localPart.equals("include")) { String includeName = Utils.getAttribute(node, "schemaLocation"); if (includeName != null) { URL url = getURL(context, includeName); Document includeDoc = XMLUtils.newDocument(url.toString()); // Vidyanand : Fix for Bug #15124 org.w3c.dom.Element schemaEl = includeDoc.getDocumentElement(); if (!schemaEl.hasAttribute("targetNamespace")) { org.w3c.dom.Element parentSchemaEl = (org.w3c.dom.Element) node.getParentNode(); if (parentSchemaEl.hasAttribute("targetNamespace")) { // we need to set two things in here // 1. targetNamespace // 2. setup the xmlns=<targetNamespace> attribute
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -