1 64 65 package com.jcorporate.expresso.kernel.util; 66 67 import com.jcorporate.expresso.kernel.DataContext; 68 import com.jcorporate.expresso.kernel.RootContainerInterface; 69 import com.jcorporate.expresso.kernel.management.ExpressoRuntimeMap; 70 71 import java.util.Iterator ; 72 73 91 public class DataContextIterator implements Iterator { 92 RootContainerInterface runtime; 93 Iterator currentChild; 94 DataContext next = null; 95 96 102 public DataContextIterator() { 103 runtime = ExpressoRuntimeMap.getDefaultRuntime(); 104 105 if (runtime == null) { 106 throw new IllegalArgumentException ("No default runtime installed"); 107 } 108 currentChild = runtime.getContainerImplementation() 109 .getChildComponents().values().iterator(); 110 findNext(); 111 } 112 113 120 public DataContextIterator(String runtimeName) { 121 runtime = ExpressoRuntimeMap.getRuntime(runtimeName); 122 if (runtime == null) { 123 throw new IllegalArgumentException ("No runtime by the name: " 124 + runtimeName + " installed!"); 125 } 126 127 currentChild = runtime.getContainerImplementation() 128 .getChildComponents().values().iterator(); 129 findNext(); 130 } 131 132 137 public DataContextIterator(RootContainerInterface iteratingRuntime) { 138 runtime = iteratingRuntime; 139 if (runtime == null) { 140 throw new IllegalArgumentException ("Parameter iteratingRuntime cannot be null."); 141 } 142 143 currentChild = runtime.getContainerImplementation() 144 .getChildComponents().values().iterator(); 145 findNext(); 146 } 147 148 154 public boolean hasNext() { 155 return (next != null) ? true : false; 156 } 157 158 164 public Object next() { 165 if (next == null) { 166 throw new java.lang.ArrayIndexOutOfBoundsException ("No more contexts"); 167 } 168 Object returnValue = next; 169 findNext(); 170 return returnValue; 171 } 172 173 180 public DataContext nextContext() { 181 if (next == null) { 182 throw new java.lang.ArrayIndexOutOfBoundsException ("No more contexts"); 183 } 184 DataContext returnValue = next; 185 findNext(); 186 return returnValue; 187 } 188 189 190 193 public void remove() { 194 throw new java.lang.UnsupportedOperationException ("Method remove() not yet implemented."); 195 } 196 197 200 private void findNext() { 201 next = null; 202 while (currentChild.hasNext()) { 203 Object oneObj = currentChild.next(); 204 if (oneObj instanceof DataContext) { 205 next = (DataContext) oneObj; 206 break; 207 } 208 } 209 210 } 211 } | Popular Tags |