1 64 65 package com.jcorporate.expresso.core.misc; 66 67 import com.jcorporate.expresso.core.dbobj.Schema; 68 import com.jcorporate.expresso.kernel.DataContext; 69 import com.jcorporate.expresso.kernel.ExpressoComponent; 70 import com.jcorporate.expresso.kernel.RootContainerInterface; 71 import com.jcorporate.expresso.kernel.management.ExpressoRuntimeMap; 72 73 import java.util.Iterator ; 74 75 94 95 public class SchemaIterator implements Iterator { 96 DataContext context; 97 Schema next = null; 98 Iterator currentChild = null; 99 100 108 public SchemaIterator() { 109 RootContainerInterface expressoRuntime = ExpressoRuntimeMap.getDefaultRuntime(); 110 if (expressoRuntime == null) { 111 throw new IllegalStateException ("No runtimes are in memory!"); 112 } 113 114 ExpressoComponent ec = expressoRuntime.getContainerImplementation() 115 .locateComponent("default"); 116 117 if (ec == null) { 118 throw new IllegalStateException ("No default data context defined in the default runtime."); 119 } 120 121 if (!(ec instanceof DataContext)) { 122 throw new IllegalStateException ("Component " + ec.getClass().getName() 123 + " is not of type DataContext"); 124 } 125 126 context = (DataContext) ec; 127 initIterator(); 128 } 129 130 137 public SchemaIterator(String runtime, String contextName) { 138 RootContainerInterface expressoRuntime = ExpressoRuntimeMap.getRuntime(runtime); 139 if (expressoRuntime == null) { 140 throw new IllegalArgumentException ("Cannot find runtime named: " 141 + runtime); 142 } 143 144 ExpressoComponent ec = expressoRuntime.getContainerImplementation() 145 .locateComponent(contextName); 146 147 if (ec == null) { 148 throw new IllegalArgumentException ("Cannot find context named: " 149 + contextName); 150 } 151 152 if (!(ec instanceof DataContext)) { 153 throw new IllegalArgumentException ("Component " + ec.getClass().getName() 154 + " is not of type DataContext"); 155 } 156 157 context = (DataContext) ec; 158 initIterator(); 159 } 160 161 168 public SchemaIterator(DataContext iteratingContext) { 169 if (iteratingContext == null) { 170 throw new IllegalArgumentException ("Parameter iterating Context must not be null"); 171 } 172 context = iteratingContext; 173 initIterator(); 174 } 175 176 182 public boolean hasNext() { 183 return (next != null) ? true : false; 184 } 185 186 192 public Object next() { 193 if (next == null) { 194 throw new java.lang.ArrayIndexOutOfBoundsException ("No more contexts"); 195 } 196 Object returnValue = next; 197 findNext(); 198 return returnValue; 199 } 200 201 208 public Schema nextContext() { 209 if (next == null) { 210 throw new java.lang.ArrayIndexOutOfBoundsException ("No more contexts"); 211 } 212 Schema returnValue = next; 213 findNext(); 214 return returnValue; 215 } 216 217 218 221 public void remove() { 222 223 throw new java.lang.UnsupportedOperationException ("Method remove() not yet implemented."); 224 } 225 226 230 private void initIterator() { 231 currentChild = context.getContainerImplementation() 232 .getChildComponents().values().iterator(); 233 } 234 235 238 private void findNext() { 239 next = null; 240 while (currentChild.hasNext()) { 241 Object oneObj = currentChild.next(); 242 if (oneObj instanceof Schema) { 243 next = (Schema) oneObj; 244 break; 245 } 246 } 247 248 } 249 } | Popular Tags |