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

📄 bindingbuilder.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *     * @param ctx unmarshalling context information     * @param defc definition context for defined namespaces     * @throws JiBXException if error in unmarshalling     */        private static void unmarshalNamespaces(UnmarshallingContext ctx,        DefinitionContext defc) throws JiBXException {        while (ctx.isAt(URI_ELEMENTS, NAMESPACE_ELEMENT)) {            defc.addNamespace(unmarshalNamespace(ctx));        }    }    /**     * Unmarshal format definitions. Any format definitions present are     * unmarshalled and added to the supplied definition context.     *     * @param ctx unmarshalling context information     * @param defc definition context for defined formats     * @throws JiBXException if error in unmarshalling     */        private static void unmarshalFormats(UnmarshallingContext ctx,        DefinitionContext defc) throws JiBXException {                // process all format definitions at level        while (ctx.isAt(URI_ELEMENTS, FORMAT_ELEMENT)) {                        // find the current default format information for type            String type = ctx.attributeText(URI_ATTRIBUTES, FORMAT_TYPE);            String sig = Utility.getSignature(type);            StringConversion base = null;            if (sig.length() == 1) {                                // must be a primitive, check type directly                base = defc.getSpecificConversion(type);                if (base == null) {                    ctx.throwStartTagException("Unsupported \"" +                        FORMAT_TYPE + "\" value");                }                            } else {                                // must be an object type, find best match                ClassFile cf = ClassCache.getClassFile(type);                base = defc.getConversion(cf);                            }                        // unmarshal with defaults provided by existing format            StringConversion format =                unmarshalStringConversion(ctx, base, type);                        // handle based on presence or absence of name attribute            String text = ctx.attributeText(URI_ATTRIBUTES, FORMAT_NAME, null);            if (text == null) {                defc.setConversion(format);            } else {                QName qname = QName.deserialize(text, ctx);                defc.setNamedConversion(qname, format);            }                        // scan past end of definition            ctx.parsePastEndTag(URI_ELEMENTS, FORMAT_ELEMENT);        }    }    /**     * Unmarshal mapping definitions. Any mapping definitions present are     * unmarshalled and added to the supplied definition context.     *     * @param ctx unmarshalling context information     * @param parent containing binding definition structure     * @param nss extra namespaces to be included in this mapping definition     * (may be <code>null</code>)     * @param uord container is unordered structure flag     * @throws JiBXException if error in unmarshalling     */        private static void unmarshalMappings(UnmarshallingContext ctx,        IContainer parent, ArrayList nss, boolean uord) throws JiBXException {        while (ctx.isAt(URI_ELEMENTS, MAPPING_ELEMENT)) {            unmarshalMapping(ctx, parent, nss, uord);        }    }    /**     * Unmarshal subclass instance for structure definition. This handles all     * combinations of attributes on the start tag, generating the appropriate     * structure of nested components and other classes to represent the binding     * information within the current element. This must be called with the     * parse positioned at the start tag of the element to be unmarshalled.     *      * TODO: At least split this up, or organize a better way to build binding     *     * @param ctx unmarshalling context information     * @param contain containing binding definition structure     * @param cobj context object information     * @param coll collection structure flag     * @param uord container is unordered structure flag     * @param implic property value implicit flag     * @return root of component tree constructed from binding     * @throws JiBXException if error in unmarshalling     */        public static IComponent unmarshalStructure(UnmarshallingContext ctx,        IContainer contain, IContextObj cobj, boolean coll, boolean uord,        boolean implic) throws JiBXException {                // get name definition if supplied (check later to see if valid)        NameDefinition name = null;        if (isNamePresent(ctx)) {            name = unmarshalName(ctx, false);        }                        // check for optional flag on structure        boolean opt = isOptionalProperty(ctx);        boolean incoll = false;        if (contain instanceof NestedCollection) {            incoll = true;            opt = false;        }                // check for property definition supplied        IComponent comp;        boolean hasprop = isPropertyPresent(ctx);        boolean thisref = false;        if (!hasprop) {            thisref = incoll || ctx.hasAttribute(URI_ATTRIBUTES, COMMON_TYPE);        }        boolean mapping = isMappingRef(ctx);        if (hasprop || coll || implic || thisref) {                        // set up the property definition to be used            PropertyDefinition prop = null;            boolean hasobj = hasprop;            if (implic) {                                // make sure no override of implicit property from collection                if (hasprop) {                    ctx.throwStartTagException("Property definition not " +                        "allowed for collection items");                } else {                    String type = ctx.attributeText(URI_ATTRIBUTES,                        COMMON_TYPE, null);                    if (type == null) {                        if (!mapping) {                            if (incoll) {                                type = ((NestedCollection)contain).getItemType();                                hasobj = true;                            } else {                                type = "java.lang.Object";                            }                        }                    } else {                        hasobj = true;                    }                    prop = new PropertyDefinition(type, cobj, opt);                }                            } else if (hasprop || thisref) {                prop = unmarshalProperty(ctx, contain, cobj, opt);            } else {                prop = new PropertyDefinition(cobj, opt);            }                        // check if using direct object marshalling and unmarshalling            if (isDirectObject(ctx)) {                                // validate and configure direct marshalling and unmarshalling                comp = new DirectProperty(prop, unmarshalDirectObj(ctx,                    prop.getTypeName(), contain, null, -1, name));                            } else if (mapping) {                                // validate and configure reference to mapping in context                comp = unmarshalMappingRef(ctx, contain, cobj, prop, name);                            } else {                                // check for object binding needed                IContextObj icobj = cobj;                ObjectBinding bind = null;                boolean typed = false;                if (implic) {                    typed = !prop.getTypeName().equals("java.lang.Object");                } else {                    typed = !prop.getTypeName().equals                        (cobj.getBoundClass().getClassName());                }                if ((hasobj && !prop.isThis()) || (!hasobj && typed)) {                    bind = unmarshalObjectBinding(ctx, cobj, contain,                        prop.getTypeName());                    icobj = bind;                }                                // validate and configure reference to structure in context                if (ctx.hasAttribute(URI_ATTRIBUTES, COMMON_USING)) {                    comp = unmarshalStructureRef(ctx, contain, name,                        prop, icobj);                } else {                                        // validate and configure actual binding definition                    DefinitionContext defc = contain.getDefinitionContext();                    IComponent top = bind;                                        // check for optional label definition                    String label = ctx.attributeText(URI_ATTRIBUTES,                        COMMON_LABEL, null);                                        // set load and store handlers for collection                    NestedCollection.CollectionLoad load = null;                    NestedCollection.CollectionStore store = null;                    String itype = null;                    if (coll) {                                                // get any method names and type supplied by user                        String stname = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_STOREMETHOD, null);                        String aname = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_ADDMETHOD, null);                        String lname = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_LOADMETHOD, null);                        String szname = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_SIZEMETHOD, null);                        String iname = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_ITERMETHOD, null);                        itype = ctx.attributeText(URI_ATTRIBUTES,                            COLLECTION_ITEMTYPE, "java.lang.Object");                                                // verify combinations of attributes supplied                        if ((lname == null || szname == null) &&                            !(lname == null && szname == null)) {                            ctx.throwStartTagException(COLLECTION_LOADMETHOD +                                " and " + COLLECTION_SIZEMETHOD +                                " attributes must be used together");                        }                        if (iname != null && lname != null) {                            ctx.throwStartTagException(COLLECTION_ITERMETHOD +                                " and " + COLLECTION_LOADMETHOD +                                " attributes cannot be used together");                        }                        if (aname != null && stname != null) {                            ctx.throwStartTagException(COLLECTION_ADDMETHOD +                                " and " + COLLECTION_STOREMETHOD +                                " attributes cannot be used together");                        }                                                // set defaults based on collection type                        ClassFile cf = ClassCache.getClassFile                            (prop.getTypeName());                        if (cf.isSuperclass("java.util.Vector")||                            cf.isSuperclass("java.util.ArrayList")) {                            if (stname == null && aname == null) {                                aname = "add";                            }                            if (iname == null && lname == null) {                                lname = "get";                                szname = "size";                            }                        } else if (cf.isImplements("Ljava/util/Collection;")) {                            if (stname == null && aname == null) {                                aname = "add";                            }                            if (iname == null && lname == null) {                                iname = "iterator";                            }                        } else if (cf.isArray()) {                            String ptype = prop.getTypeName();                            itype = ptype.substring(0, ptype.length()-2);                        }                                                // check binding direction(s)                        BindingDefinition bdef = contain.getBindingRoot();                        boolean isdoub =                            "long".equals(itype) || "double".equals(itype);                        if (bdef.isInput()) {                                                        // define strategy for adding items to collection                            if (aname != null) {                                ClassItem meth = cf.getBestMethod(aname,                                    null, new String[] { itype });                                if (meth == null) {                                    ctx.throwStartTagException                                        ("Add method " + aname +                                        " not found in collection type " +                                        cf.getName());                                }                                boolean hasval =                                    !"void".equals(meth.getTypeName());                                store = new NestedCollection.AddStore(meth,                                    isdoub, hasval);                            } else if (stname != null) {                                ClassItem meth = cf.getBestMethod(stname,                                    null, new String[] { "int", itype });                                if (meth == null) {                                    ctx.throwStartTagException                                        ("Indexed store method " + stname +                                        " not found in collection type " +                                        cf.getName());

⌨️ 快捷键说明

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