📄 emitter.java
字号:
if (fullJavaName != null) { return fullJavaName; } fullJavaName = getJavaNameHook(qName); if (fullJavaName != null) { return fullJavaName; } // Use the namespace uri to get the appropriate package String pkg = getPackage(qName.getNamespaceURI()); if (pkg != null && pkg.length() > 0) { fullJavaName = pkg + "." + Utils.xmlNameToJavaClass(qName.getLocalPart()); } else { fullJavaName = Utils.xmlNameToJavaClass(qName.getLocalPart()); } return fullJavaName; } // getJavaName protected String getJavaNameHook(QName qname) { return null; } /** * @param typeQName QName for containing xml type * @param xmlName QName for element * @return */ public String getJavaVariableName(QName typeQName, QName xmlName, boolean isElement) { String javaName = getJavaVariableNameHook(typeQName, xmlName, isElement); if (javaName == null) { String elemName = Utils.getLastLocalPart(xmlName.getLocalPart()); javaName = Utils.xmlNameToJava(elemName); } return javaName; } protected String getJavaVariableNameHook(QName typeQName, QName xmlName, boolean isElement) { return null; } /** * Emit appropriate Java files for a WSDL at a given URL. * <p/> * This method will time out after the number of milliseconds specified * by our timeoutms member. * * @param wsdlURL * @throws Exception */ public void run(String wsdlURL) throws Exception { setup(); super.run(wsdlURL); } // run /** * Call this method if your WSDL document has already been * parsed as an XML DOM document. * * @param context context This is directory context for the Document. * If the Document were from file "/x/y/z.wsdl" then the context * could be "/x/y" (even "/x/y/z.wsdl" would work). * If context is null, then the context becomes the current directory. * @param doc doc This is the XML Document containing the WSDL. * @throws IOException * @throws SAXException * @throws WSDLException * @throws ParserConfigurationException */ public void run(String context, Document doc) throws IOException, SAXException, WSDLException, ParserConfigurationException { setup(); super.run(context, doc); } // run /** * Method setup * * @throws IOException */ private void setup() throws IOException { if (baseTypeMapping == null) { setTypeMappingVersion(typeMappingVersion); } getFactory().setBaseTypeMapping(baseTypeMapping); namespaces = new Namespaces(outputDir); if (packageName != null) { namespaces.setDefaultPackage(packageName); } else { // First, read the namespace mapping file - configurable, by default // NStoPkg.properties - if it exists, and load the namespaceMap HashMap // with its data. getNStoPkgFromPropsFile(namespaces); if (delayedNamespacesMap != null) { namespaces.putAll(delayedNamespacesMap); } } } // setup /** * Method sanityCheck * * @param symbolTable */ protected void sanityCheck(SymbolTable symbolTable) { Iterator it = symbolTable.getHashMap().values().iterator(); while (it.hasNext()) { Vector v = (Vector) it.next(); for (int i = 0; i < v.size(); ++i) { SymTabEntry entry = (SymTabEntry) v.elementAt(i); String namespace = entry.getQName().getNamespaceURI(); String packageName = org.apache.axis.wsdl.toJava.Utils.makePackageName( namespace); String localName = entry.getQName().getLocalPart(); if (localName.equals(packageName) && packageName.equals( namespaces.getCreate(namespace))) { packageName += "_pkg"; namespaces.put(namespace, packageName); } } } } /** * Tries to load the namespace-to-package mapping file. * <ol> * <li>if a file name is explicitly set using <code>setNStoPkg()</code>, tries * to load the mapping from this file. If this fails, the built-in default * mapping is used. * <p/> * <li>if no file name is set, tries to load the file <code>DEFAULT_NSTOPKG_FILE</code> * as a java resource. If this fails, the built-in dfault mapping is used. * </ol> * * @param namespaces a hashmap which is filled with the namespace-to-package mapping * in this method * @throws IOException * @see #setNStoPkg(String) * @see #DEFAULT_NSTOPKG_FILE * @see org.apache.axis.utils.ClassUtils#getResourceAsStream(java.lang.Class,String) */ private void getNStoPkgFromPropsFile(HashMap namespaces) throws IOException { Properties mappings = new Properties(); if (NStoPkgFilename != null) { try { mappings.load(new FileInputStream(NStoPkgFilename)); if (verbose) { System.out.println( Messages.getMessage( "nsToPkgFileLoaded00", NStoPkgFilename)); } } catch (Throwable t) { // loading the custom mapping file failed. We do not try // to load the mapping from a default mapping file. throw new IOException( Messages.getMessage( "nsToPkgFileNotFound00", NStoPkgFilename)); } } else { try { mappings.load(new FileInputStream(DEFAULT_NSTOPKG_FILE)); if (verbose) { System.out.println( Messages.getMessage( "nsToPkgFileLoaded00", DEFAULT_NSTOPKG_FILE)); } } catch (Throwable t) { try { mappings.load(ClassUtils.getResourceAsStream(Emitter.class, DEFAULT_NSTOPKG_FILE)); if (verbose) { System.out.println( Messages.getMessage( "nsToPkgDefaultFileLoaded00", DEFAULT_NSTOPKG_FILE)); } } catch (Throwable t1) { // loading the default mapping file failed. // The built-in default mapping is used // No message is given, since this is generally what happens } } } Enumeration keys = mappings.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); namespaces.put(key, mappings.getProperty(key)); } } // getNStoPkgFromPropsFile /** * Get the typemapping version */ public String getTypeMappingVersion() { return typeMappingVersion; } /** * Method setTypeMappingVersion * * @param typeMappingVersion */ public void setTypeMappingVersion(String typeMappingVersion) { this.typeMappingVersion = typeMappingVersion; tmr.doRegisterFromVersion(typeMappingVersion); baseTypeMapping = new BaseTypeMapping() { final TypeMapping defaultTM = getDefaultTypeMapping(); public String getBaseName(QName qNameIn) { javax.xml.namespace.QName qName = new javax.xml.namespace.QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart()); Class cls = defaultTM.getClassForQName(qName); if (cls == null) { return null; } else { return JavaUtils.getTextClassName(cls.getName()); } } }; } // The remainder are deprecated methods. /** * Get the GeneratorFactory. * * @return * @deprecated Call getFactory instead. This doesn't return * a WriterFactory, it returns a GeneratorFactory. */ public GeneratorFactory getWriterFactory() { return getFactory(); } // getWriterFactory /** * Call this method if you have a uri for the WSDL document * * @param uri wsdlURI the location of the WSDL file. * @throws Exception * @deprecated Call run(uri) instead. */ public void emit(String uri) throws Exception { run(uri); } // emit /** * Call this method if your WSDL document has already been * parsed as an XML DOM document. * * @param context context This is directory context for the Document. * If the Document were from file "/x/y/z.wsdl" then the context could be "/x/y" * (even "/x/y/z.wsdl" would work). If context is null, then the context * becomes the current directory. * @param doc doc This is the XML Document containing the WSDL. * @throws IOException * @throws SAXException * @throws WSDLException * @throws ParserConfigurationException * @deprecated Call run(context, doc) instead. */ public void emit(String context, Document doc) throws IOException, SAXException, WSDLException, ParserConfigurationException { run(context, doc); } // emit /** * Turn on/off server-side binding generation * * @param value * @deprecated Use setServerSide(value) */ public void generateServerSide(boolean value) { setServerSide(value); } /** * Indicate if we should be emitting server side code and deploy/undeploy * * @return * @deprecated Use isServerSide() */ public boolean getGenerateServerSide() { return isServerSide(); } /** * Turn on/off server skeleton deploy * * @param value * @deprecated Use setSkeletonWanted(value) */ public void deploySkeleton(boolean value) { setSkeletonWanted(value); } /** * Indicate if we should be deploying skeleton or implementation * * @return * @deprecated Use isSkeletonWanted() */ public boolean getDeploySkeleton() { return isSkeletonWanted(); } /** * Turn on/off Helper class generation * * @param value * @deprecated Use setHelperWanted(value) */ public void setHelperGeneration(boolean value) { setHelperWanted(value); } /** * Indicate if we should be generating Helper classes * * @return * @deprecated Use isHelperWanted() */ public boolean getHelperGeneration() { return isHelperWanted(); } /** * Turn on/off generation of elements from imported files. * * @param generateImports * @deprecated Use setImports(generateImports) */ public void generateImports(boolean generateImports) { setImports(generateImports); } // generateImports /** * Turn on/off debug messages. * * @param value * @deprecated Use setDebug(value) */ public void debug(boolean value) { setDebug(value); } // debug /** * Return the status of the debug switch. * * @return * @deprecated Use isDebug() */ public boolean getDebug() { return isDebug(); } // getDebug /** * Turn on/off verbose messages * * @param value * @deprecated Use setVerbose(value) */ public void verbose(boolean value) { setVerbose(value); } /** * Return the status of the verbose switch * * @return * @deprecated Use isVerbose() */ public boolean getVerbose() { return isVerbose(); } /** * Turn on/off test case creation * * @param value * @deprecated Use setTestCaseWanted() */ public void generateTestCase(boolean value) { setTestCaseWanted(value); } /** * @param all * @deprecated Use setAllWanted(all) */ public void generateAll(boolean all) { setAllWanted(all); } // generateAll /** * Get the type collision protection setting * @return */ public boolean isTypeCollisionProtection(){ return this.typeCollisionProtection; } /** * Enable/disable type collision protection * @param value */ public void setTypeCollisionProtection(boolean value){ this.typeCollisionProtection = value; } /** * Get an implementation classname to use instead of the default. * @return */ public String getImplementationClassName() { return implementationClassName; } /** * Set an implementation classname to use instead of the default. * * @param implementationClassName */ public void setImplementationClassName(String implementationClassName) { this.implementationClassName = implementationClassName; } /** * @return Returns the allowInvalidURL. */ public boolean isAllowInvalidURL() { return allowInvalidURL; } /** * @param allowInvalidURL The allowInvalidURL to set. */ public void setAllowInvalidURL(boolean allowInvalidURL) { this.allowInvalidURL = allowInvalidURL; } /** * Set the type qname to java class map * @param map a type qname to javaclass map (from Java2Wsdl emitter) */ public void setQName2ClassMap(HashMap map) { qName2ClassMap = map; } /** * Get the type qname to java class map * @return the type qname to java class map */ public HashMap getQName2ClassMap() { return qName2ClassMap; } /** * Retruns the SericeDesc object * @return */ public ServiceDesc getServiceDesc() { return serviceDesc; } /** * Sets the ServicdDesc object * @param serviceDesc ServiceDesc to set */ public void setServiceDesc(ServiceDesc serviceDesc) { this.serviceDesc = serviceDesc; } /** * Returns the deploy mode flag * @return */ public boolean isDeploy() { return isDeploy; } /** * Sets the deploy mode flag * @param isDeploy deploy mode flag */ public void setDeploy(boolean isDeploy) { this.isDeploy = isDeploy; } /** * Check if the className exists. * * @param className className to check * @return true if exists, false if not */ protected boolean doesExist(String className) { try { ClassUtils.forName(className); } catch (ClassNotFoundException e) { return false; } return true; } public void setWrapArrays(boolean wrapArrays) { this.wrapArrays = wrapArrays; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -