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 DirectProperty implements IComponent 44 { 45 46 private final PropertyDefinition m_property; 47 48 49 private final DirectObject m_direct; 50 51 57 58 public DirectProperty(PropertyDefinition prop, DirectObject direct) { 59 m_property = prop; 60 m_direct = direct; 61 } 62 63 66 public boolean isOptional() { 67 return m_property.isOptional(); 68 } 69 70 public boolean hasAttribute() { 71 return false; 72 } 73 74 public void genAttrPresentTest(ContextMethodBuilder mb) 75 throws JiBXException { 76 throw new IllegalStateException 77 ("Internal error - no attributes allowed"); 78 } 79 80 public void genAttributeUnmarshal(ContextMethodBuilder mb) 81 throws JiBXException { 82 throw new IllegalStateException 83 ("Internal error - no attributes allowed"); 84 } 85 86 public void genAttributeMarshal(ContextMethodBuilder mb) 87 throws JiBXException { 88 throw new IllegalStateException 89 ("Internal error - no attributes allowed"); 90 } 91 92 public boolean hasContent() { 93 return true; 94 } 95 96 public void genContentPresentTest(ContextMethodBuilder mb) 97 throws JiBXException { 98 m_direct.genContentPresentTest(mb); 99 } 100 101 public void genContentUnmarshal(ContextMethodBuilder mb) 102 throws JiBXException { 103 104 if (m_property.isImplicit()) { 106 107 mb.appendACONST_NULL(); 109 m_direct.genContentUnmarshal(mb); 110 111 } else if (m_property.isThis()) { 112 113 mb.loadObject(); 115 m_direct.genContentUnmarshal(mb); 116 117 } else { 118 119 120 mb.loadObject(); 123 BranchWrapper ifpres = null; 124 BranchWrapper tosave = null; 125 if (m_property.isOptional()) { 126 127 m_direct.genContentPresentTest(mb); 131 ifpres = mb.appendIFNE(this); 132 mb.appendACONST_NULL(); 133 tosave = mb.appendUnconditionalBranch(this); 134 } 135 136 mb.targetNext(ifpres); 140 mb.loadObject(); 141 m_property.genLoad(mb); 142 m_direct.genContentUnmarshal(mb); 143 mb.appendCreateCast(m_property.getSetValueType()); 144 mb.targetNext(tosave); 145 m_property.genStore(mb); 146 } 147 } 148 149 public void genContentMarshal(ContextMethodBuilder mb) 150 throws JiBXException { 151 152 if (m_property.isImplicit()) { 154 155 m_direct.genContentMarshal(mb); 157 158 } else if (m_property.isThis()) { 159 160 mb.loadObject(); 162 m_direct.genContentMarshal(mb); 163 164 } else { 165 166 mb.loadObject(); 168 m_property.genLoad(mb); 169 BranchWrapper missing = null; 170 if (m_property.isOptional()) { 171 172 missing = mb.appendIFNULL(this); 176 mb.loadObject(); 177 m_property.genLoad(mb); 178 } 179 180 m_direct.genContentMarshal(mb); 184 mb.targetNext(missing); 185 } 186 } 187 188 public void genNewInstance(ContextMethodBuilder mb) { 189 throw new IllegalStateException 190 ("Internal error - no instance creation"); 191 } 192 193 public String getType() { 194 return m_property.getTypeName(); 195 } 196 197 public boolean hasId() { 198 return false; 199 } 200 201 public void genLoadId(ContextMethodBuilder mb) throws JiBXException { 202 throw new IllegalStateException ("Internal error - no id defined"); 203 } 204 205 public boolean checkContentSequence(boolean text) throws JiBXException { 206 return !m_property.isOptional(); 207 } 208 209 public void setLinkages() throws JiBXException { 210 m_direct.setLinkages(); 211 } 212 213 public void print(int depth) { 215 BindingDefinition.indent(depth); 216 if (m_property == null) { 217 System.out.println("direct implicit property"); 218 } else { 219 System.out.println("direct property using " + 220 m_property.toString()); 221 } 222 m_direct.print(depth+1); 223 } 224 } 225 | Popular Tags |