KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > components > util > ServiceProviderToServiceFactoryAdapter


1 /*******************************************************************************
2  * Copyright (c) 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.components.util;
12
13 import java.util.Collection JavaDoc;
14 import java.util.Collections JavaDoc;
15
16 import org.eclipse.ui.internal.components.framework.ComponentException;
17 import org.eclipse.ui.internal.components.framework.ComponentHandle;
18 import org.eclipse.ui.internal.components.framework.IServiceProvider;
19 import org.eclipse.ui.internal.components.framework.NonDisposingHandle;
20 import org.eclipse.ui.internal.components.framework.ServiceFactory;
21
22 /**
23  * Adapts an <code>IServiceProvider</code> to an <code>AbstractServiceFactory</code>. This is
24  * essentially a factory that always returns existing instances from the <code>IServiceProvider</code>.
25  *
26  * <p>EXPERIMENTAL: The components framework is currently under active development. All
27  * aspects of this class including its existence, name, and public interface are likely
28  * to change during the development of Eclipse 3.1</p>
29  *
30  * @since 3.1
31  */

32 public final class ServiceProviderToServiceFactoryAdapter extends ServiceFactory {
33
34     private IServiceProvider target;
35     
36     /**
37      * Creates a service factory that delegates to the given service provider.
38      *
39      * @param target service provider to adapt
40      */

41     public ServiceProviderToServiceFactoryAdapter(IServiceProvider target) {
42         this.target = target;
43     }
44     
45     /* (non-Javadoc)
46      * @see org.eclipse.core.component.IContainerContext#getComponentFactory(java.lang.Object)
47      */

48     public ComponentHandle createHandle(Object JavaDoc key, IServiceProvider provider) throws ComponentException {
49         Object JavaDoc component = target.getService(key);
50         
51         if (component != null) {
52             return new NonDisposingHandle(component);
53         }
54
55         return null;
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.core.components.IComponentContext#hasKey(java.lang.Object)
60      */

61     public boolean hasService(Object JavaDoc componentKey) {
62         return target.hasService(componentKey);
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.core.components.IComponentContext#getMissingDependencies()
67      */

68     public Collection JavaDoc getMissingDependencies() {
69         // Service providers don't have dependencies
70
return Collections.EMPTY_SET;
71     }
72     
73 }
74
Popular Tags