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

📄 mappingdefinition.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*Copyright (c) 2003-2007, Dennis M. SosnoskiAll rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this   list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,   this list of conditions and the following disclaimer in the documentation   and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used   to endorse or promote products derived from this software without specific   prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/package org.jibx.binding.def;import java.util.ArrayList;import org.apache.bcel.Constants;import org.apache.bcel.generic.*;import org.jibx.binding.classes.*;import org.jibx.runtime.JiBXException;/** * Normal mapping with defined binding. This is used for a mapping definition * which includes detailed binding information (rather than marshaller and * unmarshaller classes which handle the binding directly). * * @author Dennis M. Sosnoski */public class MappingDefinition extends MappingBase{    //    // Constants and such related to code generation.        // definitions used in generating the adapter class    private static final String ADAPTERCLASS_SUFFIX = "_access";    private static final String MARSHAL_METHODNAME = "marshal";    private static final String BASEMARSHAL_METHODNAME = "baseMarshal";    private static final String UNMARSHAL_METHODNAME = "unmarshal";    private static final String ISPRESENT_METHODNAME = "isPresent";    private static final String UNMARSHALCONTEXT_CLASS =        "org.jibx.runtime.impl.UnmarshallingContext";    private static final String MARSHALCONTEXT_CLASS =        "org.jibx.runtime.impl.MarshallingContext";    private static final String UNMARSHAL_ISATMETHOD =        "org.jibx.runtime.IUnmarshallingContext.isAt";    private static final String UNMARSHAL_ISATSIGNATURE =        "(Ljava/lang/String;Ljava/lang/String;)Z";    private static final String CHECKEXTENDS_METHOD =        "org.jibx.runtime.IMarshaller.isExtension";    private static final String GETINDEX_METHOD =        "org.jibx.runtime.IMarshallable.JiBX_getIndex";    private static final String UNMARSHALLERPRESENT_METHOD =        "org.jibx.runtime.IUnmarshaller.isPresent";    private static final String UNMARSHALLERPRESENT_SIGNATURE =        "(Lorg/jibx/runtime/IUnmarshallingContext;)Z";    private static final String UNMARSHALCONTEXT_INTERFACE =        "org.jibx.runtime.IUnmarshallingContext";    private static final String MARSHALCONTEXT_INTERFACE =        "org.jibx.runtime.IMarshallingContext";    private static final String CURRENTELEMENT_METHOD =        "org.jibx.runtime.impl.UnmarshallingContext.currentNameString";    private static final String CURRENTELEMENT_SIGNATURE =        "()Ljava/lang/String;";    private static final String PARSERNEXT_METHOD =        "org.jibx.runtime.impl.UnmarshallingContext.next";    private static final String PARSERNEXT_SIGNATURE = "()I";    private static final String CLOSESTART_METHOD =        "org.jibx.runtime.impl.MarshallingContext.closeStartContent";    private static final String CLOSESTART_SIGNATURE =        "()Lorg/jibx/runtime/impl/MarshallingContext;";    private static final String ADDUNMARSHALLER_METHOD =        "org.jibx.runtime.impl.UnmarshallingContext.addUnmarshalling";    private static final String ADDUNMARSHALLER_SIGNATURE =        "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V";    private static final String REMOVEUNMARSHALLER_METHOD =        "org.jibx.runtime.impl.UnmarshallingContext.removeUnmarshalling";    private static final String REMOVEUNMARSHALLER_SIGNATURE = "(I)V";    private static final String ADDMARSHALLER_METHOD =        "org.jibx.runtime.impl.MarshallingContext.addMarshalling";    private static final String ADDMARSHALLER_SIGNATURE =        "(ILjava/lang/String;)V";    private static final String REMOVEMARSHALLER_METHOD =        "org.jibx.runtime.impl.MarshallingContext.removeMarshalling";    private static final String REMOVEMARSHALLER_SIGNATURE = "(I)V";        // argument list for the unmarshaller methods    private static final Type[] ISPRESENT_METHOD_ARGS =    {        ClassItem.typeFromName("org.jibx.runtime.IUnmarshallingContext")    };    private static final Type[] UNMARSHAL_METHOD_ARGS =    {        Type.OBJECT,        ClassItem.typeFromName("org.jibx.runtime.IUnmarshallingContext")    };        // argument list for the marshaller methods    private static final Type[] MARSHAL_METHOD_ARGS =    {        Type.OBJECT,        ClassItem.typeFromName("org.jibx.runtime.IMarshallingContext")    };        //    // Data shared with other classes within package        // interface list for adapter with unmarshaller only    /*package*/ static final String[] UNMARSHALLER_INTERFACES =    {        UNMARSHALLER_INTERFACE    };        // interface list for adapter with marshaller only    /*package*/ static final String[] MARSHALLER_INTERFACES =    {        MARSHALLER_INTERFACE    };        // interface list for adapter with both unmarshaller and marshaller    /*package*/ static final String[] BOTH_INTERFACES =    {        UNMARSHALLER_INTERFACE, MARSHALLER_INTERFACE    };        //    // Actual instance data.        /** Containing binding definition structure. */    private final IContainer m_container;        /** Definition context for mapping. */    private final DefinitionContext m_defContext;        /** Class linked to mapping. */    private final BoundClass m_class;    /** Mapped element name (may be <code>null</code> if element(s) defined     by marshaller and unmarshaller, or if abstract mapping). */    private final NameDefinition m_name;        /** Abstract mapping flag. */    private final boolean m_isAbstract;        /** Name of abstract base type. */    private final String m_baseType;        /** Abstract binding this one is based on (<code>null</code> if not an     extension. */    private IMapping m_baseMapping;        /** Duplicate of component structure for use as "this" reference     * (<code>null</code> if not yet defined). */    private IComponent m_thisBinding;        /** Constructed marshaller class. */    private ClassFile m_marshaller;    /** Constructed unmarshaller class. */    private ClassFile m_unmarshaller;        /** Mapping which extend this one (<code>null</code> if none). */    private ArrayList m_extensions;        /** Reference type of mapping, as fully qualifed class name. */    private String m_referenceType;    /**     * Constructor. This initializes the new definition context.     *     * @param contain containing binding definition structure     * @param defc definition context for this mapping     * @param type bound class name     * @param name mapped element name information (<code>null</code> if defined     * by marshaller and unmarshaller)     * @param tname qualified type name for abstract mapping (<code>null</code>     * if none)     * @param abs abstract mapping flag     * @param base abstract mapping extended by this one     * @param bind binding definition component     * @param nillable flag for nillable element     * @throws JiBXException if class definition not found     */    public MappingDefinition(IContainer contain, DefinitionContext defc,        String type, NameDefinition name, String tname, boolean abs,        String base, ObjectBinding bind, boolean nillable) throws JiBXException {        super(contain, type, tname);        IComponent tref = new ObjectBinding(bind);        if (name == null) {            setWrappedComponent(bind);        } else {            setWrappedComponent(new ElementWrapper(defc, name, bind, nillable));            tref = new ElementWrapper(defc, name, tref, nillable);        }        m_thisBinding = tref;        m_container = contain;        m_defContext = defc;        m_class = BoundClass.getInstance(type, null);        m_referenceType = type == null ? "java.lang.Object" : type;        m_name = name;        m_isAbstract = abs;        m_baseType = base;    }    /**     * Check if one or more namespaces are defined for element.     *     * @return <code>true</code> if namespaces are defined, <code>false</code>     * if not     */    /*package*/ boolean hasNamespace() {        return m_defContext.hasNamespace();    }    /**     * Generate code for loading namespace index and URI arrays.     *     * @param mb method builder for generated code     */    /*package*/ void genLoadNamespaces(MethodBuilder mb) {        m_defContext.genLoadNamespaces(mb);    }    /**     * Get the mapped class information. This implements the method used by the     * base class.     *     * @return information for mapped class     */    public BoundClass getBoundClass() {        return m_class;    }        /**     * Links extension mappings to their base mappings. This must be done before     * the more general linking step in order to determine which abstract     * mappings are standalone and which are extended by other mappings     *     * @throws JiBXException if error in linking     */    public void linkMappings() throws JiBXException {        if (m_baseType != null) {            m_baseMapping = m_defContext.getClassMapping(m_baseType);            if (m_baseMapping == null) {                throw new JiBXException("Mapping for base class " + m_baseType +                    " not defined");            }            m_baseMapping.addExtension(this);        }        m_defContext.linkMappings();    }        //    // IMapping interface method definitions        public String getBoundType() {        return m_class.getClassName();    }        public String getReferenceType() {        return m_referenceType;    }        public IComponent getImplComponent() {        return m_component;    }        public ClassFile getMarshaller() {        return m_marshaller;    }        public ClassFile getUnmarshaller() {        return m_unmarshaller;    }        public NameDefinition getName() {        return m_name;    }    public void addNamespace(NamespaceDefinition ns) throws JiBXException {        m_defContext.addNamespace(ns);    }    public boolean isAbstract() {        return m_isAbstract;    }    public boolean isBase() {

⌨️ 快捷键说明

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