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

📄 bindinggenerator.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                System.err.println("Warning: mapping abstract class " + name +                    "; make sure actual subclasses are mapped as extending " +                    "this abstract mapping");                abstracts.add(name);                drop = true;            }            if (drop) {                names.remove(i--);            } else {                m_mappedNames.put(name, elementName(name));            }        }        for (Iterator iter = abstracts.iterator(); iter.hasNext();) {            m_mappedNames.put((String)iter.next(), "");        }        for (Iterator iter = customs.keySet().iterator(); iter.hasNext();) {            String name = (String)iter.next();            m_mappedNames.put(name, elementName(name));        }                // create set for ignores        m_ignoreNames.clear();        m_ignoreNames.addAll(ignores);                // create binding with optional namespace        BindingElement binding = new BindingElement();        binding.setStyleName("attribute");        if (m_namespaceUri != null) {            NamespaceElement namespace = new NamespaceElement();            namespace.setComment(" namespace for all elements of binding ");            namespace.setDefaultName("elements");            namespace.setUri(m_namespaceUri);            binding.addTopChild(namespace);        }                // add mapping for each specified class        m_structureStack.clear();        m_structureNames.clear();        m_beanNames = beans;        m_enumerationNames = enums;        for (int i = 0; i < names.size(); i++) {            String cname = (String)names.get(i);            if (!abstracts.contains(cname)) {                ClassFile cf = ClassCache.getClassFile(cname);                MappingElement mapping = createMapping(cf, false);                mapping.setComment(" generated mapping for class " + cname);                binding.addTopChild(mapping);            }        }        for (Iterator iter = abstracts.iterator(); iter.hasNext();) {            String cname = (String)iter.next();            ClassFile cf = ClassCache.getClassFile(cname);            MappingElement mapping = createMapping(cf, true);            mapping.setComment(" generate abstract mapping for class " + cname);            binding.addTopChild(mapping);        }                // finish with custom mapping definitions        for (Iterator iter = customs.keySet().iterator(); iter.hasNext();) {            String cname = (String)iter.next();            String mname = (String)customs.get(cname);            MappingElement mapping = new MappingElement();            mapping.setComment(" specified mapping for class " + cname);            mapping.setClassName(cname);            mapping.setName((String)m_mappedNames.get(cname));            mapping.setMarshallerName(mname);            mapping.setUnmarshallerName(mname);            binding.addTopChild(mapping);        }                // list classes handled if verbose        if (m_verbose) {            for (int i = 0; i < names.size(); i++) {                m_structureNames.add(names.get(i));            }            m_structureNames.addAll(customs.keySet());            String[] classes = (String[])m_structureNames.                toArray(new String[m_structureNames.size()]);            Arrays.sort(classes);            System.out.println("\nClasses included in binding:");            for (int i = 0; i < classes.length; i++) {                System.out.println(" " + classes[i]);            }        }        return binding;    }        /**     * Main method for running compiler as application.     *     * @param args command line arguments     */    public static void main(String[] args) {        if (args.length > 0) {            try {                                // check for various flags set                boolean mixed = false;                boolean verbose = false;                String uri = null;                String fname = "binding.xml";                ArrayList paths = new ArrayList();                HashMap enums = new HashMap();                HashSet abstracts = new HashSet();                ArrayList ignores = new ArrayList();                HashMap customs = new HashMap();                HashMap beans = new HashMap();                int offset = 0;                for (; offset < args.length; offset++) {                    String arg = args[offset];                    if ("-v".equalsIgnoreCase(arg)) {                        verbose = true;                    } else if ("-b".equalsIgnoreCase(arg)) {                        String plist = args[++offset];                        int split = plist.indexOf("=");                        String bname = plist.substring(0, split);                        ArrayList props = new ArrayList();                        int base = ++split;                        while ((split = plist.indexOf(',', split)) >= 0) {                            props.add(plist.substring(base, split));                            base = ++split;                        }                        props.add(plist.substring(base));                        beans.put(bname, props);                    } else if ("-c".equalsIgnoreCase(arg)) {                        String custom = args[++offset];                        int split = custom.indexOf('=');                        if (split > 0) {                            customs.put(custom.substring(0, split),                                custom.substring(split+1));                        } else {                            System.err.println                                ("Unable to interpret customization " + custom);                        }                    } else if ("-e".equalsIgnoreCase(arg)) {                        String cname;                        String mname;                        String enumf = args[++offset];                        int split = enumf.indexOf('=');                        if (split > 0) {                            cname = enumf.substring(0, split);                            mname = enumf.substring(split+1);                            if (mname.indexOf('.') < 0) {                                mname = cname + '.' + mname;                            }                        } else {                            cname = enumf;                            split = cname.lastIndexOf('.');                            if (split >= 0) {                                mname = cname + '.' + "get" +                                    cname.substring(split+1);                            } else {                                mname = cname + '.' + "get" + cname;                            }                        }                        enums.put(cname, mname);                    } else if ("-i".equalsIgnoreCase(arg)) {                        ignores.add(args[++offset]);                    } else if ("-m".equalsIgnoreCase(arg)) {                        mixed = true;                    } else if ("-f".equalsIgnoreCase(arg)) {                        fname = args[++offset];                    } else if ("-n".equalsIgnoreCase(arg)) {                        uri = args[++offset];                    } else if ("-p".equalsIgnoreCase(arg)) {                        paths.add(args[++offset]);                    } else if ("-a".equalsIgnoreCase(arg)) {                        abstracts.add(args[++offset]);                    } else {                        break;                    }                }                                // set up path and binding lists                String[] vmpaths = Utility.getClassPaths();                for (int i = 0; i < vmpaths.length; i++) {                    paths.add(vmpaths[i]);                }                ArrayList names = new ArrayList();                for (int i = offset; i < args.length; i++) {                    if (!abstracts.contains(args[i])) {                        names.add(args[i]);                    }                }                                // report on the configuration                if (verbose) {                    System.out.println("Using paths:");                    for (int i = 0; i < paths.size(); i++) {                        System.out.println(" " + paths.get(i));                    }                    System.out.println("Using class names:");                    for (int i = 0; i < names.size(); i++) {                        System.out.println(" " + names.get(i));                    }                    if (abstracts.size() > 0) {                        System.out.println("Using abstract class names:");                        for (Iterator iter = abstracts.iterator();                            iter.hasNext();) {                            System.out.println(" " + iter.next());                        }                    }                    if (customs.size() > 0) {                        System.out.println                            ("Using custom marshaller/unmarshallers:");                        Iterator iter = customs.keySet().iterator();                        while (iter.hasNext()) {                            String key = (String)iter.next();                            System.out.println(" " + customs.get(key) +                                " for " + key);                        }                    }                    if (beans.size() > 0) {                        System.out.println("Using bean property lists:");                        Iterator iter = beans.keySet().iterator();                        while (iter.hasNext()) {                            String key = (String)iter.next();                            System.out.print(" " + key + " with properties:");                            ArrayList props = (ArrayList)beans.get(key);                            for (int i = 0; i < props.size(); i++) {                                System.out.print(i > 0 ? ", " : " ");                                System.out.print(props.get(i));                            }                        }                    }                    if (enums.size() > 0) {                        System.out.println("Using enumeration classes:");                        Iterator iter = enums.keySet().iterator();                        while (iter.hasNext()) {                            String key = (String)iter.next();                            System.out.println(" " + key +                                " with deserializer " + enums.get(key));                        }                    }                }                                // set paths to be used for loading referenced classes                String[] parray =                    (String[])paths.toArray(new String[paths.size()]);                ClassCache.setPaths(parray);                ClassFile.setPaths(parray);                                // generate the binding                BindingGenerator generate =                    new BindingGenerator(verbose, mixed, uri);                BindingElement binding = generate.generate(names, abstracts,                    customs, beans, enums, ignores);                                // marshal binding out to file                IBindingFactory bfact =                    BindingDirectory.getFactory(BindingElement.class);                IMarshallingContext mctx = bfact.createMarshallingContext();                mctx.setIndent(2);                mctx.marshalDocument(binding, "UTF-8", null,                    new FileOutputStream(fname));                            } catch (JiBXException ex) {                ex.printStackTrace(System.out);                System.exit(1);            } catch (FileNotFoundException e) {                e.printStackTrace(System.out);                System.exit(2);            }                    } else {            System.out.println                ("\nUsage: java org.jibx.binding.BindingGenerator [options] " +                "class1 class2 ...\nwhere options are:\n -a  abstract class\n" +                " -b  bean property class,\n -c  custom mapped class,\n" +                " -e  enumeration class,\n -f  binding file name,\n" +                " -i  ignore class,\n -m  use mixed case XML names (instead " +                "of hyphenated),\n -n  namespace URI,\n -p  class " +                "loading path component,\n -v  turns on verbose output\n" +                "The class# files are different classes to be included in " +                "binding (references from\nthese classes will also be " +                "included).\n");            System.exit(1);        }    }}

⌨️ 快捷键说明

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