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

📄 emitter.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    public String emitToString(int mode)            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        Document doc = emit(mode);        StringWriter sw = new StringWriter();        XMLUtils.PrettyDocumentToWriter(doc, sw);        return sw.toString();    }    /**     * Generates a WSDL document for a given <code>Class</code>.     * The WSDL generated is controlled by the mode parameter     * mode 0: All     * mode 1: Interface     * mode 2: Implementation     *      * @param filename WSDL     * @param mode     generation mode - all, interface, implementation     * @throws IOException                       * @throws WSDLException                     * @throws SAXException                      * @throws ParserConfigurationException      */    public void emit(String filename, int mode)            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        Document doc = emit(mode);        // Supply a reasonable file name if not supplied        if (filename == null) {            filename = getServicePortName();            switch (mode) {                case MODE_ALL:                    filename += ".wsdl";                    break;                case MODE_INTERFACE:                    filename += "_interface.wsdl";                    break;                case MODE_IMPLEMENTATION:                    filename += "_implementation.wsdl";                    break;            }        }        prettyDocumentToFile(doc, filename);    }    /**     * Get a Full WSDL <code>Definition</code> for the current     * configuration parameters     *      * @return WSDL <code>Definition</code>     * @throws IOException                       * @throws WSDLException                     * @throws SAXException                      * @throws ParserConfigurationException      */    public Definition getWSDL()            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        // Invoke the init() method to ensure configuration is setup        init(MODE_ALL);        // Create a Definition for the output wsdl        Definition def = createDefinition();        // Write interface header        writeDefinitions(def, intfNS);        // Create Types        types = createTypes(def);        // Write the WSDL constructs and return full Definition        Binding binding = writeBinding(def, true);        writePortType(def, binding);        writeService(def, binding);        return def;    }    /**     * Get a interface WSDL <code>Definition</code> for the     * current configuration parameters     *      * @return WSDL <code>Definition</code>     * @throws IOException                       * @throws WSDLException                     * @throws SAXException                      * @throws ParserConfigurationException      */    public Definition getIntfWSDL()            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        // Invoke the init() method to ensure configuration is setup        init(MODE_INTERFACE);        // Create a definition for the output wsdl        Definition def = createDefinition();        // Write interface header        writeDefinitions(def, intfNS);        // Create Types        types = createTypes(def);        // Write the interface WSDL constructs and return the Definition        Binding binding = writeBinding(def, true);        writePortType(def, binding);        return def;    }    /**     * Get implementation WSDL <code>Definition</code> for the     * current configuration parameters     *      * @return WSDL <code>Definition</code>     * @throws IOException                       * @throws WSDLException                     * @throws SAXException                      * @throws ParserConfigurationException      */    public Definition getImplWSDL()            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        // Invoke the init() method to ensure configuration is setup        init(MODE_IMPLEMENTATION);        // Create a Definition for the output wsdl        Definition def = createDefinition();        // Write implementation header and import        writeDefinitions(def, implNS);        writeImport(def, intfNS, importUrl);        // Write the implementation WSDL constructs and return Definition        Binding binding = writeBinding(def, false);    // Don't add binding to def        writeService(def, binding);        return def;    }    /**     * Invoked prior to building a definition to ensure parms     * and data are set up.     *      * @param mode      */    protected void init(int mode) {        // Default use depending on setting of style        if (use == null) {            if (style == Style.RPC) {                use = Use.ENCODED;            } else {                use = Use.LITERAL;            }        }        if (tm == null) {            String encodingStyle = "";            if (use == Use.ENCODED) {                encodingStyle = Constants.URI_SOAP11_ENC;                /** TODO : Set this correctly if we do SOAP 1.2 support here */            }            tm = (TypeMapping)tmr.getTypeMapping(encodingStyle);        }        // Set up a ServiceDesc to use to introspect the Service        if (serviceDesc == null) {            JavaServiceDesc javaServiceDesc = new JavaServiceDesc();            serviceDesc = javaServiceDesc;            javaServiceDesc.setImplClass(cls);            // Set the typeMapping to the one provided.            serviceDesc.setTypeMapping(tm);            javaServiceDesc.setStopClasses(stopClasses);            serviceDesc.setAllowedMethods(allowedMethods);            javaServiceDesc.setDisallowedMethods(disallowedMethods);            serviceDesc.setStyle(style);            serviceDesc.setUse(use);            // If the class passed in is a portType,            // there may be an implClass that is used to            // obtain the method parameter names.  In this case,            // a serviceDesc2 is built to get the method parameter names.            if ((implCls != null) && (implCls != cls)                    && (serviceDesc2 == null)) {                serviceDesc2 = new JavaServiceDesc();                serviceDesc2.setImplClass(implCls);                // Set the typeMapping to the one provided.                serviceDesc2.setTypeMapping(tm);                serviceDesc2.setStopClasses(stopClasses);                serviceDesc2.setAllowedMethods(allowedMethods);                serviceDesc2.setDisallowedMethods(disallowedMethods);                serviceDesc2.setStyle(style);            }        }        if (encodingList == null) {            // if cls contains a Class object with the service implementation use the Name of the            // class else use the service name            if (cls != null) {                clsName = cls.getName();                clsName = clsName.substring(clsName.lastIndexOf('.') + 1);            } else {                clsName = getServiceDesc().getName();            }            // Default the portType name            if (getPortTypeName() == null) {                setPortTypeName(clsName);            }            // Default the serviceElementName            if (getServiceElementName() == null) {                setServiceElementName(getPortTypeName() + "Service");            }            // If service port name is null, construct it from location or className            if (getServicePortName() == null) {                String name = getLocationUrl();                if (name != null) {                    if (name.lastIndexOf('/') > 0) {                        name = name.substring(name.lastIndexOf('/') + 1);                    } else if (name.lastIndexOf('\\') > 0) {                        name = name.substring(name.lastIndexOf('\\') + 1);                    } else {                        name = null;                    }                    // if we got the name from the location, strip .jws from it                    if ((name != null) && name.endsWith(".jws")) {                        name = name.substring(0, (name.length()                                - ".jws".length()));                    }                }                if ((name == null) || name.equals("")) {                    name = clsName;                }                setServicePortName(name);            }            // Default the bindingName            if (getBindingName() == null) {                setBindingName(getServicePortName() + "SoapBinding");            }            encodingList = new ArrayList();            encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);            if (intfNS == null) {                Package pkg = cls.getPackage();                intfNS = namespaces.getCreate((pkg == null)                        ? null                        : pkg.getName());            }            // Default the implementation namespace to the interface            // namespace if not split wsdl mode.            if (implNS == null) {                if (mode == MODE_ALL) {                    implNS = intfNS;                } else {                    implNS = intfNS + "-impl";                }            }            // set the namespaces in the serviceDesc(s)            serviceDesc.setDefaultNamespace(intfNS);            if (serviceDesc2 != null) {                serviceDesc2.setDefaultNamespace(implNS);            }            if (cls != null) {                String clsName = cls.getName();                int idx = clsName.lastIndexOf(".");                if (idx > 0) {                    String pkgName = clsName.substring(0, idx);                    namespaces.put(pkgName, intfNS, "intf");                }            }            namespaces.putPrefix(implNS, "impl");        }    }    /**     * Build a Definition from the input wsdl file or create     * a new Definition     *      * @return WSDL Definition     * @throws WSDLException                     * @throws SAXException                      * @throws IOException                       * @throws ParserConfigurationException      */    protected Definition createDefinition()            throws WSDLException, SAXException, IOException,            ParserConfigurationException {        Definition def;        if (inputWSDL == null) {            def = WSDLFactory.newInstance().newDefinition();        } else {            javax.wsdl.xml.WSDLReader reader =                    WSDLFactory.newInstance().newWSDLReader();            Document doc = XMLUtils.newDocument(inputWSDL);            def = reader.readWSDL(null, doc);            // The input wsdl types section is deleted.  The            // types will be added back in at the end of processing.            def.setTypes(null);        }        return def;    }    /** Field standardTypes */    protected static TypeMapping standardTypes =            (TypeMapping) new org.apache.axis.encoding.TypeMappingRegistryImpl().getTypeMapping(                    null);    /**     * Build a Types object and load the input wsdl types     *      * @param def Corresponding wsdl Definition     * @return Types object     * @throws IOException                       * @throws WSDLException                     * @throws SAXException                      * @throws ParserConfigurationException      */    protected Types createTypes(Definition def)            throws IOException, WSDLException, SAXException,            ParserConfigurationException {        types = new Types(def, tm, (TypeMapping)tmr.getDefaultTypeMapping(),                          namespaces, intfNS, stopClasses, serviceDesc, this);        if (inputWSDL != null) {            types.loadInputTypes(inputWSDL);        }        if (inputSchema != null) {            StringTokenizer tokenizer = new StringTokenizer(inputSchema, ", ");            while (tokenizer.hasMoreTokens()) {                String token = tokenizer.nextToken();                types.loadInputSchema(token);            }        }                // If we're supposed to emit all mapped types, do it now.        if (emitAllTypes && tm != null) {             Class[] mappedTypes = tm.getAllClasses();                         for (int i = 0; i < mappedTypes.length; i++) {                 Class mappedType = mappedTypes[i];                 QName name = tm.getTypeQName(mappedType);                 if (name.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1) {                     // If this is an anonymous type, it doesn't need to be                    // written out here (and trying to do so will generate an                    // error). Skip it.                     continue;                 }                                 /** 

⌨️ 快捷键说明

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