objectbinding.java
来自「对xml很好的java处理引擎,编译中绑定xml」· Java 代码 · 共 992 行 · 第 1/3 页
JAVA
992 行
m_unmarshalAttributeMethod = m_class.getUniqueMethod(meth).getItem(); m_unmarshalAttributeName = fullMethodName(m_unmarshalAttributeMethod); } } else { m_lockAttributeUnmarshal = true; } } // generate code to call created unmarshal method mb.loadContext(UNMARSHALLING_CONTEXT); genUnmarshalCall(m_unmarshalAttributeName, mb); } /** * Generate call to attribute marshal method for object. This convenience * method just generates code to call the generated marshal method added to * the class definition. The code generated prior to this call must have * loaded a reference to the object to be marshalled on the stack. * * @param mb method builder * @throws JiBXException if error in configuration */ private void genMarshalAttributeCall(ContextMethodBuilder mb) throws JiBXException { // check if marshal method needs to be added to class if (m_marshalAttributeMethod == null) { if (m_marshalAttributeName == null) { // set up for constructing new method String name = m_container.getBindingRoot().getPrefix() + MARSHAL_ATTR_SUFFIX; MarshalBuilder meth = new MarshalBuilder(name, m_class.getClassFile(), m_class.getMungedFile()); m_marshalAttributeName = fullMethodName(meth); m_marshalSignature = meth.getSignature(); m_isStaticMarshal = meth.isStaticMethod(); // if preget method supplied add code to call it if (m_preGetMethod != null) { genUserMethodCall(false, m_preGetMethod, meth); } // push object being marshalled to marshaller stack if (!m_isThisBinding) { meth.loadContext(); meth.loadObject(); meth.appendCallVirtual(MARSHAL_PUSHOBJECTMETHOD, PUSHOBJECT_SIGNATURE); } // generate actual marshalling code meth.loadContext(); m_component.genAttributeMarshal(meth); // pop object from stack if (!m_isThisBinding) { meth.loadContext(); meth.appendCallVirtual(MARSHAL_POPOBJECTMETHOD, POPOBJECT_SIGNATURE); } // finish and add constructed method to class meth.appendReturn(); if (m_lockAttributeMarshal) { m_marshalAttributeMethod = m_class.getUniqueNamed(meth).getItem(); } else { m_marshalAttributeMethod = m_class.getUniqueMethod(meth).getItem(); m_marshalAttributeName = fullMethodName(m_marshalAttributeMethod); } } else { m_lockAttributeMarshal = true; } } // generate code to call created marshal method// if (!m_directAccess) { mb.loadContext(MARSHALLING_CONTEXT);// } genMarshalCall(m_marshalAttributeName, mb); } /** * Generate call to content unmarshal method for object. This convenience * method just generates code to call the generated unmarshal method added * to the class definition. The code generated prior to this call must have * loaded a reference to the object to be unmarshalled on the stack, and the * generated code returns the (possibly different, in the case of arrays) * object on the stack. * * @param mb method builder * @throws JiBXException if error in configuration */ private void genUnmarshalContentCall(ContextMethodBuilder mb) throws JiBXException { // check if unmarshal method needs to be added to class if (m_unmarshalContentMethod == null) { if (m_unmarshalContentName == null) { // set up for constructing new method String name = m_container.getBindingRoot().getPrefix() + UNMARSHAL_SUFFIX; UnmarshalBuilder meth = new UnmarshalBuilder(name, m_class.getClassFile(), m_class.getMungedFile()); m_unmarshalContentName = fullMethodName(meth); m_unmarshalSignature = meth.getSignature(); m_isStaticUnmarshal = meth.isStaticMethod(); // if preset method supplied add code to call it if (!hasAttribute() && m_preSetMethod != null) { meth.loadObject(); genUserMethodCall(true, m_preSetMethod, meth); } // push object being unmarshalled to unmarshaller stack if (!m_isThisBinding) { meth.loadContext(); meth.loadObject(); String mname = hasAttribute() ? UNMARSHAL_PUSHOBJECTMETHOD : UNMARSHAL_PUSHTRACKEDOBJECTMETHOD; meth.appendCallVirtual(mname, PUSHOBJECT_SIGNATURE); } // generate the actual unmarshalling code in method meth.loadObject(); m_component.genContentUnmarshal(meth); // pop object from unmarshal stack if (!m_isThisBinding) { meth.loadContext(); meth.appendCallVirtual(UNMARSHAL_POPOBJECTMETHOD, POPOBJECT_SIGNATURE); } // if postset method supplied and no attributes add code to call if (m_postSetMethod != null) { genUserMethodCall(true, m_postSetMethod, meth); } // finish by returning object meth.loadObject(); meth.appendReturn(m_class.getClassFile().getName()); // add method to class if (m_lockContentUnmarshal) { m_unmarshalContentMethod = m_class.getUniqueNamed(meth).getItem(); } else { m_unmarshalContentMethod = m_class.getUniqueMethod(meth).getItem(); m_unmarshalContentName = fullMethodName(m_unmarshalContentMethod); } } else { m_lockContentUnmarshal = true; } } // generate code to call created unmarshal method mb.loadContext(UNMARSHALLING_CONTEXT); genUnmarshalCall(m_unmarshalContentName, mb); } /** * Generate call to content marshal method for object. This convenience * method just generates code to call the generated marshal method added to * the class definition. The code generated prior to this call must have * loaded a reference to the object to be marshalled on the stack. * * @param mb method builder * @throws JiBXException if error in configuration */ private void genMarshalContentCall(ContextMethodBuilder mb) throws JiBXException { // check if marshal method needs to be added to class if (m_marshalContentMethod == null) { if (m_marshalContentName == null) { // set up for constructing new method String name = m_container.getBindingRoot().getPrefix() + MARSHAL_SUFFIX; MarshalBuilder meth = new MarshalBuilder(name, m_class.getClassFile(), m_class.getMungedFile()); m_marshalContentName = fullMethodName(meth); m_marshalSignature = meth.getSignature(); m_isStaticMarshal = meth.isStaticMethod(); // if preget method supplied and no attributes add code to call it if (m_preGetMethod != null && !hasAttribute()) { genUserMethodCall(false, m_preGetMethod, meth); } // push object being marshalled to marshaller stack if (!m_isThisBinding) { meth.loadContext(); meth.loadObject(); meth.appendCallVirtual(MARSHAL_PUSHOBJECTMETHOD, PUSHOBJECT_SIGNATURE); } // generate actual marshalling code meth.loadContext(); m_component.genContentMarshal(meth); // pop object from stack if (!m_isThisBinding) { meth.loadContext(); meth.appendCallVirtual(MARSHAL_POPOBJECTMETHOD, POPOBJECT_SIGNATURE); } // finish and add constructed method to class meth.appendReturn(); if (m_lockContentMarshal) { m_marshalContentMethod = m_class.getUniqueNamed(meth).getItem(); } else { m_marshalContentMethod = m_class.getUniqueMethod(meth).getItem(); m_marshalContentName = fullMethodName(m_marshalContentMethod); } } else { m_lockContentMarshal = true; } } // generate code to call created marshal method mb.loadContext(MARSHALLING_CONTEXT); genMarshalCall(m_marshalContentName, mb); } // // IContextObj interface method definitions public BoundClass getBoundClass() { return m_class; } public boolean setIdChild(IComponent child) { if (m_idChild == null) { m_idChild = child; return true; } else { return false; } } // // IComponent interface method definitions public boolean isOptional() { return false; } public void genAttributeUnmarshal(ContextMethodBuilder mb) throws JiBXException { genUnmarshalAttributeCall(mb); } public void genAttributeMarshal(ContextMethodBuilder mb) throws JiBXException { genMarshalAttributeCall(mb); } public void genContentUnmarshal(ContextMethodBuilder mb) throws JiBXException { genUnmarshalContentCall(mb); } public void genContentMarshal(ContextMethodBuilder mb) throws JiBXException { genMarshalContentCall(mb); } public void genNewInstance(ContextMethodBuilder mb) throws JiBXException { genNewInstanceCall(mb); } public String getType() { return m_class.getClassName(); } public boolean hasId() { return m_idChild != null; } public void genLoadId(ContextMethodBuilder mb) throws JiBXException { if (m_idChild == null) { throw new IllegalStateException("Internal error: no id defined"); } else { m_idChild.genLoadId(mb); } } public void setLinkages() throws JiBXException { super.setLinkages(); if (m_container.getBindingRoot().isTrackSource()) { genTrackSourceCode(); } } // DEBUG public void print(int depth) { BindingDefinition.indent(depth); System.out.print("object binding for " + m_class.getClassFile().getName()); if (m_isThisBinding) { System.out.print(" (\"this\" reference)"); } if (m_createClass != null) { System.out.print(" create class " + m_createClass.getName()); } System.out.println(); m_component.print(depth+1); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?