1 28 29 package org.jibx.binding.model; 30 31 import org.jibx.binding.classes.ClassFile; 32 import org.jibx.binding.classes.ClassItem; 33 import org.jibx.runtime.JiBXException; 34 35 43 44 public class ClassWrapper implements IClass 45 { 46 private final ClassFile m_class; 47 48 public ClassWrapper(ClassFile clas) { 49 m_class = clas; 50 } 51 52 55 public String getName() { 56 return m_class.getName(); 57 } 58 59 62 public String getSignature() { 63 return m_class.getSignature(); 64 } 65 66 69 public String getPackage() { 70 return m_class.getPackage(); 71 } 72 73 76 public IClass getSuperClass() { 77 ClassFile scf = m_class.getSuperFile(); 78 if (scf == null) { 79 return null; 80 } else { 81 return new ClassWrapper(m_class.getSuperFile()); 82 } 83 } 84 85 88 public String [] getInterfaces() { 89 return m_class.getInterfaces(); 90 } 91 92 95 public String [] getInstanceSigs() { 96 try { 97 return m_class.getInstanceSigs(); 98 } catch (JiBXException e) { 99 throw new IllegalStateException ("Internal error: instance " + 101 "signatures not found for class " + m_class.getName()); 102 } 103 } 104 105 108 public boolean isImplements(String sig) { 109 try { 110 return m_class.isImplements(sig); 111 } catch (JiBXException e) { 112 throw new IllegalStateException ("Internal error: instance " + 114 "signatures not found for class " + m_class.getName()); 115 } 116 } 117 118 121 public boolean isSuperclass(String name) { 122 ClassFile current = m_class; 123 while (current != null) { 124 if (current.getName().equals(name)) { 125 return true; 126 } else { 127 current = current.getSuperFile(); 128 } 129 } 130 return false; 131 } 132 133 136 public IClassItem getDirectField(String name) { 137 ClassItem item = m_class.getDirectField(name); 138 if (item == null) { 139 return null; 140 } else { 141 return new ClassItemWrapper(this, item); 142 } 143 } 144 145 148 public IClassItem getField(String name) { 149 try { 150 return new ClassItemWrapper(this, m_class.getField(name)); 151 } catch (JiBXException e) { 152 return null; 154 } 155 } 156 157 160 public IClassItem getMethod(String name, String sig) { 161 ClassItem item = m_class.getMethod(name, sig); 162 if (item == null) { 163 return null; 164 } else { 165 return new ClassItemWrapper(this, item); 166 } 167 } 168 169 172 public IClassItem getMethod(String name, String [] sigs) { 173 ClassItem item = m_class.getMethod(name, sigs); 174 if (item == null) { 175 return null; 176 } else { 177 return new ClassItemWrapper(this, item); 178 } 179 } 180 181 184 public IClassItem getInitializerMethod(String sig) { 185 ClassItem item = m_class.getInitializerMethod(sig); 186 if (item == null) { 187 return null; 188 } else { 189 return new ClassItemWrapper(this, item); 190 } 191 } 192 193 196 public IClassItem getStaticMethod(String name, String sig) { 197 ClassItem item = m_class.getStaticMethod(name, sig); 198 if (item == null) { 199 return null; 200 } else { 201 return new ClassItemWrapper(this, item); 202 } 203 } 204 205 208 public boolean isAccessible(IClassItem item) { 209 return m_class.isAccessible(((ClassItemWrapper)item).m_item); 210 } 211 212 215 public boolean isAssignable(IClass other) { 216 String [] sigs; 217 try { 218 sigs = m_class.getInstanceSigs(); 219 } catch (JiBXException e) { 220 throw new IllegalStateException 221 ("Internal error: class information not available"); 222 } 223 String match = other.getSignature(); 224 for (int i = 0; i < sigs.length; i++) { 225 if (match.equals(sigs[i])) { 226 return true; 227 } 228 } 229 return false; 230 } 231 232 235 public IClassItem getBestMethod(String name, String type, String [] args) { 236 ClassItem item = m_class.getBestMethod(name, type, args); 237 if (item == null) { 238 return null; 239 } else { 240 return new ClassItemWrapper(this, item); 241 } 242 } 243 244 248 public ClassFile getClassFile() { 249 return m_class; 250 } 251 } | Popular Tags |