KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > DelegatingServiceFactory


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.part;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
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 JavaDoc delegatingComponents = new ArrayList JavaDoc();
32     
33     public DelegatingServiceFactory(ServiceFactory delegatingComponentFactory) {
34         this.delegatingComponentFactory = delegatingComponentFactory;
35     }
36     
37     public ComponentHandle createHandle(Object JavaDoc 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 JavaDoc component = handle.getInstance();
48         
49         if (component instanceof IDelegatingComponent) {
50             delegatingComponents.add(component);
51         }
52         
53         return handle;
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.core.components.IContainerContext#hasComponent(java.lang.Object)
58      */

59     public boolean hasService(Object JavaDoc 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 JavaDoc iter = delegatingComponents.iterator(); iter.hasNext();) {
71             IDelegatingComponent next = (IDelegatingComponent) iter.next();
72             
73             next.setActive(active);
74         }
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.core.components.IComponentContext#getMissingDependencies()
79      */

80     public Collection JavaDoc getMissingDependencies() {
81         Collection JavaDoc result = delegatingComponentFactory.getMissingDependencies();
82         
83         result.remove(IDelegatingContext.class);
84         return result;
85     }
86 }
87
Popular Tags