1 11 package org.eclipse.ui.internal.part; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.ui.internal.components.framework.ComponentException; 19 import org.eclipse.ui.internal.components.framework.ComponentHandle; 20 import org.eclipse.ui.internal.components.framework.IServiceProvider; 21 import org.eclipse.ui.internal.components.framework.ServiceFactory; 22 import org.eclipse.ui.internal.components.util.ServiceMap; 23 import org.eclipse.ui.internal.part.multiplexer.IDelegatingComponent; 24 import org.eclipse.ui.internal.part.multiplexer.IDelegatingContext; 25 26 public class DelegatingServiceFactory extends ServiceFactory implements IDelegatingContext { 27 28 private IServiceProvider active; 29 private ServiceFactory delegatingComponentFactory; 30 31 private List delegatingComponents = new ArrayList (); 32 33 public DelegatingServiceFactory(ServiceFactory delegatingComponentFactory) { 34 this.delegatingComponentFactory = delegatingComponentFactory; 35 } 36 37 public ComponentHandle createHandle(Object componentKey, IServiceProvider container) 38 throws ComponentException { 39 40 ComponentHandle handle = delegatingComponentFactory.createHandle(componentKey, 41 new ServiceMap(container).map(IDelegatingContext.class, this)); 42 43 if (handle == null) { 44 return null; 45 } 46 47 Object component = handle.getInstance(); 48 49 if (component instanceof IDelegatingComponent) { 50 delegatingComponents.add(component); 51 } 52 53 return handle; 54 } 55 56 59 public boolean hasService(Object key) { 60 return delegatingComponentFactory.hasService(key); 61 } 62 63 public IServiceProvider getActive() { 64 return active; 65 } 66 67 public void setActive(IServiceProvider active) { 68 this.active = active; 69 70 for (Iterator iter = delegatingComponents.iterator(); iter.hasNext();) { 71 IDelegatingComponent next = (IDelegatingComponent) iter.next(); 72 73 next.setActive(active); 74 } 75 } 76 77 80 public Collection getMissingDependencies() { 81 Collection result = delegatingComponentFactory.getMissingDependencies(); 82 83 result.remove(IDelegatingContext.class); 84 return result; 85 } 86 } 87 | Popular Tags |