1 package org.objectweb.modfact.jmi.ps; 2 import javax.jmi.reflect.*; 3 import java.util.*; 4 5 import org.objectweb.modfact.jmi.logging.Level; 6 import org.objectweb.modfact.jmi.logging.ModFactLogger; 7 import org.objectweb.modfact.jmi.reflect.*; 8 9 21 public class MOFPolymorphicIterator implements Iterator { 22 23 private Vector allNodes = new Vector(); 24 private int index = 0; 25 26 private boolean packageFilter = false; 27 private boolean classFilter = false; 28 private boolean associationFilter = false; 29 private boolean instanceFilter = false; 30 private ModFactLogger logger; 31 32 41 public void setFilters( 42 boolean packageFilter, 43 boolean classFilter, 44 boolean associationFilter, 45 boolean instanceFilter) { 46 this.packageFilter = packageFilter; 47 this.classFilter = classFilter; 48 this.associationFilter = associationFilter; 49 this.instanceFilter = instanceFilter; 50 51 } 52 53 58 public MOFPolymorphicIterator(RefBaseObject o) { 59 60 Iterator it; 61 62 allNodes.addElement(o); 63 BFS(o); 64 65 this.logger = ModFactLogger.getLogger("fr.lip6.modfact.jmi.reflect.ps"); 67 logger.log(Level.INFO, "création de l'itérateur"); 68 69 it = allNodes.iterator(); 70 71 while (it.hasNext()) { 72 73 RefBaseObject oo = (RefBaseObject) it.next(); 74 75 if (!(oo instanceof RefObject)) 76 logger.log( 77 Level.INFO, 78 (oo.getClass().toString() 79 + "type de l'objet:" 80 + (((RefBaseObject) oo).refMetaObject()).refGetValue( 81 "name")) 82 + " "); 83 else if (oo instanceof RefObject) 84 logger.log( 85 Level.INFO, 86 (oo.getClass().toString() 87 + "nom et type de l'objet:" 88 + ((RefObject) oo).refGetValue("name")) 89 + "----" 90 + ((RefObject) oo).refMetaObject().refGetValue("name")); 91 else 92 logger.log(Level.INFO, oo.getClass().toString() + ":" + "#"); 93 } 94 95 index = 0; 96 } 97 98 103 public boolean hasNext() { 104 105 while (index < allNodes.size()) { 106 if ((allNodes.elementAt(index) instanceof RefPackage 107 && packageFilter) 108 || ((allNodes.elementAt(index) instanceof RefClass 109 && classFilter)) 110 || ((allNodes.elementAt(index) instanceof RefAssociation 111 && associationFilter)) 112 || ((allNodes.elementAt(index) instanceof RefObject 113 && instanceFilter))) 114 index++; 115 else 116 return true; 117 118 } 119 return false; 120 } 121 122 126 127 public Object next() { 128 129 RefBaseObject o = null; 130 131 while (index < allNodes.size()) { 132 if ((allNodes.elementAt(index) instanceof RefPackage 133 && packageFilter) 134 || ((allNodes.elementAt(index) instanceof RefClass 135 && classFilter)) 136 || ((allNodes.elementAt(index) instanceof RefAssociation 137 && associationFilter)) 138 || ((allNodes.elementAt(index) instanceof RefObject 139 && instanceFilter))) 140 index++; 141 else { 142 143 return allNodes.elementAt(index++); 144 145 } 146 147 } 148 return o; 149 } 150 151 155 public Object first() { 156 index = 0; 157 return (RefBaseObject) allNodes.elementAt(index); 158 } 159 160 164 public void reinitialize() { 165 index = 0; 166 } 167 168 171 public void remove() { 172 } 173 174 181 private void BFS(RefBaseObject current) { 182 183 Iterator it; 184 185 index++; 186 if (hasPackages(current)) { 187 it = ((RefPackage) current).refAllPackages().iterator(); 188 while (it.hasNext()) 189 allNodes.addElement(it.next()); 190 191 } 192 if (hasClasses(current)) { 193 it = ((RefPackage) current).refAllClasses().iterator(); 194 while (it.hasNext()) 195 allNodes.addElement(it.next()); 196 197 } 198 if (hasAssociation(current)) { 199 it = ((RefPackage) current).refAllAssociations().iterator(); 200 while (it.hasNext()) 201 allNodes.addElement(it.next()); 202 203 } 204 205 if (hasInstance(current)) { 206 it = ((RefClass) current).refAllOfClass().iterator(); 207 while (it.hasNext()) { 208 allNodes.addElement(it.next()); 209 } 210 211 } 212 213 if (index < allNodes.size()) 214 BFS((RefBaseObject) allNodes.elementAt(index)); 215 216 } 217 218 225 private boolean hasChild(RefPackageImpl p) { 226 227 if (!p.refAllPackages().isEmpty()) 228 return true; 229 230 return false; 231 232 } 233 234 239 private boolean hasPackages(RefBaseObject o) { 240 if ((o instanceof RefPackageImpl) 241 && !(((RefPackage) o).refAllPackages().isEmpty())) 242 return true; 243 244 return false; 245 } 246 247 252 private boolean hasClasses(RefBaseObject o) { 253 if ((o instanceof RefPackageImpl) 254 && !(((RefPackage) o).refAllClasses().isEmpty())) 255 return true; 256 return false; 257 } 258 259 264 private boolean hasAssociation(RefBaseObject o) { 265 if ((o instanceof RefPackage) 266 && !(((RefPackage) o).refAllAssociations().isEmpty())) 267 return true; 268 return false; 269 } 270 271 276 private boolean hasInstance(RefBaseObject o) { 277 if ((o instanceof RefClass) 278 && !(((RefClass) o).refAllOfClass().isEmpty())) 279 return true; 280 return false; 281 } 282 283 } 284 | Popular Tags |