1 28 29 package org.jibx.binding.def; 30 31 import org.jibx.binding.classes.*; 32 import org.jibx.runtime.JiBXException; 33 34 42 43 public class ComponentProperty extends PassThroughComponent 44 { 45 46 private final PropertyDefinition m_property; 47 48 49 private final boolean m_skipMarshal; 50 51 58 59 public ComponentProperty(PropertyDefinition prop, IComponent impl, 60 boolean skip) { 61 super(impl); 62 m_property = prop; 63 m_skipMarshal = skip; 64 } 65 66 69 public boolean isOptional() { 70 return m_property.isOptional(); 71 } 72 73 public void genAttributeUnmarshal(ContextMethodBuilder mb) 74 throws JiBXException { 75 76 if (!m_property.isImplicit() && !m_property.isThis()) { 79 mb.loadObject(); 80 } 81 BranchWrapper ifpres = null; 82 BranchWrapper tosave = null; 83 if (m_property.isOptional()) { 84 85 m_component.genAttrPresentTest(mb); 89 ifpres = mb.appendIFNE(this); 90 mb.appendACONST_NULL(); 91 tosave = mb.appendUnconditionalBranch(this); 92 } 93 94 mb.targetNext(ifpres); 98 if (m_property.isImplicit()) { 99 m_component.genNewInstance(mb); 100 } else if (!m_property.isThis()) { 101 102 mb.loadObject(); 104 m_property.genLoad(mb); 105 mb.appendCreateCast(m_property.getGetValueType(), 106 m_component.getType()); 107 mb.appendDUP(); 108 BranchWrapper haveinst = mb.appendIFNONNULL(this); 109 110 mb.appendPOP(); 112 m_component.genNewInstance(mb); 113 mb.targetNext(haveinst); 114 } 115 mb.appendDUP(); 116 m_component.genAttributeUnmarshal(mb); 117 118 mb.appendCreateCast(m_component.getType(), 120 m_property.getSetValueType()); 121 mb.targetNext(tosave); 122 if (!m_property.isImplicit() && !m_property.isThis()) { 123 m_property.genStore(mb); 124 } 125 } 126 127 public void genAttributeMarshal(ContextMethodBuilder mb) 128 throws JiBXException { 129 if (m_skipMarshal) { 130 131 m_component.genAttributeMarshal(mb); 133 134 } else { 135 136 if (!m_property.isImplicit()) { 138 mb.loadObject(); 139 m_property.genLoad(mb); 140 } 141 BranchWrapper ifpres = null; 142 BranchWrapper toend = null; 143 if (m_property.isOptional()) { 144 145 mb.appendDUP(); 149 ifpres = mb.appendIFNONNULL(this); 150 mb.appendPOP(); 151 toend = mb.appendUnconditionalBranch(this); 152 } 153 154 mb.targetNext(ifpres); 158 m_component.genAttributeMarshal(mb); 159 mb.targetNext(toend); 160 } 161 } 162 163 public void genContentUnmarshal(ContextMethodBuilder mb) 164 throws JiBXException { 165 166 if (m_component.hasAttribute()) { 168 169 if (!m_property.isImplicit()) { 171 mb.loadObject(); 172 m_property.genLoad(mb); 173 } else { 174 mb.appendDUP(); 175 } 176 BranchWrapper toend = null; 177 if (m_property.isOptional()) { 178 179 toend = mb.appendIFNULL(this); 183 if (!m_property.isImplicit()) { 184 mb.loadObject(); 185 m_property.genLoad(mb); 186 } else { 187 mb.appendDUP(); 188 } 189 } 190 191 m_component.genContentUnmarshal(mb); 193 mb.targetNext(toend); 194 195 } else { 196 197 if (!m_property.isImplicit() && !m_property.isThis()) { 200 mb.loadObject(); 201 } 202 BranchWrapper ifpres = null; 203 BranchWrapper tosave = null; 204 if (m_property.isOptional()) { 205 206 m_component.genContentPresentTest(mb); 210 ifpres = mb.appendIFNE(this); 211 mb.appendACONST_NULL(); 212 tosave = mb.appendUnconditionalBranch(this); 213 } 214 215 mb.targetNext(ifpres); 219 if (m_property.isImplicit()) { 220 m_component.genNewInstance(mb); 221 } else if (!m_property.isThis()) { 222 223 mb.loadObject(); 225 m_property.genLoad(mb); 226 mb.appendCreateCast(m_property.getGetValueType(), 227 m_component.getType()); 228 mb.appendDUP(); 229 BranchWrapper haveinst = mb.appendIFNONNULL(this); 230 231 mb.appendPOP(); 233 m_component.genNewInstance(mb); 234 mb.targetNext(haveinst); 235 } 236 mb.appendDUP(); 237 m_component.genContentUnmarshal(mb); 238 239 mb.appendCreateCast(m_component.getType(), 241 m_property.getSetValueType()); 242 mb.targetNext(tosave); 243 if (!m_property.isImplicit() && !m_property.isThis()) { 244 m_property.genStore(mb); 245 } 246 } 247 } 248 249 public void genContentMarshal(ContextMethodBuilder mb) 250 throws JiBXException { 251 if (m_skipMarshal) { 252 253 m_component.genContentMarshal(mb); 255 256 } else { 257 258 if (!m_property.isImplicit()) { 260 mb.loadObject(); 261 m_property.genLoad(mb); 262 } 263 BranchWrapper ifpres = null; 264 BranchWrapper tonext = null; 265 if (m_property.isOptional()) { 266 267 mb.appendDUP(); 271 ifpres = mb.appendIFNONNULL(this); 272 mb.appendPOP(); 273 tonext = mb.appendUnconditionalBranch(this); 274 } 275 276 mb.targetNext(ifpres); 280 m_component.genContentMarshal(mb); 281 mb.targetNext(tonext); 282 283 } 284 } 285 286 public void print(int depth) { 288 BindingDefinition.indent(depth); 289 System.out.print("component " + m_property.toString()); 290 if (m_skipMarshal) { 291 System.out.print(" (pass-through marshal)"); 292 } 293 System.out.println(); 294 m_component.print(depth+1); 295 } 296 } | Popular Tags |