1 56 package org.objectstyle.cayenne.map; 57 58 import java.util.ArrayList ; 59 import java.util.Iterator ; 60 import java.util.List ; 61 62 import org.objectstyle.cayenne.util.Util; 63 import org.objectstyle.cayenne.util.XMLEncoder; 64 65 70 public class Procedure extends MapObject { 71 protected String catalog; 72 protected String schema; 73 protected boolean returningValue; 74 protected List callParameters = new ArrayList (); 75 76 79 public Procedure() { 80 super(); 81 } 82 83 86 public Procedure(String name) { 87 super(name); 88 } 89 90 95 public void encodeAsXML(XMLEncoder encoder) { 96 encoder.print("<procedure name=\""); 97 encoder.print(Util.encodeXmlAttribute(getName())); 98 encoder.print('\"'); 99 100 if (getSchema() != null && getSchema().trim().length() > 0) { 101 encoder.print(" schema=\""); 102 encoder.print(getSchema().trim()); 103 encoder.print('\"'); 104 } 105 106 if (getCatalog() != null && getCatalog().trim().length() > 0) { 107 encoder.print(" catalog=\""); 108 encoder.print(getCatalog().trim()); 109 encoder.print('\"'); 110 } 111 112 if (isReturningValue()) { 113 encoder.print(" returningValue=\"true\""); 114 } 115 116 encoder.println('>'); 117 118 encoder.indent(1); 119 encoder.print(getCallParameters()); 120 encoder.indent(-1); 121 122 encoder.println("</procedure>"); 123 } 124 125 128 public String getFullyQualifiedName() { 129 return (schema != null) ? schema + '.' + getName() : getName(); 130 } 131 132 135 public DataMap getDataMap() { 136 return (DataMap) getParent(); 137 } 138 139 142 public void setDataMap(DataMap dataMap) { 143 this.setParent(dataMap); 144 } 145 146 public void setCallParameters(List parameters) { 147 clearCallParameters(); 148 callParameters.addAll(parameters); 149 } 150 151 155 public void addCallParameter(ProcedureParameter param) { 156 if (param.getName() == null) { 157 throw new IllegalArgumentException ("Attempt to add unnamed parameter."); 158 } 159 160 if (callParameters.contains(param)) { 161 throw new IllegalArgumentException ( 162 "Attempt to add the same parameter more than once:" + param); 163 } 164 165 param.setProcedure(this); 166 callParameters.add(param); 167 } 168 169 170 public void removeCallParameter(String name) { 171 for (int i = 0; i < callParameters.size(); i++) { 172 ProcedureParameter nextParam = (ProcedureParameter) callParameters.get(i); 173 if (name.equals(nextParam.getName())) { 174 callParameters.remove(i); 175 break; 176 } 177 } 178 } 179 180 public void clearCallParameters() { 181 callParameters.clear(); 182 } 183 184 189 public List getCallParameters() { 190 return callParameters; 191 } 192 193 197 public List getCallOutParameters() { 198 List outParams = new ArrayList (callParameters.size()); 199 Iterator it = callParameters.iterator(); 200 while (it.hasNext()) { 201 ProcedureParameter param = (ProcedureParameter) it.next(); 202 if (param.isOutParam()) { 203 outParams.add(param); 204 } 205 } 206 207 return outParams; 208 } 209 210 215 public ProcedureParameter getResultParam() { 216 return (returningValue && callParameters.size() > 0) 219 ? (ProcedureParameter) callParameters.get(0) 220 : null; 221 } 222 223 230 public boolean isReturningValue() { 231 return returningValue; 232 } 233 234 public void setReturningValue(boolean returningValue) { 235 this.returningValue = returningValue; 236 } 237 238 public String getCatalog() { 239 return catalog; 240 } 241 242 public String getSchema() { 243 return schema; 244 } 245 246 249 public void setCatalog(String string) { 250 catalog = string; 251 } 252 253 256 public void setSchema(String string) { 257 schema = string; 258 } 259 } 260 | Popular Tags |