1 package org.objectweb.kilim.description; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import org.objectweb.kilim.KilimException; 8 9 12 13 public class TpMethod extends InlinedElement { 14 private BasicElement support; 15 private String methodName; 16 private boolean isStatic; 17 18 private List parameters; 19 private Object resultValue; 20 21 31 public TpMethod(BasicElement aSupport, String aMethodName, boolean jStatic, boolean isP, boolean isT, TemplateDescription aTemplate) throws KilimException { 32 super(isP, isT, aTemplate); 33 if (aMethodName == null) { 34 throw new KilimException("illegal null method name in MethodActionImpl"); 35 } 36 37 support = aSupport; 38 methodName = aMethodName; 39 isStatic = jStatic; 40 } 41 42 45 public int getKind() { 46 return KILIM.METHOD; 47 } 48 49 52 public boolean isStatic() { 53 return isStatic; 54 } 55 56 59 public void isStatic(boolean jStatic) throws KilimException { 60 isStatic = jStatic; 61 } 62 63 66 public BasicElement getSupport() { 67 return support; 68 } 69 70 75 public void setSupport(BasicElement aSupport) throws KilimException { 76 if (aSupport == null) { 77 throw new KilimException("no null support is allowed in method source "); 78 } 79 support = aSupport; 80 } 81 82 86 public String getMethodName() { 87 return methodName; 88 } 89 90 94 public void setMethodName(String aMethodName) throws KilimException { 95 if (aMethodName == null) { 96 throw new KilimException("no null method name is allowed in method source "); 97 } 98 methodName = aMethodName; 99 } 100 101 105 public int getParameterNumber() { 106 if (parameters == null) { 107 return 0; 108 } 109 return parameters.size(); 110 } 111 112 113 118 public void addParameter(Parameter aParam) throws KilimException { 119 if (aParam == null) { 120 throw new KilimException("illegal null value when adding parameter"); 121 } 122 if (aParam.isEventSource()) { 123 if (parameters == null) { 124 parameters = new ArrayList (); 125 } 126 parameters.add(aParam); 127 return; 128 } 129 if (checkParameterUnicity(aParam)) { 130 if (parameters == null) { 131 parameters = new ArrayList (); 132 } 133 parameters.add(aParam); 134 } else { 135 throw new KilimException("name clash in parameter addition : " + aParam.getName() + " of method " + methodName + " in template " + getContainingTemplate().getName()); 136 } 137 } 138 139 140 146 public void insertParameter(Parameter aParam, int position) throws KilimException { 147 if (aParam == null) { 148 throw new KilimException("illegal null value when inserting parameter to method " + methodName + " in template " + getContainingTemplate().getName()); 149 } 150 if (aParam.isEventSource()) { 151 if (parameters == null) { 152 parameters = new ArrayList (); 153 } 154 parameters.add(position, aParam); 155 return; 156 } 157 if (checkParameterUnicity(aParam)) { 158 if (parameters == null) { 159 parameters = new ArrayList (); 160 } 161 parameters.add(position, aParam); 162 } else { 163 throw new KilimException("name clash in parameter insertion : " + aParam.getName() + "in method " + methodName + " in template " + getContainingTemplate().getName()); 164 } 165 } 166 167 172 public void removeParameter(Parameter aParam) throws KilimException { 173 if (aParam == null) { 174 throw new KilimException("illegal null parameter in parameter removal in method " + methodName + " in template " + getContainingTemplate().getName()); 175 } 176 if (parameters == null) { 177 throw new KilimException("illegal parameter removal on no arg method " + methodName + " in template " + getContainingTemplate().getName()); 178 } 179 boolean result = parameters.remove(aParam); 180 if (!result) { 181 throw new KilimException("attempt to removel an unknown parameter in method " + methodName + " in template " + getContainingTemplate().getName()); 182 } 183 } 184 185 191 public Parameter getParameter(int aPosition) throws KilimException { 192 if (parameters == null) { 193 throw new KilimException("illegal getParameter on no arg method " + methodName + " in template " + getContainingTemplate().getName()); 194 } 195 if (aPosition < 0 || aPosition >= parameters.size()) { 196 throw new KilimException("illegal position value in getParameter of method " + methodName + " in template " + getContainingTemplate().getName()); 197 } 198 return (Parameter) parameters.get(aPosition); 199 } 200 201 202 206 public Iterator getParameters() { 207 if (parameters == null) { 208 return KILIM.EMPTY_ITERATOR; 209 } 210 211 return parameters.listIterator(); 212 } 213 214 private boolean checkParameterUnicity(Parameter aParam) throws KilimException { 215 if (parameters == null) { 216 return true; 217 } 218 219 if (aParam.isEventSource()) { 220 return true; 221 } 222 String name = aParam.getName(); 223 if (name == null) { 224 return true; 225 } 226 int pLength = parameters.size(); 227 for (int i = 0; i < pLength ; i++) { 228 if (name != null && name.equals(((Parameter) parameters.get(i)).getName())) { 229 return false; 230 } 231 } 232 return true; 233 } 234 } | Popular Tags |