1 23 24 package org.objectweb.fractal.gui.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 import org.objectweb.fractal.api.control.LifeCycleController; 28 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Set ; 34 import java.util.HashSet ; 35 import java.util.Iterator ; 36 37 40 41 public class BasicConfiguration implements 42 Configuration, 43 Factory, 44 BindingController, 45 LifeCycleController 46 { 47 48 52 53 public final static String VETOABLE_CONFIGURATION_LISTENERS_BINDING = 54 "vetoable-configuration-listeners"; 55 56 60 61 public final static String CONFIGURATION_LISTENERS_BINDING = 62 "configuration-listeners"; 63 64 67 68 private Map vetoableListeners; 69 70 73 74 private Map listeners; 75 76 79 80 private Component root; 81 82 85 86 private boolean initialized; 87 88 91 92 private boolean started; 93 94 97 98 private long changeCount; 99 100 103 104 private String storage; 105 106 109 110 public BasicConfiguration () { 111 root = createComponent(); 112 vetoableListeners = new HashMap (); 113 listeners = new HashMap (); 114 listeners.put("", new StatusManager()); 115 } 116 117 122 123 List getVetoableListeners () { 124 return new ArrayList (vetoableListeners.values()); 125 } 126 127 132 133 List getListeners () { 134 return new ArrayList (listeners.values()); 135 } 136 137 141 public String [] listFc () { 142 Set itfs = new HashSet (); 143 itfs.addAll(listeners.keySet()); 144 itfs.addAll(vetoableListeners.keySet()); 145 return (String [])itfs.toArray(new String [itfs.size()]); 146 } 147 148 public Object lookupFc (final String clientItfName) { 149 if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 150 return listeners.get(clientItfName); 151 } else if (clientItfName.startsWith(VETOABLE_CONFIGURATION_LISTENERS_BINDING)) { 152 vetoableListeners.get(clientItfName); 153 } 154 return null; 155 } 156 157 public void bindFc ( 158 final String clientItfName, 159 final Object serverItf) 160 { 161 if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 162 listeners.put(clientItfName, serverItf); 163 } else if (clientItfName.startsWith(VETOABLE_CONFIGURATION_LISTENERS_BINDING)) { 164 vetoableListeners.put(clientItfName, serverItf); 165 } 166 } 167 168 public void unbindFc (final String clientItfName) { 169 if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 170 listeners.remove(clientItfName); 171 } else if (clientItfName.startsWith(VETOABLE_CONFIGURATION_LISTENERS_BINDING)) { 172 vetoableListeners.remove(clientItfName); 173 } 174 } 175 176 180 public String getFcState () { 181 return started ? STARTED : STOPPED; 182 } 183 184 public void startFc () { 185 if (!initialized) { 186 setRootComponent(createComponent()); 187 initialized = true; 188 } 189 started = true; 190 changeCount = 0; 191 } 192 193 public void stopFc () { 194 started = false; 195 } 196 197 201 public Component getRootComponent () { 202 return root; 203 } 204 205 public void setRootComponent (final Component root) { 206 if (root == null) { 207 throw new IllegalArgumentException (); 208 } 209 Component oldRoot = this.root; 210 if (root != oldRoot) { 211 Iterator i = vetoableListeners.values().iterator(); 212 while (i.hasNext()) { 213 VetoableConfigurationListener l = 214 (VetoableConfigurationListener)i.next(); 215 l.canChangeRootComponent(); 216 } 217 this.root = root; 218 i = listeners.values().iterator(); 219 while (i.hasNext()) { 220 ConfigurationListener l = (ConfigurationListener)i.next(); 221 l.rootComponentChanged(oldRoot); 222 } 223 } 224 initialized = true; 225 changeCount = 0; 226 } 227 228 public long getChangeCount () { 229 return changeCount; 230 } 231 232 public void setChangeCount (long changeCount) { 233 this.changeCount = changeCount; 234 Iterator i = listeners.values().iterator(); 235 while (i.hasNext()) { 236 ConfigurationListener l = (ConfigurationListener)i.next(); 237 l.changeCountChanged(getRootComponent(), changeCount); 238 } 239 } 240 241 public String getStorage () { 242 return storage; 243 } 244 245 public void setStorage (String storage) { 246 this.storage = storage; 247 } 248 249 253 public Component createComponent () { 254 return new BasicComponent(this); 255 } 256 257 public Component createComponent (final Component component) { 258 BasicComponent c; 259 if (component.getMasterComponent() != null) { 260 c = (BasicComponent)component.getMasterComponent(); 261 } else { 262 c = (BasicComponent)component; 263 } 264 return new SharedComponent(c); 265 } 266 267 public ClientInterface createClientInterface (Component owner) { 268 if (owner.getMasterComponent() != null) { 269 owner = owner.getMasterComponent(); 270 } 271 return new BasicClientInterface((BasicComponent)owner); 272 } 273 274 public ServerInterface createServerInterface (Component owner) { 275 if (owner.getMasterComponent() != null) { 276 owner = owner.getMasterComponent(); 277 } 278 return new BasicServerInterface((BasicComponent)owner); 279 } 280 } 281 | Popular Tags |