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

📄 objectbinding.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*Copyright (c) 2003-2004, 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 org.apache.bcel.Constants;import org.apache.bcel.generic.*;import org.jibx.binding.classes.*;import org.jibx.runtime.JiBXException;import org.jibx.runtime.Utility;/** * Binding modifiers that apply to a class reference. This adds the methods used * for handling binding operations to the object class, then generates calls to * the added methods as this binding definition is used. * * @author Dennis M. Sosnoski * @version 1.0 */public class ObjectBinding extends PassThroughComponentimplements IComponent, IContextObj{    //    // Constants and such related to code generation.        // recognized marshal hook method (pre-get) signatures.    private static final String[] MARSHAL_HOOK_SIGNATURES =    {        "(Lorg/jibx/runtime/IMarshallingContext;)V",        "(Ljava/lang/Object;)V",        "()V"    };        // recognized factory hook method signatures.    private static final String[] FACTORY_HOOK_SIGNATURES =    {        "(Lorg/jibx/runtime/IUnmarshallingContext;)",        "(Ljava/lang/Object;)",        "()"    };        // recognized unmarshal hook method (pre-set, post-set) signatures.    private static final String[] UNMARSHAL_HOOK_SIGNATURES =    {        "(Lorg/jibx/runtime/IUnmarshallingContext;)V",        "(Ljava/lang/Object;)V",        "()V"    };        // definitions used in generating calls to user defined methods    private static final String UNMARSHAL_GETSTACKTOPMETHOD =        "org.jibx.runtime.impl.UnmarshallingContext.getStackTop";    private static final String MARSHAL_GETSTACKTOPMETHOD =        "org.jibx.runtime.impl.MarshallingContext.getStackTop";    private static final String GETSTACKTOP_SIGNATURE =        "()Ljava/lang/Object;";    private static final String MARSHALLING_CONTEXT =        "org.jibx.runtime.impl.MarshallingContext";    private static final String UNMARSHALLING_CONTEXT =        "org.jibx.runtime.impl.UnmarshallingContext";    private static final String UNMARSHAL_PARAMETER_SIGNATURE =        "(Lorg/jibx/runtime/impl/UnmarshallingContext;)";    private static final String UNMARSHAL_PUSHOBJECTMETHOD =        "org.jibx.runtime.impl.UnmarshallingContext.pushObject";    private static final String UNMARSHAL_PUSHTRACKEDOBJECTMETHOD =        "org.jibx.runtime.impl.UnmarshallingContext.pushTrackedObject";    private static final String MARSHAL_PUSHOBJECTMETHOD =        "org.jibx.runtime.impl.MarshallingContext.pushObject";    private static final String PUSHOBJECT_SIGNATURE =        "(Ljava/lang/Object;)V";    private static final String UNMARSHAL_POPOBJECTMETHOD =        "org.jibx.runtime.impl.UnmarshallingContext.popObject";    private static final String MARSHAL_POPOBJECTMETHOD =        "org.jibx.runtime.impl.MarshallingContext.popObject";    private static final String POPOBJECT_SIGNATURE = "()V";        // definitions for methods added to mapped class    private static final String NEWINSTANCE_SUFFIX = "_newinstance";    private static final String UNMARSHAL_ATTR_SUFFIX = "_unmarshalAttr";    private static final String MARSHAL_ATTR_SUFFIX = "_marshalAttr";    private static final String UNMARSHAL_SUFFIX = "_unmarshal";    private static final String MARSHAL_SUFFIX = "_marshal";        // definitions for source position tracking    private static final String SOURCE_TRACKING_INTERFACE =        "org.jibx.runtime.impl.ITrackSourceImpl";    private static final String SETSOURCE_METHODNAME = "jibx_setSource";    private static final Type[] SETSOURCE_ARGS =    {        Type.STRING, Type.INT, Type.INT    };    private static final String SOURCEDOCUMENT_FIELDNAME ="jibx_sourceDocument";    private static final String SOURCELINE_FIELDNAME = "jibx_sourceLine";    private static final String SOURCECOLUMN_FIELDNAME = "jibx_sourceColumn";    private static final String SOURCENAME_METHODNAME = "jibx_getDocumentName";    private static final String SOURCELINE_METHODNAME = "jibx_getLineNumber";    private static final String SOURCECOLUMN_METHODNAME =         "jibx_getColumnNumber";    private static final Type[] EMPTY_ARGS = {};    //    // Actual instance data.    /** Containing binding definition structure. */    private final IContainer m_container;        /** Class linked to mapping. */    private BoundClass m_class;    /** Object factory method. */    private final ClassItem m_factoryMethod;    /** Preset method for object. */    private final ClassItem m_preSetMethod;    /** Postset method for object. */    private final ClassItem m_postSetMethod;    /** Preget method for object. */    private final ClassItem m_preGetMethod;        /** Type to be used for creating new instances. */    private final ClassFile m_createClass;        /** Generated new instance method. */    private ClassItem m_newInstanceMethod;        /** Flag for recursion while generating attribute unmarshal. */    private boolean m_lockAttributeUnmarshal;        /** Flag for recursion while generating attribute marshal. */    private boolean m_lockAttributeMarshal;        /** Flag for recursion while generating attribute unmarshal. */    private boolean m_lockContentUnmarshal;        /** Flag for recursion while generating attribute marshal. */    private boolean m_lockContentMarshal;        /** Signature used for unmarshal methods. */    private String m_unmarshalSignature;        /** Name for unmarshal attribute method (<code>null</code> unless     generation started). */    private String m_unmarshalAttributeName;        /** Name for  unmarshal content method (<code>null</code> unless     generation started). */    private String m_unmarshalContentName;        /** Flag for static unmarshal methods. */    private boolean m_isStaticUnmarshal;        /** Flag for static marshal methods. */    private boolean m_isStaticMarshal;        /** Signature used for marshal methods. */    private String m_marshalSignature;        /** Name for  marshal attribute method (<code>null</code> unless     generation started). */    private String m_marshalAttributeName;        /** Name for  marshal content method (<code>null</code> unless     generation istarted). */    private String m_marshalContentName;        /** Generated unmarshal attribute method. */    private ClassItem m_unmarshalAttributeMethod;        /** Generated unmarshal content method. */    private ClassItem m_unmarshalContentMethod;        /** Generated marshal attribute method. */    private ClassItem m_marshalAttributeMethod;        /** Generated marshal content method. */    private ClassItem m_marshalContentMethod;        /** Child supplying instance identifier value. */    private IComponent m_idChild;        /** Flag for "this" reference, meaning that there's no separate object     * instance created. */    private boolean m_isThisBinding;    /**     * Constructor. This initializes the definition context to be the same as     * the parent's. Subclasses may change this definition context if     * appropriate.     *     * @param contain containing binding definition component     * @param objc current object context     * @param type fully qualified class name for bound object     * @param fact user new instance factory method     * @param pres user preset method for unmarshalling     * @param posts user postset method for unmarshalling     * @param pget user preget method for marshalling     * @param ctype type to use for creating new instance (<code>null</code> if     * not specified)     * @throws JiBXException if method not found     */    public ObjectBinding(IContainer contain, IContextObj objc, String type,        String fact, String pres, String posts, String pget, String ctype)        throws JiBXException {                // initialize the basics        m_container = contain;        BoundClass ctxc = (objc == null) ? null : objc.getBoundClass();        m_class = BoundClass.getInstance(type, ctxc);        ClassFile cf = m_class.getClassFile();        if (ctype == null) {            m_createClass = cf;        } else {            m_createClass = ClassCache.getClassFile(ctype);        }                // check instance creation for unmarshalling        if (fact == null) {            m_factoryMethod = null;        } else {                        // look up supplied static factory method            int split = fact.lastIndexOf('.');            if (split >= 0) {                                // verify the method is defined                String cname = fact.substring(0, split);                String mname = fact.substring(split+1);                ClassFile mcf = ClassCache.getClassFile(cname);                m_factoryMethod = mcf.getMethod(mname,                    FACTORY_HOOK_SIGNATURES);                if (m_factoryMethod == null) {                    throw new JiBXException("Factory method " + fact +                        " not found");                } else {                                        // force access if necessary                    m_factoryMethod.makeAccessible(cf);                                    }            } else {                m_factoryMethod = null;            }            if (m_factoryMethod == null) {                throw new JiBXException("Factory method " + fact +                    " not found.");            }        }                // look up other method names as members of class        if (pres == null) {            m_preSetMethod = null;        } else {            m_preSetMethod = cf.getMethod(pres, UNMARSHAL_HOOK_SIGNATURES);            if (m_preSetMethod == null) {                throw new JiBXException("User method " + pres + " not found.");            }        }        if (posts == null) {            m_postSetMethod = null;        } else {            m_postSetMethod = cf.getMethod(posts, UNMARSHAL_HOOK_SIGNATURES);            if (m_postSetMethod == null) {                throw new JiBXException("User method " + posts + " not found.");            }        }        if (pget == null) {            m_preGetMethod = null;        } else {            m_preGetMethod = cf.getMethod(pget, MARSHAL_HOOK_SIGNATURES);            if (m_preGetMethod == null) {                throw new JiBXException("User method " + pget + " not found.");            }        }    }        /**     * Abstract binding copy constructor. This is used to create a variation of     * the object binding for a mapping which will be used for "this"     * references. The "this" reference handling differs only in the code     * generation, where it skips adding the source tracking interfaces and     * does not push an instance of the object on the marshalling or     * unmarshalling stack (since the object will already be there). This method     * is only to be used before code generation.     *      * @param base original object binding     */    public ObjectBinding(ObjectBinding base) {        m_container = base.m_container;        m_class = base.m_class;        m_factoryMethod = null;        m_preSetMethod = base.m_preSetMethod;        m_postSetMethod = base.m_postSetMethod;        m_preGetMethod = base.m_preGetMethod;        m_createClass = base.m_createClass;        m_idChild = base.m_idChild;        m_component = base.m_component;        m_isThisBinding = true;    }        /**     * Copy constructor. This is used in handling abstract mappings, where the     * properties of the mapping definition object binding need to be copied for

⌨️ 快捷键说明

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