1 28 29 package org.jibx.binding.def; 30 31 import org.jibx.binding.classes.*; 32 import org.jibx.runtime.JiBXException; 33 34 43 44 public class DirectGeneric implements IComponent 45 { 46 49 private static final String ISEND_METHOD = 50 "org.jibx.runtime.impl.UnmarshallingContext.isEnd"; 51 private static final String ISEND_SIGNATURE = "()Z"; 52 private static final String UNMARSHALELEMENT_METHOD = 53 "org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement"; 54 private static final String UNMARSHALELEMENT_SIGNATURE = 55 "()Ljava/lang/Object;"; 56 private static final String MARSHALLABLE_INTERFACE = 57 "org.jibx.runtime.IMarshallable"; 58 private static final String MARSHALLABLE_METHOD = 59 "org.jibx.runtime.IMarshallable.marshal"; 60 private static final String MARSHALLABLE_SIGNATURE = 61 "(Lorg/jibx/runtime/IMarshallingContext;)V"; 62 63 66 67 private final IContainer m_parent; 68 69 70 private final String m_type; 71 72 73 private final PropertyDefinition m_property; 74 75 82 83 public DirectGeneric(IContainer parent, String type) { 84 m_parent = parent; 85 m_type = (type == null) ? "java.lang.Object" : type; 86 m_property = null; 87 } 88 89 97 98 public DirectGeneric(IContainer parent, String type, 99 PropertyDefinition prop) { 100 m_parent = parent; 101 m_type = (type == null) ? "java.lang.Object" : type; 102 m_property = prop; 103 } 104 105 111 112 public void genTestPresent(ContextMethodBuilder mb) { 113 114 mb.loadContext(); 117 mb.appendCallVirtual(ISEND_METHOD, ISEND_SIGNATURE); 118 mb.appendLoadConstant(1); 119 mb.appendIXOR(); 120 } 121 122 132 133 public void genUnmarshal(ContextMethodBuilder mb) throws JiBXException { 134 135 BranchWrapper tosave = null; 137 if (m_property != null && m_property.isOptional()) { 138 139 genTestPresent(mb); 143 BranchWrapper ifpres = mb.appendIFNE(this); 144 mb.appendACONST_NULL(); 145 tosave = mb.appendUnconditionalBranch(this); 146 mb.targetNext(ifpres); 147 } 148 149 mb.loadContext(); 151 mb.appendCallVirtual(UNMARSHALELEMENT_METHOD, 152 UNMARSHALELEMENT_SIGNATURE); 153 mb.appendCreateCast(m_type); 154 mb.targetNext(tosave); 155 if (m_property != null && !m_property.isImplicit()) { 156 m_property.genStore(mb); 157 } 158 } 159 160 167 168 public void genMarshal(ContextMethodBuilder mb) throws JiBXException { 169 170 BranchWrapper toend = null; 172 if (m_property != null && !m_property.isImplicit()) { 173 mb.loadObject(); 174 m_property.genLoad(mb); 175 if (m_property.isOptional()) { 176 177 mb.appendDUP(); 181 BranchWrapper ifpres = mb.appendIFNONNULL(this); 182 mb.appendPOP(); 183 toend = mb.appendUnconditionalBranch(this); 184 mb.targetNext(ifpres); 185 } 186 } 187 mb.appendCreateCast(MARSHALLABLE_INTERFACE); 188 mb.loadContext(); 189 mb.appendCallInterface(MARSHALLABLE_METHOD, MARSHALLABLE_SIGNATURE); 190 mb.targetNext(toend); 191 } 192 193 196 public boolean isOptional() { 197 return false; 198 } 199 200 public boolean hasAttribute() { 201 return false; 202 } 203 204 public void genAttrPresentTest(ContextMethodBuilder mb) { 205 throw new IllegalStateException 206 ("Internal error - no attributes defined"); 207 } 208 209 public void genAttributeUnmarshal(ContextMethodBuilder mb) { 210 throw new IllegalStateException 211 ("Internal error - no attributes defined"); 212 } 213 214 public void genAttributeMarshal(ContextMethodBuilder mb) { 215 throw new IllegalStateException 216 ("Internal error - no attributes defined"); 217 } 218 219 public boolean hasContent() { 220 return true; 221 } 222 223 public void genContentPresentTest(ContextMethodBuilder mb) 224 throws JiBXException { 225 genTestPresent(mb); 226 } 227 228 public void genContentUnmarshal(ContextMethodBuilder mb) 229 throws JiBXException { 230 genUnmarshal(mb); 231 } 232 233 public void genContentMarshal(ContextMethodBuilder mb) 234 throws JiBXException { 235 genMarshal(mb); 236 } 237 238 public void genNewInstance(ContextMethodBuilder mb) { 239 throw new IllegalStateException 240 ("Internal error - no instance creation"); 241 } 242 243 public String getType() { 244 return MARSHALLABLE_INTERFACE; 245 } 246 247 public boolean hasId() { 248 return false; 249 } 250 251 public void genLoadId(ContextMethodBuilder mb) { 252 throw new IllegalStateException ("Internal error - no ID allowed"); 253 } 254 255 public boolean checkContentSequence(boolean text) { 256 return false; 257 } 258 259 public void setLinkages() {} 260 261 public void print(int depth) { 263 BindingDefinition.indent(depth); 264 System.out.println("direct generic reference" ); 265 } 266 } | Popular Tags |