1 19 package org.objectweb.carol.cmi.compiler; 20 21 import java.lang.reflect.Method ; 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 26 public class ClassConf { 27 private HashMap mthInfos = new HashMap (); 28 private boolean lookupChoice = false; 29 private ArrayList rrList = new ArrayList (); 30 private ArrayList randList = new ArrayList (); 31 private int balancerNo = 0; 32 private String defaultBalancer = null; 33 private Class cl; 34 35 public ClassConf(Class cl) { 36 this.cl = cl; 37 } 38 39 public String getClassName() { 40 return MethodProto.getName(cl); 41 } 42 43 public boolean containsMethod(MethodProto mp) { 44 return mthInfos.containsKey(mp); 45 } 46 47 public void putMethod(MethodProto mp, MethodConf cmc) { 48 mthInfos.put(mp, cmc); 49 } 50 51 public Iterator getMethodConfs() { 52 return mthInfos.values().iterator(); 53 } 54 55 public void setLookupChoice() { 56 lookupChoice = true; 57 } 58 59 public MethodConf getMethodConf(MethodProto mp) 60 throws CompilerException { 61 MethodConf cmc = (MethodConf) mthInfos.get(mp); 62 if (cmc == null) { 63 throw new CompilerException( 64 "No configuration found for method " 65 + mp 66 + " in class " 67 + getClassName()); 68 } 69 return cmc; 70 } 71 72 public String getRemoteItfString() { 73 Iterator it = Compiler.getRemoteItfs(cl).iterator(); 74 String s = ""; 75 while (it.hasNext()) { 76 Class itf = (Class ) it.next(); 77 if (s.equals("")) { 78 s = MethodProto.getName(itf); 79 } else { 80 s += ", " + MethodProto.getName(itf); 81 } 82 } 83 return s; 84 } 85 86 public String addRR() { 87 String s = "rr" + balancerNo; 88 balancerNo++; 89 rrList.add(s); 90 return s; 91 } 92 93 public String addRandom() { 94 String s = "rand" + balancerNo; 95 balancerNo++; 96 randList.add(s); 97 return s; 98 } 99 100 public ArrayList getRR() { 101 return rrList; 102 } 103 104 public ArrayList getRandom() { 105 return randList; 106 } 107 108 public String getBalancer() { 109 if (defaultBalancer == null) { 110 defaultBalancer = "balancer"; 111 } 112 randList.add(defaultBalancer); 113 return defaultBalancer; 114 } 115 116 public void validate() throws CompilerException { 117 Method [] m = Compiler.getRemoteMethods(cl); 118 if (m.length == 0) { 119 throw new CompilerException("class " + cl + " does not implement remote methods"); 120 } 121 for (int i=0; i<m.length; i++) { 122 MethodProto mp = new MethodProto(m[i]); 123 MethodConf mc = (MethodConf) mthInfos.get(mp); 124 if (mc == null) { 125 throw new CompilerException("no configuration given for method " + mp); 126 } 127 mc.setMethod(m[i]); 128 } 129 Iterator it = getMethodConfs(); 130 while (it.hasNext()) { 131 MethodConf mc = (MethodConf) it.next(); 132 if (mc.getMethod() == null) { 133 throw new CompilerException("class " + mc.getClassConf().getClassName() + " has no method " + mc.getMethodProto()); 134 } 135 } 136 } 137 } 138 | Popular Tags |