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

📄 customizationcommandlinebase.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 2007, Dennis M. SosnoskiAll rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this   list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,   this list of conditions and the following disclaimer in the documentation   and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used   to endorse or promote products derived from this software without specific   prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/package org.jibx.binding.generator;import java.io.File;import java.io.IOException;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.jibx.binding.Utility;import org.jibx.binding.classes.ClassCache;import org.jibx.binding.classes.ClassFile;import org.jibx.binding.model.IClassLocator;import org.jibx.runtime.IUnmarshallingContext;import org.jibx.runtime.JiBXException;import org.jibx.ws.wsdl.ClassSourceLocator;/** * Command line processor for customizable tools. */public abstract class CustomizationCommandLineBase{    /** Array of method parameter classes for single String parameter. */    public static final Class[] STRING_PARAMETER_ARRAY =        new Class[] { String.class };        /** Array of classes for String and unmarshaller parameters. */    public static final Class[] STRING_UNMARSHALLER_PARAMETER_ARRAY =        new Class[] { String.class, IUnmarshallingContext.class };        /** Ordered array of usage lines. */    protected static final String[] BASE_USAGE_LINES = new String[] {        " -f path  input binding customizations file",        " -p path  class loading path component",        " -s path  source path component",        " -t path  target directory for generated output (default is" +        " current directory)",        " -v       verbose output flag"    };        /** List of source paths. */    private List m_sourcePaths;        /** List of specified classes or files. */    private List m_extraArgs;        /** Target directory for output. */    private File m_generateDirectory;        /**     * Process command line arguments array.     *     * @param args     * @return <code>true</code> if valid, <code>false</code> if not     * @throws JiBXException     * @throws IOException     */    public boolean processArgs(String[] args) throws JiBXException, IOException {        boolean verbose = false;        String custom = null;        String genpath = null;        ArrayList paths = new ArrayList();        m_sourcePaths = new ArrayList();        Map overrides = new HashMap();        ArgList alist = new ArgList(args);        while (alist.hasNext()) {            String arg = alist.next();            if ("-f".equalsIgnoreCase(arg)) {                custom = alist.next();            } else if ("-p".equalsIgnoreCase(arg)) {                paths.add(alist.next());            } else if ("-s".equalsIgnoreCase(arg)) {                m_sourcePaths.add(alist.next());            } else if ("-t".equalsIgnoreCase(arg)) {                genpath = alist.next();            } else if ("-v".equalsIgnoreCase(arg)) {                verbose = true;            } else if (arg.startsWith("--") && arg.length() > 2 &&                Character.isLetter(arg.charAt(2))) {                if (!putKeyValue(arg.substring(2), overrides)) {                    alist.setValid(false);                }            } else if (!checkParameter(alist)) {                if (arg.startsWith("-")) {                    System.err.println("Unknown option flag '" + arg + '\'');                    alist.setValid(false);                }  else {                    break;                }            }        }                // collect the class names to be generated        m_extraArgs = new ArrayList();        m_extraArgs.add(alist.current());        while (alist.hasNext()) {            String arg = alist.next();            if (arg.startsWith("-")) {                System.err.println("Command line options must precede all other arguments: error on '" + arg + '\'');;                alist.setValid(false);                break;            } else {                m_extraArgs.add(arg);            }        }                // check for valid command line arguments        if (alist.isValid()) {                        // set up path and binding lists            String[] vmpaths = Utility.getClassPaths();            for (int i = 0; i < vmpaths.length; i++) {                paths.add(vmpaths[i]);            }                        // set output directory            if (genpath == null) {                m_generateDirectory = new File(".");            } else {                m_generateDirectory = new File(genpath);            }            if (!m_generateDirectory.exists()) {                m_generateDirectory.mkdirs();            }            if (!m_generateDirectory.canWrite()) {                System.err.println("Target directory " + m_generateDirectory.getPath() + " is not writable");                alist.setValid(false);            } else {                                // report on the configuration                if (verbose) {                    System.out.println("Using class loading paths:");                    for (int i = 0; i < paths.size(); i++) {                        System.out.println(" " + paths.get(i));                    }                    System.out.println("Using source loading paths:");                    for (int i = 0; i < m_sourcePaths.size(); i++) {                        System.out.println(" " + m_sourcePaths.get(i));                    }                    verboseDetails();                    System.out.println("Output to directory " + m_generateDirectory);                }                                // set paths to be used for loading referenced classes                String[] parray = (String[])paths.toArray(new String[paths.size()]);                ClassCache.setPaths(parray);                ClassFile.setPaths(parray);                                // load customizations and apply overrides                String[] spaths = (String[])m_sourcePaths.toArray                    (new String[m_sourcePaths.size()]);                loadCustomizations(custom, new ClassSourceLocator(spaths));                Map unknowns = applyOverrides(overrides);                if (!unknowns.isEmpty()) {                    for (Iterator iter = unknowns.keySet().iterator();                        iter.hasNext();) {                        String key = (String)iter.next();                        System.err.println("Unknown override key '" + key + '\'');                    }                    alist.setValid(false);                }            }                    } else {            printUsage();        }        return alist.isValid();    }        /**     * Get generate directory.     *     * @return directory     */    public File getGeneratePath() {        return m_generateDirectory;    }    /**     * Get extra arguments from command line. These extra arguments must follow     * all parameter flags.     *     * @return args     */    public List getExtraArgs() {        return m_extraArgs;    }        /**     * Apply a key/value map to a customization object instance. This uses     * reflection to match the keys to either set methods (with names of the     * form setZZZText, or setZZZ, taking a single String parameter) or String     * fields (named m_ZZZ). The ZZZ in the names is based on the key name, with     * hyphenation converted to camel case (leading upper camel case, for the     * method names).     *     * @param map     * @param obj     * @return map for key/values not found in the supplied object     */    public static Map applyKeyValueMap(Map map, Object obj) {        Map missmap = new HashMap();        for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {            String key = (String)iter.next();            String value = (String)map.get(key);            boolean fail = true;            Throwable t = null;            try {                StringBuffer buff = new StringBuffer(key);                for (int i = 0; i < buff.length(); i++) {                    char chr = buff.charAt(i);                    if (chr == '-') {                        buff.deleteCharAt(i);                        buff.setCharAt(i,                            Character.toUpperCase(buff.charAt(i)));                    }                }                String fname = "m_" + buff.toString();                buff.setCharAt(0, Character.toUpperCase(buff.charAt(0)));                String mname = "set" + buff.toString();                Method method = null;                Class clas = obj.getClass();

⌨️ 快捷键说明

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