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

📄 bindinggenerator.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                            // create a collection for list subclass                            System.err.println("Warning: property " + pname +                                " requires mapped implementation of item " +                                "classes");                            element = new CollectionElement();                            element.setComment(" add details of collection " +                                "items to complete binding definition ");                            element.setGetName(gname);                            element.setSetName(sname);                                                        // specify factory method if just typed as interface                            if ("java.util.List".equals(tname)) {                                element.setFactoryName("org.jibx.runtime." +                                    "Utility.arrayListFactory");                            }                                                    } else if (pcf.isInterface() ||                            m_ignoreNames.contains(tname)) {                                                        // mapping reference with warning for interface                            nestingIndent(System.err);                            System.err.println("Warning: reference to " +                                "interface or abstract class " + tname +                                " requires mapped implementation");                            element = new StructureElement();                            element.setGetName(gname);                            element.setSetName(sname);                                                    } else {                                                        // handle other types of structures directly                            element = createStructure(pcf, pname);                        }                                                // finish with common handling                        element.setUsageName("optional");                        contain.addChild(element);                                            }                }            }        }    }        /**     * Construct the list of child binding components that define the binding     * structure corresponding to a particular class. This binds all     * non-final/non-static/non-transient fields of the class, if necessary     * creating nested structure elements for unmapped classes referenced by the     * fields.     *      * @param cf class information     * @param contain binding structure container element     * @throws JiBXException on error in binding generation     */    private void defineStructure(ClassFile cf, ContainerElementBase contain)        throws JiBXException {                // process basic fields or property list        Object props = m_beanNames.get(cf.getName());        if (props == null) {            defineFields(cf, contain);        } else {            defineProperties(cf, (ArrayList)props, true, contain);        }                // check if superclass may have data for binding        ClassFile sf = cf.getSuperFile();        String sname = sf.getName();        if (!"java.lang.Object".equals(sname) &&            !m_ignoreNames.contains(sname)) {            if (m_mappedNames.get(sname) != null) {                StructureElement structure = new StructureElement();                structure.setMapAsName(sname);                structure.setName(elementName(sname));                contain.addChild(structure);            } else if (m_beanNames.get(sname) != null) {                defineProperties(sf, (ArrayList)m_beanNames.get(sname),                    false, contain);            } else if (sf.getRawClass().getFields().length > 0) {                nestingIndent(System.err);                System.err.println("Warning: fields from base class " + sname +                    " of class " + cf.getName() + " not handled by generated " +                    "binding; use mapping or specify property list");                contain.setComment(" missing information for base class " +                    sname + " ");            }        }    }        /**     * Create the structure element for a particular class. This maps all     * non-final/non-static/non-transient fields of the class, if necessary     * creating nested structures.     *      * @param cf class information     * @param fname name of field supplying reference     * @throws JiBXException on error in binding generation     */    private StructureElement createStructure(ClassFile cf, String fname)        throws JiBXException {        JavaClass clas = cf.getRawClass();        if (m_verbose) {            nestingIndent(System.out);            System.out.println("creating nested structure definition for " +                clas.getClassName());        }        String cname = clas.getClassName();        for (int i = 0; i < m_structureStack.size(); i++) {            if (cname.equals(m_structureStack.peek(i))) {                StringBuffer buff =                    new StringBuffer("Error: recursive use of ");                buff.append(cname);                buff.append(" requires <mapping>:\n ");                while (i >= 0) {                    buff.append(m_structureStack.peek(i--));                    buff.append(" -> ");                }                buff.append(cname);                throw new JiBXException(buff.toString());            }        }        if (cname.startsWith("java.")) {            nestingIndent(System.err);            System.err.println("Warning: trying to create structure for " +                cname);        } else if (m_structureNames.contains(cname)) {            nestingIndent(System.err);            System.err.println("Warning: repeated usage of class " +                cname + "; consider adding to mapping list");        } else {            m_structureNames.add(cname);        }        m_structureStack.push(cname);        StructureElement element = new StructureElement();        element.setFieldName(fname);        element.setName(valueName(fname));        defineStructure(cf, element);        if (element.children().isEmpty()) {            throw new JiBXException("No content found for class " + cname);        }        m_structureStack.pop();        if (m_verbose) {            nestingIndent(System.out);            System.out.println("completed nested structure definition for " +                clas.getClassName());        }        return element;    }    /**     * Create the mapping element for a particular class. This maps all     * non-final/non-static/non-transient fields of the class, if necessary     * creating nested structures.     *      * @param cf class information     * @param abstr force abstract mapping flag     * @throws JiBXException on error in binding generation     */    private MappingElement createMapping(ClassFile cf, boolean abstr)        throws JiBXException {        JavaClass clas = cf.getRawClass();        if (m_verbose) {            System.out.println("\nBuilding mapping definition for " +                clas.getClassName());        }        MappingElement element = new MappingElement();        element.setAbstract(abstr || clas.isAbstract() || clas.isInterface());        String name = clas.getClassName();        element.setClassName(name);        if (abstr) {            element.setAbstract(true);        } else {            element.setName((String)m_mappedNames.get(name));        }        m_structureStack.push(name);        defineStructure(cf, element);        m_structureStack.pop();        return element;    }        private static boolean isMappable(String cname) {        if ("java.lang.String".equals(cname)) {            return false;        } else if ("java.lang.Object".equals(cname)) {            return false;        } else if (ClassItem.isPrimitive(cname)) {            return false;        } else {            return !s_objectPrimitiveSet.contains(cname);        }    }    /**     * Get the set of data classes passed to or returned by a list of methods     * within a class. The classes returned exclude primitive types, wrappers,     * <code>java.lang.String</code>, and <code>java.lang.Object</code>.     * Exception classes thrown by the methods are also optionally accumulated.     *      * @param cname target class name     * @param mnames method names to be checked     * @param dataset set for accumulation of data classes (optional, data     * classes not recorded if <code>null</code>)     * @param exceptset set for accumulation of exception classes (optional,     * data classes not recorded if <code>null</code>)     * @throws JiBXException on error in loading class information     */    public static void findClassesUsed(String cname, ArrayList mnames,        HashSet dataset, HashSet exceptset) throws JiBXException {        ClassFile cf = ClassCache.getClassFile(cname);        if (cf != null) {            for (int i = 0; i < mnames.size(); i++) {                String mname = (String)mnames.get(i);                ClassItem mitem = cf.getMethod(mname, "");                if (mitem == null) {                    System.err.println("Method " + mname +                        " not found in class " + cname);                } else {                    if (dataset != null) {                        String type = mitem.getTypeName();                        if (type != null && isMappable(type)) {                            dataset.add(type);                        }                        String[] args = mitem.getArgumentTypes();                        for (int j = 0; j < args.length; j++) {                            type = args[j];                            if (isMappable(type)) {                                dataset.add(args[j]);                            }                        }                    }                    if (exceptset != null) {                        String[] excepts = mitem.getExceptions();                        for (int j = 0; j < excepts.length; j++) {                            exceptset.add(excepts[j]);                        }                    }                }            }        }    }        /**     * Generate a set of bindings using supplied classpaths and class names.     *      * @param names list of class names to be included in binding     * @param abstracts set of classes to be handled with abstract mappings in     * binding     * @param customs map of customized class names to marshaller/unmarshaller     * class names     * @param beans map of class names to supplied lists of properties     * @param enums map of typesafe enumeration classes to deserializer methods     * @param ignores list of non-interface classes to be treated as interfaces     * (no mapping, but mapped subclasses are used at runtime)     * @exception JiBXException if error in generating the binding definition     */    public BindingElement generate(ArrayList names, HashSet abstracts,        HashMap customs, HashMap beans, HashMap enums, ArrayList ignores)        throws JiBXException {                // print current version information        System.out.println("Running binding generator version " +            CURRENT_VERSION);                // add all classes with mappings to tracking map        m_mappedNames.clear();        for (int i = 0; i < names.size(); i++) {                        // make sure class can potentially be handled automatically            boolean drop = false;            String name = (String)names.get(i);            ClassFile cf = ClassCache.getClassFile(name);            if (cf.isImplements("Ljava/util/List;") ||                cf.isImplements("Ljava/util/Map;")) {                System.err.println("Warning: referenced class " + name +                    " is a collection class that cannot be mapped " +                    "automatically; dropped from mapped list in binding");                drop = true;            } else if (cf.isInterface()) {                System.err.println("Warning: interface " + name +                    " is being handled as abstract mapping");                abstracts.add(name);                drop = true;            } else if (cf.isAbstract()) {

⌨️ 快捷键说明

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