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

📄 happyclient.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2003,2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.client;import org.apache.axis.utils.Messages;import org.apache.axis.utils.ClassUtils;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import java.io.InputStream;import java.io.IOException;import java.io.PrintStream;/** * Client side equivalent of happyaxis */public class HappyClient {    PrintStream out;    public HappyClient(PrintStream out) {        this.out = out;    }    /**     * test for a class existing     * @param classname     * @return class iff present     */    Class classExists(String classname) {        try {            return Class.forName(classname);        } catch (ClassNotFoundException e) {            return null;        }    }    /**     * test for resource on the classpath     * @param resource     * @return true iff present     */    boolean resourceExists(String resource) {        boolean found;        InputStream instream = ClassUtils.getResourceAsStream(this.getClass(),resource);        found = instream != null;        if (instream != null) {            try {                instream.close();            } catch (IOException e) {            }        }        return found;    }    /**     * probe for a class, print an error message is missing     * @param category text like "warning" or "error"     * @param classname class to look for     * @param jarFile where this class comes from     * @param errorText extra error text     * @param homePage where to d/l the library     * @return the number of missing classes     * @throws java.io.IOException     */    int probeClass(            String category,                   String classname,                   String jarFile,                   String description,                   String errorText,                   String homePage) throws IOException {        String url = "";        if (homePage != null) {            url=Messages.getMessage("happyClientHomepage",homePage);        }        String errorLine="";        if (errorText != null) {            errorLine=Messages.getMessage(errorText);        }        try {            Class clazz = classExists(classname);            if (clazz == null) {                String text;                text=Messages.getMessage("happyClientMissingClass",                        category,classname,jarFile);                out.println(text);                out.println(url);                return 1;            } else {                String location = getLocation(clazz);                String text;                if (location == null) {                    text=Messages.getMessage("happyClientFoundDescriptionClass",                                    description,classname);                } else {                    text = Messages.getMessage("happyClientFoundDescriptionClassLocation",                            description, classname,location);                }                out.println(text);                return 0;            }        } catch (NoClassDefFoundError ncdfe) {            out.println(Messages.getMessage("happyClientNoDependency",                category, classname, jarFile));            out.println(errorLine);            out.println(url);            out.println(ncdfe.getMessage());            return 1;        }    }    /**     * get the location of a class     * @param clazz     * @return the jar file or path where a class was found     */    String getLocation(            Class clazz) {        try {            java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();            String location = url.toString();            if (location.startsWith("jar")) {                url = ((java.net.JarURLConnection) url.openConnection()).getJarFileURL();                location = url.toString();            }            if (location.startsWith("file")) {                java.io.File file = new java.io.File(url.getFile());                return file.getAbsolutePath();            } else {                return url.toString();            }        } catch (Throwable t) {        }        return Messages.getMessage("happyClientUnknownLocation");    }    /**     * a class we need if a class is missing     * @param classname class to look for     * @param jarFile where this class comes from     * @param errorText extra error text     * @param homePage where to d/l the library     * @throws java.io.IOException when needed     * @return the number of missing libraries (0 or 1)     */    int needClass(            String classname,                  String jarFile,                  String description,                  String errorText,                  String homePage) throws IOException {        return probeClass(                Messages.getMessage("happyClientError"),                classname,                jarFile,                description,                errorText,                homePage);    }    /**     * print warning message if a class is missing     * @param classname class to look for     * @param jarFile where this class comes from     * @param errorText extra error text     * @param homePage where to d/l the library     * @throws java.io.IOException when needed     * @return the number of missing libraries (0 or 1)     */    int wantClass(            String classname,                  String jarFile,                  String description,                  String errorText,                  String homePage) throws IOException {        return probeClass(                Messages.getMessage("happyClientWarning"),                classname,                jarFile,                description,                errorText,                homePage);    }    /**     * probe for a resource existing,     * @param resource     * @param errorText     * @throws Exception     */    int wantResource(            String resource,                     String errorText) throws Exception {        if (!resourceExists(resource)) {            out.println(Messages.getMessage("happyClientNoResource",resource));            out.println(errorText);            return 0;        } else {            out.println(Messages.getMessage("happyClientFoundResource", resource));            return 1;        }    }    /**     * what parser are we using.     * @return the classname of the parser     */    private String getParserName() {        SAXParser saxParser = getSAXParser();        if (saxParser == null) {            return Messages.getMessage("happyClientNoParser");        }        // check to what is in the classname        String saxParserName = saxParser.getClass().getName();        return saxParserName;    }    /**     * Create a JAXP SAXParser     * @return parser or null for trouble     */    private SAXParser getSAXParser() {        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();        if (saxParserFactory == null) {            return null;        }        SAXParser saxParser = null;        try {            saxParser = saxParserFactory.newSAXParser();        } catch (Exception e) {

⌨️ 快捷键说明

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