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

📄 bindingbuilder.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (convert == null) {                                // find best match converter for type                ClassFile target = ClassCache.getClassFile(type);                convert = defc.getConversion(target);                                // check for a Java 5 enumeration                boolean isenum = false;                ClassFile sclas = target;                while ((sclas = sclas.getSuperFile()) != null) {                    if (sclas.getName().equals("java.lang.Enum")) {                        isenum = true;                        break;                    }                }                                // generate specific converter based on general form                if (isenum) {                    String dser = type + '.' + "valueOf";                    convert = convert.derive(type, null, dser, null);                } else if (convert.getTypeName().equals("java.lang.Object")) {                    convert = new ObjectStringConversion(type,                        (ObjectStringConversion)convert);                }            }                    } else {                        // format name supplied, look it up and check compatibility            QName qname = QName.deserialize(format, ctx);            convert = defc.getNamedConversion(qname);            if (convert == null) {                ctx.throwStartTagException                    ("Unknown format \"" + format + "\"");            }            String ctype = convert.getTypeName();            if (!ClassItem.isAssignable(type, ctype) &&                !ClassItem.isAssignable(ctype, type)) {                ctx.throwStartTagException                    ("Converter type not compatible with value type");            }        }                // check for any special conversion handling        String dflt = ctx.attributeText(URI_ATTRIBUTES, COMMON_DEFAULT, null);        String ser = ctx.attributeText(URI_ATTRIBUTES, COMMON_SERIALIZER, null);        String dser = ctx.attributeText(URI_ATTRIBUTES,             COMMON_DESERIALIZER, null);        if (dflt != null || ser != null || dser != null) {            convert = convert.derive(type, ser, dser, dflt);        }                // create the instance to be returned        boolean nillable = ctx.attributeBoolean(URI_ATTRIBUTES,            COMMON_NILLABLE, false);        if (nillable) {            parent.getBindingRoot().setSchemaInstanceUsed();        }        ValueChild value = new ValueChild(parent, cobj, name, prop, convert,            style, ident, constant, nillable);                // handle identifier property flag        if (ident == ValueChild.DEF_IDENT || ident == ValueChild.AUTO_IDENT) {            if (!cobj.setIdChild(value)) {                ctx.throwStartTagException                    ("Duplicate ID definition for containing mapping");            } else if (!"java.lang.String".equals(type)) {                ctx.throwStartTagException                    ("ID property must be a String");            }        }                // finish with skipping past end tag        ctx.parsePastEndTag(URI_ELEMENTS, VALUE_ELEMENT);        return value;    }    /**     * Unmarshal direct object component. Just constructs the component to     * be returned along with the supporting objects, and verifies that no     * disallowed properties are present.     *     * @param ctx unmarshalling context information     * @param type fully qualified class name of object type handled     * @param parent containing binding definition structure     * @param defc definition context to be used (if separate from parent,     * otherwise <code>null</code>)     * @param slot marshaller/unmarshaller slot number     * @param name element name information (<code>null</code> if no element     * name)     * @return constructed direct object component     * @throws JiBXException if error in unmarshalling     */        private static DirectObject unmarshalDirectObj(UnmarshallingContext ctx,        String type, IContainer parent, DefinitionContext defc, int slot,        NameDefinition name) throws JiBXException {                // define and validate marshaller        ClassFile mcf = null;        if (parent.getBindingRoot().isOutput()) {            String clas = ctx.attributeText(URI_ATTRIBUTES, COMMON_MARSHALLER);            mcf = ClassCache.getClassFile(clas);            if (!mcf.isImplements(MARSHALLER_INTERFACETYPE)) {                ctx.throwStartTagException("Marshaller class " + clas +                    " does not implement required interface " +                    MARSHALLER_INTERFACE);            }        }                // define and validate unmarshaller        ClassFile ucf = null;        if (parent.getBindingRoot().isInput()) {            String clas = ctx.attributeText(URI_ATTRIBUTES,                COMMON_UNMARSHALLER);            ucf = ClassCache.getClassFile(clas);            if (!ucf.isImplements(UNMARSHALLER_INTERFACETYPE)) {                ctx.throwStartTagException("Unmarshaller class " + clas +                    " does not implement required interface " +                    UNMARSHALLER_INTERFACE);            }        }                // make sure none of the prohibited attributes are present        if (isObjectBinding(ctx)) {            ctx.throwStartTagException("Other object attributes not " +                "allowed when using marshaller or unmarshaller");        } else if (isMappingRef(ctx)) {            ctx.throwStartTagException("Mapping not allowed when " +                "using marshaller or unmarshaller");        } else if (ctx.hasAttribute(URI_ATTRIBUTES, COMMON_USING)) {            ctx.throwStartTagException(COMMON_USING +                 " attribute not allowed when using marshaller or unmarshaller");        }                // return constructed instance        return new DirectObject(parent, defc,            ClassCache.getClassFile(type), false, mcf, ucf, slot, name);    }    /**     * Unmarshal mapping reference component. Just constructs the component to     * be returned along with the supporting objects, and verifies that no     * disallowed properties are present.     *     * @param ctx unmarshalling context information     * @param parent containing binding definition structure     * @param objc current object context     * @param prop property definition     * @param name reference name definition (only allowed with abstract     * mappings)     * @return constructed mapping reference component     * @throws JiBXException if error in unmarshalling     */    private static IComponent unmarshalMappingRef(UnmarshallingContext ctx,        IContainer parent, IContextObj objc, PropertyDefinition prop,        NameDefinition name) throws JiBXException {                // make sure no forbidden attributes are present        if (isObjectBinding(ctx)) {            ctx.throwStartTagException("Other object attributes not " +                "allowed when using mapping reference");        } else if (ctx.hasAttribute(URI_ATTRIBUTES, COMMON_USING)) {            ctx.throwStartTagException(COMMON_USING +                 " attribute not allowed when using mapping reference");        }                // build the actual component to be returned        String type = (prop == null) ? null : prop.getTypeName();        String text = ctx.attributeText(URI_ATTRIBUTES, STRUCTURE_MAPAS, type);        QName qname = QName.deserialize(text, ctx);        boolean nillable = ctx.attributeBoolean(URI_ATTRIBUTES,            COMMON_NILLABLE, false);        if (nillable) {            parent.getBindingRoot().setSchemaInstanceUsed();        }        return new MappingReference(parent, prop, type, text, qname.toString(),            objc, name, false, nillable);    }    /**     * Unmarshal structure reference component. Just constructs the component to     * be returned along with the supporting objects, and verifies that no     * disallowed properties are present.     *     * @param ctx unmarshalling context information     * @param contain containing binding component     * @param name element name information (<code>null</code> if no element     * name)     * @param prop property definition (<code>null</code> if no separate     * property)     * @param cobj context object     * @return constructed structure reference component     * @throws JiBXException if error in unmarshalling     */    private static IComponent unmarshalStructureRef(UnmarshallingContext ctx,        IContainer contain, NameDefinition name, PropertyDefinition prop,        IContextObj cobj) throws JiBXException {                // make sure no forbidden attributes are present        if (isObjectBinding(ctx)) {            ctx.throwStartTagException("Other object attributes not " +                "allowed when using structure reference");        }                // build the actual component to be returned        String ident = ctx.attributeText(URI_ATTRIBUTES, COMMON_USING);        IComponent comp = new StructureReference(contain, ident, prop,            name != null, cobj);        if (name != null) {            boolean nillable = ctx.attributeBoolean(URI_ATTRIBUTES,                COMMON_NILLABLE, false);            if (nillable) {                contain.getBindingRoot().setSchemaInstanceUsed();            }            comp = new ElementWrapper(contain.getDefinitionContext(),                name, comp, nillable);            if (prop != null && prop.isOptional()) {                ((ElementWrapper)comp).setOptionalNormal(true);                ((ElementWrapper)comp).setStructureObject(true);                comp = new OptionalStructureWrapper(comp, prop, true);                prop.setOptional(false);            }        }        return comp;    }    /**     * Unmarshal child bindings for a nested structure definition.     *     * @param ctx unmarshalling context information     * @param nest nested structure definition     * @param objc context object definition     * @param impl property value implicit flag     * @param itype item type for child components     * @throws JiBXException if error in unmarshalling     */    private static void unmarshalStructureChildren(UnmarshallingContext ctx,        NestedBase nest, IContextObj objc, boolean impl, String itype)        throws JiBXException {        boolean uord = !nest.isContentOrdered();        while (true) {                        // unmarshal next child binding definition            IComponent comp;            if (ctx.isAt(URI_ELEMENTS, VALUE_ELEMENT)) {                ValueChild child =                    unmarshalValue(ctx, nest, objc, uord, impl, itype);                comp = child;            } else if (ctx.isAt(URI_ELEMENTS, STRUCTURE_ELEMENT)) {                comp = unmarshalStructure(ctx, nest, objc, false, uord, impl);            } else if (ctx.isAt(URI_ELEMENTS, COLLECTION_ELEMENT)) {                comp = unmarshalStructure(ctx, nest, objc, true, uord, impl);            } else {                break;            }                        // add component to structure            nest.addComponent(comp);        }    }    /**     * Unmarshal object binding component. Just constructs the component to     * be returned along with the supporting objects. This handles both the     * unmarshalling of attributes, and of nested binding components.     *     * @param ctx unmarshalling context information     * @param parent containing binding definition structure     * @param objc current object context     * @param type fully qualified name of object class     * @return constructed structure reference component     * @throws JiBXException if error in unmarshalling     */        private static ObjectBinding unmarshalObjectBinding        (UnmarshallingContext ctx, IContextObj objc, IContainer parent,        String type) throws JiBXException {                // set method names from attributes of start tag        String fact = ctx.attributeText(URI_ATTRIBUTES, COMMON_FACTORY, null);        String pres = ctx.attributeText(URI_ATTRIBUTES, COMMON_PRESET, null);        String posts = ctx.attributeText(URI_ATTRIBUTES, COMMON_POSTSET, null);        String preg = ctx.attributeText(URI_ATTRIBUTES, COMMON_PREGET, null);        String ctype = ctx.attributeText(URI_ATTRIBUTES,            COMMON_CREATETYPE, null);        ObjectBinding bind = null;        try {            bind = new ObjectBinding(parent, objc, type, fact, pres,                posts, preg, ctype);        } catch (JiBXException ex) {            ctx.throwStartTagException(ex.getMessage(), ex);        }        return bind;    }    /**     * Unmarshal namespace definitions. Any namespace definitions present are     * unmarshalled and added to the supplied definition context.

⌨️ 快捷键说明

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