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

📄 bindingbuilder.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    {        DIRECTION_BOTH,        DIRECTION_INPUT,        DIRECTION_OUTPUT    };        //    // Constants for property usage values    private static final String USAGE_OPTIONAL = "optional";    private static final String USAGE_REQUIRED = "required";        //    // Checking and code generation constants        private static final String UNMARSHALLER_INTERFACE =        "org.jibx.runtime.IUnmarshaller";    private static final String MARSHALLER_INTERFACE =        "org.jibx.runtime.IMarshaller";    private static final String UNMARSHALLER_INTERFACETYPE =        "Lorg/jibx/runtime/IUnmarshaller;";    private static final String MARSHALLER_INTERFACETYPE =        "Lorg/jibx/runtime/IMarshaller;";    /**     * Check if attributes supply a name definition.     *     * @param ctx unmarshalling context information     * @return <code>true</code> if attributes define a name,     * <code>false</code> if not     */    private static boolean isNamePresent(UnmarshallingContext ctx) {        return ctx.attributeText(URI_ATTRIBUTES, COMMON_NAME, null) != null;    }    /**     * Check for property definition present. Just checks the attributes of     * the current element.     *     * @param ctx unmarshalling context information     */    private static boolean isPropertyPresent(UnmarshallingContext ctx) {        return ctx.attributeText(URI_ATTRIBUTES, COMMON_FIELD, null) != null ||            ctx.attributeText(URI_ATTRIBUTES, COMMON_GETMETHOD, null) != null ||            ctx.attributeText(URI_ATTRIBUTES, COMMON_SETMETHOD, null) != null ||            ctx.attributeText(URI_ATTRIBUTES, COMMON_TESTMETHOD, null) != null;    }    /**     * Check if attributes define a direct object reference. Just checks the     * attributes of the current element.     *     * @param ctx unmarshalling context information     */    private static boolean isDirectObject(UnmarshallingContext ctx) {        return ctx.attributeText(URI_ATTRIBUTES,            COMMON_MARSHALLER, null) != null ||            ctx.attributeText(URI_ATTRIBUTES,            COMMON_UNMARSHALLER, null) != null;    }    /**     * Check if attributes define a mapping reference.     *     * @param ctx unmarshalling context information     * @return <code>true</code> if attributes define a mapping reference,     * <code>false</code> if not     * @throws JiBXException if error in unmarshalling     */        private static boolean isMappingRef(UnmarshallingContext ctx)        throws JiBXException {        return ctx.hasAttribute(URI_ATTRIBUTES, STRUCTURE_MAPAS);    }    /**     * Check for component object present. Just checks the attributes of the     * current element, so this is not definitive - there may still be child     * binding definitions even without attributes.     *     * @param ctx unmarshalling context information     * @throws JiBXException if error in unmarshalling     */    private static boolean isObjectBinding(UnmarshallingContext ctx)        throws JiBXException {        return ctx.hasAnyAttribute(COMPONENT_OBJECT_NAMESPACES,            COMPONENT_OBJECT_NAMES);    }    /**     * Unmarshal name definition. This unmarshals directly from attributes of     * the current element.     *     * @param ctx unmarshalling context information     * @param attr flag for attribute name definition     * @throws JiBXException if error in unmarshalling     */    private static NameDefinition unmarshalName(UnmarshallingContext ctx,        boolean attr) throws JiBXException {        String name = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAME);        String ns = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAMESPACE, null);        return new NameDefinition(name, ns, attr);    }    /**     * Unmarshal namespace definition.     *     * @param ctx unmarshalling context information     * @throws JiBXException if error in unmarshalling     */    private static NamespaceDefinition unmarshalNamespace        (UnmarshallingContext ctx) throws JiBXException {                // set up the basic information        String uri = ctx.attributeText(URI_ATTRIBUTES, NAMESPACE_URI);        String prefix = ctx.attributeText(URI_ATTRIBUTES,            NAMESPACE_PREFIX, null);        if ("".equals(prefix)) {            prefix = null;        }                // check default usage attribute        int usage =  ctx.attributeEnumeration(URI_ATTRIBUTES, NAMESPACE_DEFAULT,            NAMESPACEACCESS_NAMES, NAMESPACEACCESS_NUMS,            NamespaceDefinition.NODEFAULT_USAGE);                // finish parsing the element        ctx.parsePastEndTag(URI_ELEMENTS, NAMESPACE_ELEMENT);        return new NamespaceDefinition(uri, prefix, usage);    }    /**     * Unmarshal string conversion. Unmarshals conversion information directly     * from the attributes of the current start tag.     *     * @param ctx unmarshalling context information     * @param base conversion used as base for this conversion     * @param type fully qualified class name of type handled by conversion     * @throws JiBXException if error in unmarshalling     */    private static StringConversion unmarshalStringConversion        (UnmarshallingContext ctx, StringConversion base, String type)        throws JiBXException {        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);        return base.derive(type, ser, dser, dflt);    }    /**     * Check for optional property. Just checks for the attribute and makes sure     * it has a valid value if present, returning either the default or the     * defined value.     *     * @param ctx unmarshalling context information     * @return <code>true</code> if attribute present with value "true",     * <code>false</code> otherwise     * @throws JiBXException if error in unmarshalling     */    private static boolean isOptionalProperty(UnmarshallingContext ctx)        throws JiBXException {        boolean opt = false;        String value = ctx.attributeText(URI_ATTRIBUTES, COMMON_USAGE,            USAGE_REQUIRED);        if (USAGE_OPTIONAL.equals(value)) {            opt = true;        } else if (!USAGE_REQUIRED.equals(value)) {            ctx.throwStartTagException("Illegal value for \"" + COMMON_USAGE+                "\" attribute");        }        return opt;    }    /**     * Unmarshal property definition. This unmarshals directly from attributes     * of the current element.     *     * @param ctx unmarshalling context information     * @param parent containing binding definition structure     * @param cobj context object information     * @param opt force optional value flag     * @throws JiBXException if error in unmarshalling     */    private static PropertyDefinition unmarshalProperty        (UnmarshallingContext ctx, IContainer parent, IContextObj cobj,        boolean opt) throws JiBXException {        // read basic attribute values for property definition        String type = ctx.attributeText(URI_ATTRIBUTES, COMMON_TYPE, null);        if (!(parent instanceof NestedCollection) && isOptionalProperty(ctx)) {            opt = true;        }        // read and validate method and/or field attribute values        PropertyDefinition pdef = null;        try {            String fname = ctx.attributeText(URI_ATTRIBUTES,                COMMON_FIELD, null);            String test = ctx.attributeText(URI_ATTRIBUTES,                COMMON_TESTMETHOD, null);            String get = ctx.attributeText(URI_ATTRIBUTES,                COMMON_GETMETHOD, null);            String set = ctx.attributeText(URI_ATTRIBUTES,                COMMON_SETMETHOD, null);            boolean isthis = fname == null && get == null && set == null;            pdef = new PropertyDefinition                (parent, cobj, type, isthis, opt, fname, test, get, set);                    } catch (JiBXException ex) {            // rethrow error message with position information            ctx.throwStartTagException(ex.getMessage());        }        return pdef;    }    /**     * Unmarshal value definition. This handles the complete element supplying     * the value binding.     *     * @param ctx unmarshalling context information     * @param parent containing binding definition structure     * @param cobj context object information     * @param uord unordered collection member flag     * @param impl implicit value from collection flag     * @param itype base type for value     * @throws JiBXException if error in unmarshalling     */    private static ValueChild unmarshalValue(UnmarshallingContext ctx,        IContainer parent, IContextObj cobj, boolean uord, boolean impl,        String itype) throws JiBXException {                // find the style for this value        int style = ctx.attributeEnumeration(URI_ATTRIBUTES, VALUE_STYLE,            VALUE_STYLE_NAMES, VALUE_STYLE_NUMS, parent.getStyleDefault());                    // set up the basic structures        boolean isatt = style == ValueChild.ATTRIBUTE_STYLE;        NameDefinition name = null;        if (isatt || style == ValueChild.ELEMENT_STYLE) {            name = unmarshalName(ctx, isatt);            name.fixNamespace(parent.getDefinitionContext());        } else if (isNamePresent(ctx)) {            ctx.throwStartTagException                ("Name not allowed for text or CDATA value");        }        String constant = ctx.attributeText(URI_ATTRIBUTES,            VALUE_CONSTANT, null);                // handle property information (unless auto ident or implicit value)        int ident =  ctx.attributeEnumeration(URI_ATTRIBUTES, VALUE_IDENT,            IDENTTYPE_NAMES, IDENTTYPE_NUMS, ValueChild.DIRECT_IDENT);        PropertyDefinition prop = null;        if (ident == ValueChild.AUTO_IDENT) {            ctx.throwStartTagException                ("Automatic id generation not yet supported");        } else if (impl) {            String type = ctx.attributeText(URI_ATTRIBUTES, COMMON_TYPE, itype);            prop = new PropertyDefinition(type, cobj,                !(parent instanceof NestedCollection) && isOptionalProperty(ctx));        } else {            prop = unmarshalProperty(ctx, parent, cobj,                ctx.hasAttribute(URI_ATTRIBUTES, COMMON_DEFAULT));/*            if (constant == null && prop.isThis()) {                ctx.throwStartTagException("No property for value");            } else if (prop.isOptional()) {                if (ident == ValueChild.DEF_IDENT) {                    ctx.throwStartTagException("Object ID cannot be optional");                }            } else if (uord) {                ctx.throwStartTagException("All items in unordered " +                    "structure must be optional");            }   */        }        if (ident != ValueChild.DIRECT_IDENT && uord) {            ctx.throwStartTagException(VALUE_IDENT +                " not allowed in unordered structure");        }                // find the basic converter to use        StringConversion convert = null;        String type = (prop == null || constant != null) ?            "java.lang.String" : prop.getTypeName();        String format = ctx.attributeText(URI_ATTRIBUTES, VALUE_FORMAT, null);        DefinitionContext defc = parent.getDefinitionContext();        if (format == null) {                        // no format name, get specific convertor for type or best match            convert = defc.getSpecificConversion(type);

⌨️ 快捷键说明

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