00001 package edu.ksu.cis.bandera.abstraction.specification.node;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 import java.util.*;
00039 import edu.ksu.cis.bandera.abstraction.specification.analysis.*;
00040
00041 public final class AOperator extends POperator
00042 {
00043 private TOperator _operator_;
00044 private POp _op_;
00045 private TId _id_;
00046 private TBegin _begin_;
00047 private final LinkedList _pattern_ = new TypedLinkedList(new Pattern_Cast());
00048 private TEnd _end_;
00049
00050 private class Pattern_Cast implements Cast
00051 {
00052 public Object cast(Object o)
00053 {
00054 PPattern node = (PPattern) o;
00055
00056 if((node.parent() != null) &&
00057 (node.parent() != AOperator.this))
00058 {
00059 node.parent().removeChild(node);
00060 }
00061
00062 if((node.parent() == null) ||
00063 (node.parent() != AOperator.this))
00064 {
00065 node.parent(AOperator.this);
00066 }
00067
00068 return node;
00069 }
00070 }
00071 public AOperator()
00072 {
00073 }
00074 public AOperator(
00075 TOperator _operator_,
00076 POp _op_,
00077 TId _id_,
00078 TBegin _begin_,
00079 XPPattern _pattern_,
00080 TEnd _end_)
00081 {
00082 setOperator(_operator_);
00083
00084 setOp(_op_);
00085
00086 setId(_id_);
00087
00088 setBegin(_begin_);
00089
00090 if(_pattern_ != null)
00091 {
00092 while(_pattern_ instanceof X1PPattern)
00093 {
00094 this._pattern_.addFirst(((X1PPattern) _pattern_).getPPattern());
00095 _pattern_ = ((X1PPattern) _pattern_).getXPPattern();
00096 }
00097 this._pattern_.addFirst(((X2PPattern) _pattern_).getPPattern());
00098 }
00099
00100 setEnd(_end_);
00101
00102 }
00103 public AOperator(
00104 TOperator _operator_,
00105 POp _op_,
00106 TId _id_,
00107 TBegin _begin_,
00108 List _pattern_,
00109 TEnd _end_)
00110 {
00111 setOperator(_operator_);
00112
00113 setOp(_op_);
00114
00115 setId(_id_);
00116
00117 setBegin(_begin_);
00118
00119 {
00120 Object temp[] = _pattern_.toArray();
00121 for(int i = 0; i < temp.length; i++)
00122 {
00123 this._pattern_.add(temp[i]);
00124 }
00125 }
00126
00127 setEnd(_end_);
00128
00129 }
00130 public void apply(Switch sw)
00131 {
00132 ((Analysis) sw).caseAOperator(this);
00133 }
00134 public Object clone()
00135 {
00136 return new AOperator(
00137 (TOperator) cloneNode(_operator_),
00138 (POp) cloneNode(_op_),
00139 (TId) cloneNode(_id_),
00140 (TBegin) cloneNode(_begin_),
00141 cloneList(_pattern_),
00142 (TEnd) cloneNode(_end_));
00143 }
00144 public TBegin getBegin()
00145 {
00146 return _begin_;
00147 }
00148 public TEnd getEnd()
00149 {
00150 return _end_;
00151 }
00152 public TId getId()
00153 {
00154 return _id_;
00155 }
00156 public POp getOp()
00157 {
00158 return _op_;
00159 }
00160 public TOperator getOperator()
00161 {
00162 return _operator_;
00163 }
00164 public LinkedList getPattern()
00165 {
00166 return _pattern_;
00167 }
00168 void removeChild(Node child)
00169 {
00170 if(_operator_ == child)
00171 {
00172 _operator_ = null;
00173 return;
00174 }
00175
00176 if(_op_ == child)
00177 {
00178 _op_ = null;
00179 return;
00180 }
00181
00182 if(_id_ == child)
00183 {
00184 _id_ = null;
00185 return;
00186 }
00187
00188 if(_begin_ == child)
00189 {
00190 _begin_ = null;
00191 return;
00192 }
00193
00194 if(_pattern_.remove(child))
00195 {
00196 return;
00197 }
00198
00199 if(_end_ == child)
00200 {
00201 _end_ = null;
00202 return;
00203 }
00204
00205 }
00206 void replaceChild(Node oldChild, Node newChild)
00207 {
00208 if(_operator_ == oldChild)
00209 {
00210 setOperator((TOperator) newChild);
00211 return;
00212 }
00213
00214 if(_op_ == oldChild)
00215 {
00216 setOp((POp) newChild);
00217 return;
00218 }
00219
00220 if(_id_ == oldChild)
00221 {
00222 setId((TId) newChild);
00223 return;
00224 }
00225
00226 if(_begin_ == oldChild)
00227 {
00228 setBegin((TBegin) newChild);
00229 return;
00230 }
00231
00232 for(ListIterator i = _pattern_.listIterator(); i.hasNext();)
00233 {
00234 if(i.next() == oldChild)
00235 {
00236 if(newChild != null)
00237 {
00238 i.set(newChild);
00239 oldChild.parent(null);
00240 return;
00241 }
00242
00243 i.remove();
00244 oldChild.parent(null);
00245 return;
00246 }
00247 }
00248
00249 if(_end_ == oldChild)
00250 {
00251 setEnd((TEnd) newChild);
00252 return;
00253 }
00254
00255 }
00256 public void setBegin(TBegin node)
00257 {
00258 if(_begin_ != null)
00259 {
00260 _begin_.parent(null);
00261 }
00262
00263 if(node != null)
00264 {
00265 if(node.parent() != null)
00266 {
00267 node.parent().removeChild(node);
00268 }
00269
00270 node.parent(this);
00271 }
00272
00273 _begin_ = node;
00274 }
00275 public void setEnd(TEnd node)
00276 {
00277 if(_end_ != null)
00278 {
00279 _end_.parent(null);
00280 }
00281
00282 if(node != null)
00283 {
00284 if(node.parent() != null)
00285 {
00286 node.parent().removeChild(node);
00287 }
00288
00289 node.parent(this);
00290 }
00291
00292 _end_ = node;
00293 }
00294 public void setId(TId node)
00295 {
00296 if(_id_ != null)
00297 {
00298 _id_.parent(null);
00299 }
00300
00301 if(node != null)
00302 {
00303 if(node.parent() != null)
00304 {
00305 node.parent().removeChild(node);
00306 }
00307
00308 node.parent(this);
00309 }
00310
00311 _id_ = node;
00312 }
00313 public void setOp(POp node)
00314 {
00315 if(_op_ != null)
00316 {
00317 _op_.parent(null);
00318 }
00319
00320 if(node != null)
00321 {
00322 if(node.parent() != null)
00323 {
00324 node.parent().removeChild(node);
00325 }
00326
00327 node.parent(this);
00328 }
00329
00330 _op_ = node;
00331 }
00332 public void setOperator(TOperator node)
00333 {
00334 if(_operator_ != null)
00335 {
00336 _operator_.parent(null);
00337 }
00338
00339 if(node != null)
00340 {
00341 if(node.parent() != null)
00342 {
00343 node.parent().removeChild(node);
00344 }
00345
00346 node.parent(this);
00347 }
00348
00349 _operator_ = node;
00350 }
00351 public void setPattern(List list)
00352 {
00353 Object temp[] = list.toArray();
00354 for(int i = 0; i < temp.length; i++)
00355 {
00356 _pattern_.add(temp[i]);
00357 }
00358 }
00359 public String toString()
00360 {
00361 return ""
00362 + toString(_operator_)
00363 + toString(_op_)
00364 + toString(_id_)
00365 + toString(_begin_)
00366 + toString(_pattern_)
00367 + toString(_end_);
00368 }
00369 }