1 17 package org.apache.ws.jaxme.js; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.StringTokenizer ; 23 24 import org.apache.ws.jaxme.js.JavaSource.Protection; 25 26 27 30 public abstract class AbstractJavaMethod 31 extends ConditionalIndentationJavaSourceObject { 32 private List exceptions = new ArrayList (); 33 private List params = new ArrayList (); 34 public AbstractJavaMethod(String pName, JavaQName pType, 35 Protection pProtection) { 36 super(pName, pType, pProtection); 37 } 38 39 45 public boolean isThrowing(JavaQName e) { 46 if (e == null) { 47 throw new NullPointerException ("The exception argument must not be null."); 48 } 49 for (Iterator iter = exceptions.iterator(); iter.hasNext(); ) { 50 if (e.equals(iter.next())) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 63 public boolean isThrowing(Class e) { 64 if (e == null) { 65 throw new NullPointerException ("The exception argument must not be null."); 66 } 67 return isThrowing(JavaQNameImpl.getInstance(e)); 68 } 69 70 74 public void addThrows(JavaQName e) { 75 if (e == null) { 76 throw new NullPointerException ("The exception argument must not be null."); 77 } 78 exceptions.add(e); 79 } 80 81 85 public void addThrows(Class e) { 86 if (e == null) { 87 throw new NullPointerException ("The exception argument must not be null."); 88 } 89 exceptions.add(JavaQNameImpl.getInstance(e)); 90 } 91 92 97 public void addThrows(String e) { 98 exceptions.add(JavaQNameImpl.getInstance(e, true)); 99 if (e == null) { 100 throw new NullPointerException ("The exception argument must not be null."); 101 } 102 } 103 104 105 110 public void addParam(String p) { 111 if (p == null) { 112 throw new NullPointerException ("param argument must not be null"); 113 } 114 StringTokenizer st = new StringTokenizer (p); 115 if (!st.hasMoreTokens()) { 116 throw new IllegalArgumentException ("param argument must have two tokens: type name"); 117 } 118 String type = st.nextToken(); 119 if (!st.hasMoreTokens()) { 120 throw new IllegalArgumentException ("param argument must have two tokens: type name"); 121 } 122 String name = st.nextToken(); 123 if (st.hasMoreTokens()) { 124 throw new IllegalArgumentException ("param argument must have exactly two tokens: type name"); 125 } 126 addParam(type, name); 127 } 128 129 134 public void addParam(String p, String v) { 135 if (p == null) { 136 throw new NullPointerException ("param argument must not be null"); 137 } 138 p = p.trim(); 139 addParam(JavaQNameImpl.getInstance(p, true), v); 140 } 141 142 147 public Parameter addParam(Class p, String v) { 148 return addParam(JavaQNameImpl.getInstance(p), v); 149 } 150 151 156 public Parameter addParam(JavaQName pType, String pName) { 157 if (pType == null) { 158 throw new NullPointerException ("Type argument must not be null"); 159 } 160 if (pName == null) { 161 throw new NullPointerException ("Parameter name argument must not be null"); 162 } 163 Parameter p = new Parameter(pType, pName); 164 params.add(p); 165 return p; 166 } 167 168 173 public Parameter addParam(Parameter pParam) { 174 return addParam(pParam.getType(), pParam.getName()); 175 } 176 177 179 public void clearParams() { 180 params.clear(); 181 } 182 183 187 public JavaQName[] getExceptions() { 188 return (JavaQName[]) exceptions.toArray(new JavaQName[exceptions.size()]); 189 } 190 191 192 197 public Parameter[] getParams() { 198 return (Parameter[]) params.toArray(new Parameter[params.size()]); 199 } 200 } 201 | Popular Tags |