1 28 29 package org.jibx.binding.classes; 30 31 import org.apache.bcel.Constants; 32 import org.apache.bcel.generic.*; 33 import org.jibx.runtime.JiBXException; 34 35 43 44 public class ContextMethodBuilder extends ExceptionMethodBuilder 45 { 46 47 private int m_objectSlot; 48 49 50 private String m_objectType; 51 52 53 private int m_contextSlot; 54 55 56 private String m_contextType; 57 58 59 private final boolean m_isStatic; 60 61 78 79 public ContextMethodBuilder(String name, Type ret, Type[] args, 80 ClassFile cf, int access, int obj, String type, int ctx, String ctype) 81 throws JiBXException { 82 super(name, ret, args, cf, access); 83 m_objectSlot = obj; 84 m_objectType = type; 85 m_contextSlot = ctx; 86 m_contextType = ctype; 87 m_isStatic = (access & Constants.ACC_STATIC) != 0; 88 addException(FRAMEWORK_EXCEPTION_CLASS); 89 } 90 91 105 106 public ContextMethodBuilder(String name, String sig, 107 ClassFile cf, int access, int obj, String type, int ctx, String ctype) 108 throws JiBXException { 109 this(name, Type.getReturnType(sig), Type.getArgumentTypes(sig), 110 cf, access, obj, type, ctx, ctype); 111 } 112 113 126 127 public ContextMethodBuilder(String name, String sig, ClassFile cf, 128 int obj, String type, int ctx, String ctype) throws JiBXException { 129 this(name, sig, cf, Constants.ACC_PUBLIC|Constants.ACC_FINAL, 130 obj, type, ctx, ctype); 131 } 132 133 140 141 public void setObjectSlot(int slot) { 142 m_objectSlot = slot; 143 } 144 145 148 149 public void loadObject() { 150 appendLoadLocal(m_objectSlot); 151 } 152 153 158 159 public void storeObject() { 160 if (m_objectSlot < 0) { 161 LocalVariableGen var = createLocal("obj", 162 ClassItem.typeFromName(m_objectType)); 163 m_objectSlot = var.getIndex(); 164 } else { 165 appendStoreLocal(m_objectSlot); 166 } 167 } 168 169 174 175 public void loadObject(String type) { 176 appendLoadLocal(m_objectSlot); 177 if (!m_objectType.equals(type)) { 178 appendCreateCast(m_objectType, type); 179 } 180 } 181 182 185 186 public void loadContext() { 187 appendLoadLocal(m_contextSlot); 188 } 189 190 195 196 public void loadContext(String type) { 197 appendLoadLocal(m_contextSlot); 198 if (!m_contextType.equals(type)) { 199 appendCreateCast(m_contextType, type); 200 } 201 } 202 203 208 public boolean isStaticMethod() { 209 return m_isStatic; 210 } 211 } | Popular Tags |