📄 elementwrapper.java
字号:
/*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 org.jibx.binding.classes.*;import org.jibx.runtime.JiBXException;/** * Component decorator for element definition. This associates an element name * with a component. * * @author Dennis M. Sosnoski */public class ElementWrapper implements IComponent{ // // Constants and such related to code generation. private static final String UNMARSHAL_PARSESTARTATTRIBUTES = "org.jibx.runtime.impl.UnmarshallingContext.parseToStartTag"; private static final String UNMARSHAL_PARSESTARTNOATTRIBUTES = "org.jibx.runtime.impl.UnmarshallingContext.parsePastStartTag"; private static final String UNMARSHAL_PARSEPASTSTART = "org.jibx.runtime.impl.UnmarshallingContext.parsePastStartTag"; private static final String UNMARSHAL_PARSESTARTSIGNATURE = "(Ljava/lang/String;Ljava/lang/String;)V"; private static final String UNMARSHAL_PARSEENDMETHOD = "org.jibx.runtime.impl.UnmarshallingContext.parsePastCurrentEndTag"; private static final String UNMARSHAL_PARSEENDSIGNATURE = "(Ljava/lang/String;Ljava/lang/String;)V"; 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 UNMARSHAL_SKIPELEMENTMETHOD = "org.jibx.runtime.impl.UnmarshallingContext.parsePastElement"; private static final String UNMARSHAL_SKIPELEMENTSIGNATURE = "(Ljava/lang/String;Ljava/lang/String;)V"; private static final String MARSHAL_WRITESTARTNAMESPACES = "org.jibx.runtime.impl.MarshallingContext.startTagNamespaces"; private static final String MARSHAL_STARTNAMESPACESSIGNATURE = "(ILjava/lang/String;[I[Ljava/lang/String;)" + "Lorg/jibx/runtime/impl/MarshallingContext;"; private static final String MARSHAL_WRITESTARTATTRIBUTES = "org.jibx.runtime.impl.MarshallingContext.startTagAttributes"; private static final String MARSHAL_WRITESTARTNOATTRIBUTES = "org.jibx.runtime.impl.MarshallingContext.startTag"; private static final String MARSHAL_WRITESTARTSIGNATURE = "(ILjava/lang/String;)Lorg/jibx/runtime/impl/MarshallingContext;"; private static final String MARSHAL_CLOSESTARTCONTENT = "org.jibx.runtime.impl.MarshallingContext.closeStartContent"; private static final String MARSHAL_CLOSESTARTEMPTY = "org.jibx.runtime.impl.MarshallingContext.closeStartEmpty"; private static final String MARSHAL_CLOSESTARTSIGNATURE = "()Lorg/jibx/runtime/impl/MarshallingContext;"; private static final String MARSHAL_WRITEENDMETHOD = "org.jibx.runtime.impl.MarshallingContext.endTag"; private static final String MARSHAL_WRITEENDSIGNATURE = "(ILjava/lang/String;)Lorg/jibx/runtime/impl/MarshallingContext;"; private static final String UNMARSHAL_PARSE_TO_START_NAME = "org.jibx.runtime.impl.UnmarshallingContext.parseToStartTag"; private static final String UNMARSHAL_PARSE_TO_START_SIGNATURE = "(Ljava/lang/String;Ljava/lang/String;)V"; protected static final String UNMARSHAL_ATTRIBUTE_BOOLEAN_NAME = "org.jibx.runtime.impl.UnmarshallingContext.attributeBoolean"; protected static final String UNMARSHAL_ATTRIBUTE_BOOLEAN_SIGNATURE = "(Ljava/lang/String;Ljava/lang/String;Z)Z"; private static final String UNMARSHAL_SKIP_NAME = "org.jibx.runtime.impl.UnmarshallingContext.skipElement"; private static final String UNMARSHAL_SKIP_SIGNATURE = "()V"; protected static final String MARSHAL_STARTTAG_ATTRIBUTES = "org.jibx.runtime.impl.MarshallingContext.startTagAttributes"; protected static final String MARSHAL_STARTTAG_SIGNATURE = "(ILjava/lang/String;)Lorg/jibx/runtime/impl/MarshallingContext;"; protected static final String MARSHAL_CLOSESTART_EMPTY = "org.jibx.runtime.impl.MarshallingContext.closeStartEmpty"; protected static final String MARSHAL_CLOSESTART_EMPTY_SIGNATURE = "()Lorg/jibx/runtime/impl/MarshallingContext;"; protected static final String MARSHAL_ATTRIBUTE = "org.jibx.runtime.impl.MarshallingContext.attribute"; protected static final String MARSHAL_SIGNATURE = "(ILjava/lang/String;Ljava/lang/String;)" + "Lorg/jibx/runtime/impl/MarshallingContext;"; private static final String MARSHALLING_CONTEXT = "org.jibx.runtime.impl.MarshallingContext"; private static final String UNMARSHALLING_CONTEXT = "org.jibx.runtime.impl.UnmarshallingContext"; // // Actual instance data. /** Property value binding component. */ private final IComponent m_component; /** Binding definition context. */ private final DefinitionContext m_defContext; /** Element name information. */ private final NameDefinition m_name; /** Flag for nillable element. */ private final boolean m_isNillable; /** Flag for value from collection (TODO: fix this in update). */ private boolean m_directAccess; /** Flag for optional ignored element (TODO: fix this in update). */ private boolean m_optionalIgnored; /** Flag for optional normal element (TODO: fix this in update). */ private boolean m_optionalNormal; /** Flag for optional structure object (TODO: fix this in update). */ private boolean m_structureObject; /** * Constructor. * * @param defc definition context for this component * @param name element name definition * @param wrap wrapped binding component (may be <code>null</code>, in the * case of a throwaway component) * @param nillable flag for nillable element */ public ElementWrapper(DefinitionContext defc, NameDefinition name, IComponent wrap, boolean nillable) { m_defContext = defc; m_name = name; m_component = wrap; m_isNillable = nillable; } /** * Set the direct access flag. This controls a variation in the code * generation to handle values loaded from a collection. * * @param direct <code>true</code> if direct access from collection, * <code>false</code> if not */ public void setDirect(boolean direct) { m_directAccess = direct; } /** * Set flag for an optional ignored element. * * @param opt <code>true</code> if optional ignored element, * <code>false</code> if not */ public void setOptionalIgnored(boolean opt) { m_optionalIgnored = opt; } /** * Set flag for an optional structure object. * * @param opt <code>true</code> if optional structure object, * <code>false</code> if not */ public void setStructureObject(boolean opt) { m_structureObject = opt; } /** * Set flag for an optional normal element. * * @param opt <code>true</code> if optional normal element, * <code>false</code> if not */ public void setOptionalNormal(boolean opt) { m_optionalNormal = opt; } // // IComponent interface method definitions public boolean isOptional() { return m_optionalNormal || m_optionalIgnored; } public boolean hasAttribute() { return false; } public void genAttrPresentTest(ContextMethodBuilder mb) { throw new IllegalStateException ("Internal error - no attributes from child element"); } public void genAttributeUnmarshal(ContextMethodBuilder mb) { throw new IllegalStateException ("Internal error - no attributes from child element"); } public void genAttributeMarshal(ContextMethodBuilder mb) { throw new IllegalStateException ("Internal error - no attributes from child element"); } public boolean hasContent() { return true; } public void genContentPresentTest(ContextMethodBuilder mb) throws JiBXException { // create call to unmarshalling context method with namespace and // name, then return result directly mb.loadContext(); m_name.genPushUriPair(mb); mb.appendCallInterface(UNMARSHAL_ISATMETHOD, UNMARSHAL_ISATSIGNATURE); } public void genContentUnmarshal(ContextMethodBuilder mb) throws JiBXException { // check for optional empty wrapper present BranchWrapper ifmiss = null; if (isOptional()) { genContentPresentTest(mb); ifmiss = mb.appendIFEQ(this); } BranchWrapper ifnil = null; if (m_isNillable) { // make sure we're at the element mb.loadContext(UNMARSHALLING_CONTEXT); m_name.genPushUriPair(mb); mb.appendCallVirtual(UNMARSHAL_PARSE_TO_START_NAME, UNMARSHAL_PARSE_TO_START_SIGNATURE); // check for xsi:nil="true" mb.loadContext(UNMARSHALLING_CONTEXT); mb.appendLoadConstant("http://www.w3.org/2001/XMLSchema-instance"); mb.appendLoadConstant("nil"); mb.appendICONST_0(); mb.appendCallVirtual(UNMARSHAL_ATTRIBUTE_BOOLEAN_NAME, UNMARSHAL_ATTRIBUTE_BOOLEAN_SIGNATURE); BranchWrapper notnil = mb.appendIFEQ(this); // skip past the element before jumping to end mb.loadContext(UNMARSHALLING_CONTEXT); mb.appendCallVirtual(UNMARSHAL_SKIP_NAME, UNMARSHAL_SKIP_SIGNATURE); ifnil = mb.appendUnconditionalBranch(this); mb.targetNext(notnil); } // set up flags for controlling code generation paths
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -