1 15 package org.apache.hivemind.service.impl; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import javassist.CtClass; 21 22 29 public class AbstractFab 30 { 31 32 private final CtClass _ctClass; 33 34 private final CtClassSource _source; 35 36 public AbstractFab(CtClassSource source, CtClass ctClass) 37 { 38 _ctClass = ctClass; 39 _source = source; 40 } 41 42 47 private Map _ctClassCache = new HashMap (); 48 49 public void addInterface(Class interfaceClass) 50 { 51 CtClass ctInterfaceClass = _source.getCtClass(interfaceClass); 52 53 _ctClass.addInterface(ctInterfaceClass); 54 } 55 56 protected CtClass[] convertClasses(Class [] inputClasses) 57 { 58 if (inputClasses == null || inputClasses.length == 0) 59 return null; 60 61 int count = inputClasses.length; 62 CtClass[] result = new CtClass[count]; 63 64 for (int i = 0; i < count; i++) 65 { 66 CtClass ctClass = convertClass(inputClasses[i]); 67 68 result[i] = ctClass; 69 } 70 71 return result; 72 } 73 74 public boolean canConvert(Class inputClass) 75 { 76 return _source.canConvert(inputClass); 77 } 78 79 82 protected CtClass convertClass(Class inputClass) 83 { 84 CtClass result = (CtClass) _ctClassCache.get(inputClass); 85 86 if (result == null) 87 { 88 result = _source.getCtClass(inputClass); 89 _ctClassCache.put(inputClass, result); 90 } 91 92 return result; 93 } 94 95 public Class createClass() 96 { 97 return _source.createClass(_ctClass); 98 } 99 100 protected CtClass getCtClass() 101 { 102 return _ctClass; 103 } 104 105 protected CtClassSource getSource() 106 { 107 return _source; 108 } 109 110 } | Popular Tags |