📄 elementwrapper.java
字号:
boolean attr = m_component != null && m_component.hasAttribute(); boolean cont = m_component != null && m_component.hasContent(); // load the unmarshalling context followed by the namespace URI and // element name. mb.loadContext(UNMARSHALLING_CONTEXT); m_name.genPushUriPair(mb); // check type of unmarshalling behavior required if (attr) { // unmarshal start tag with attribute(s) mb.appendCallVirtual(UNMARSHAL_PARSESTARTATTRIBUTES, UNMARSHAL_PARSESTARTSIGNATURE); m_component.genAttributeUnmarshal(mb); // generate code to parse past the start tag with another call // to unmarshalling context mb.loadContext(UNMARSHALLING_CONTEXT); m_name.genPushUriPair(mb); mb.appendCallVirtual(UNMARSHAL_PARSEPASTSTART, UNMARSHAL_PARSESTARTSIGNATURE); } else if (cont) { // unmarshal start tag without attributes mb.appendCallVirtual(UNMARSHAL_PARSESTARTNOATTRIBUTES, UNMARSHAL_PARSESTARTSIGNATURE); } else { // unmarshal element discarding all content mb.appendCallVirtual(UNMARSHAL_SKIPELEMENTMETHOD, UNMARSHAL_SKIPELEMENTSIGNATURE); } // unmarshal child content if (cont) { m_component.genContentUnmarshal(mb); } // next add code to push context, namespace and name, and call // method to parse past end tag if (attr || cont) { mb.loadContext(UNMARSHALLING_CONTEXT); m_name.genPushUriPair(mb); mb.appendCallVirtual(UNMARSHAL_PARSEENDMETHOD, UNMARSHAL_PARSEENDSIGNATURE); } // check if need code to handle missing or nil element if (ifmiss != null || ifnil != null) { // handle branch conditions, jumping around code to set null BranchWrapper toend = mb.appendUnconditionalBranch(this); mb.targetNext(ifmiss); mb.targetNext(ifnil); // generate code to store null to property if (m_component instanceof ComponentProperty) { PropertyDefinition prop = ((ComponentProperty)m_component).getProperty(); if (!prop.isImplicit()) { mb.loadObject(); mb.appendACONST_NULL(); prop.genStore(mb); } else { mb.appendACONST_NULL(); } } else { mb.appendPOP(); mb.appendACONST_NULL(); } mb.targetNext(toend); } } public void genContentMarshal(ContextMethodBuilder mb) throws JiBXException { // nothing to be done if optional ignored element if (!m_optionalIgnored) { BranchWrapper ifmiss = null; if (m_isNillable) { // check for null object BranchWrapper ifhit; if (m_directAccess || !(m_component instanceof ComponentProperty)) { mb.appendDUP(); ifhit = mb.appendIFNONNULL(this); mb.appendPOP(); } else { PropertyDefinition prop = ((ComponentProperty)m_component).getProperty(); mb.loadObject(); prop.genLoad(mb); ifhit = mb.appendIFNONNULL(this); } // generate empty element with xsi:nil="true" mb.loadContext(MARSHALLING_CONTEXT); m_name.genPushIndexPair(mb); mb.appendCallVirtual(MARSHAL_STARTTAG_ATTRIBUTES, MARSHAL_STARTTAG_SIGNATURE); mb.appendLoadConstant(2); mb.appendLoadConstant("nil"); mb.appendLoadConstant("true"); mb.appendCallVirtual(MARSHAL_ATTRIBUTE, MARSHAL_SIGNATURE); mb.appendCallVirtual(MARSHAL_CLOSESTART_EMPTY, MARSHAL_CLOSESTART_EMPTY_SIGNATURE); mb.appendPOP(); ifmiss = mb.appendUnconditionalBranch(this); mb.targetNext(ifhit); } // set up flags for controlling code generation paths boolean attr = m_component != null && m_component.hasAttribute(); boolean cont = m_component != null && m_component.hasContent(); boolean needns = !m_structureObject && m_defContext.hasNamespace(); // duplicate object reference on stack if both attribute(s) and // content if (attr && cont) { mb.appendDUP(); } // load the context followed by namespace index and element name mb.loadContext(MARSHALLING_CONTEXT); m_name.genPushIndexPair(mb); // check type of marshalling behavior required if (attr || needns) { // check for namespace definition required if (needns) { // marshal start tag with namespace(s) m_defContext.genLoadNamespaces(mb); mb.appendCallVirtual(MARSHAL_WRITESTARTNAMESPACES, MARSHAL_STARTNAMESPACESSIGNATURE); } else { // marshal start tag with attribute(s) mb.appendCallVirtual(MARSHAL_WRITESTARTATTRIBUTES, MARSHAL_WRITESTARTSIGNATURE); } // handle attributes other than namespace declarations if (attr) { // discard marshalling context from stack mb.appendPOP(); m_component.genAttributeMarshal(mb); mb.loadContext(MARSHALLING_CONTEXT); } // generate code to close the start tag with another call // to marshalling context if (cont) { mb.appendCallVirtual(MARSHAL_CLOSESTARTCONTENT, MARSHAL_CLOSESTARTSIGNATURE); } else { mb.appendCallVirtual(MARSHAL_CLOSESTARTEMPTY, MARSHAL_CLOSESTARTSIGNATURE); } } else if (cont) { // marshal start tag without attributes mb.appendCallVirtual(MARSHAL_WRITESTARTNOATTRIBUTES, MARSHAL_WRITESTARTSIGNATURE); } else { // marshal empty tag mb.appendCallVirtual(MARSHAL_WRITESTARTATTRIBUTES, MARSHAL_WRITESTARTSIGNATURE); mb.appendCallVirtual(MARSHAL_CLOSESTARTEMPTY, MARSHAL_CLOSESTARTSIGNATURE); } // handle child content if present if (cont) { mb.appendPOP(); m_component.genContentMarshal(mb); mb.loadContext(MARSHALLING_CONTEXT); m_name.genPushIndexPair(mb); mb.appendCallVirtual(MARSHAL_WRITEENDMETHOD, MARSHAL_WRITEENDSIGNATURE); } mb.appendPOP(); mb.targetNext(ifmiss); } } public void genNewInstance(ContextMethodBuilder mb) throws JiBXException { if (m_component == null) { throw new IllegalStateException ("Internal error - no wrapped component"); } else { m_component.genNewInstance(mb); } } public String getType() { if (m_component == null) { throw new IllegalStateException ("Internal error - no wrapped component"); } else { return m_component.getType(); } } public boolean hasId() { if (m_component == null) { return false; } else { return m_component.hasId(); } } public void genLoadId(ContextMethodBuilder mb) throws JiBXException { if (m_component == null) { throw new IllegalStateException ("Internal error - no wrapped component"); } else { m_component.genLoadId(mb); } } public NameDefinition getWrapperName() { return m_name; } public void setLinkages() throws JiBXException { m_name.fixNamespace(m_defContext); if (m_component != null) { m_component.setLinkages(); } } // DEBUG public void print(int depth) { BindingDefinition.indent(depth); System.out.println(toString()); if (m_component != null) { m_component.print(depth+1); } } public String toString() { StringBuffer buff = new StringBuffer("element wrapper"); if (m_name != null) { buff.append(' '); buff.append(m_name.toString()); } if (m_directAccess) { buff.append(" direct"); } if (m_optionalIgnored) { buff.append(" optional ignored"); } if (m_optionalNormal) { buff.append(" optional"); } if (m_structureObject) { buff.append(" structure object"); } return buff.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -