]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/ServiceLocator.java
Fail safe import fixes made by Antti
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / ServiceLocator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db;
13
14 import org.simantics.db.exception.ServiceNotFoundException;
15
16 /**
17  * <p>
18  * A component with which one or more services are registered. The services can
19  * be retrieved from this locator using the class representing the interface the
20  * service must implement as a key. For example:
21  * </p>
22  * 
23  * <pre>
24  * SomeService service = session.getService(SomeService.class);
25  * </pre>
26  * 
27  * <p>
28  * If you want your service be disposed when the {@link ServiceLocator} is
29  * disposed, make your service implement {@link Disposable}.
30  * </p>
31  * 
32  * <p>
33  * Implementations must be thread-safe.
34  * </p>
35  * 
36  * <p>
37  * This interface is not to be implemented or extended by clients.
38  * </p>
39  * 
40  * <strong>NOTE:</strong> this is a blatant copy of IServiceLocator in
41  * org.eclipse.ui.services, but for the purposes of the DB connection interface.
42  * 
43  * @see Disposable
44  * 
45  * @author eclipse.org
46  * @author Tuukka Lehtonen
47  */
48 public interface ServiceLocator {
49
50     /**
51      * Retrieves the service corresponding to the given API.
52      * 
53      * @param api This is the interface that the service implements and was
54      *        registered with using {@link #registerService(Class, Object)}.
55      *        Must not be <code>null</code>.
56      * @return the requested service
57      * @throws ServiceNotFoundException if a requested service is not available
58      */
59     public <T> T getService(Class<T> api) throws ServiceNotFoundException;
60
61     /**
62      * Tries to retrieve the service corresponding to the given API.
63      * 
64      * @param api
65      *            This is the interface that the service implements. Must not be
66      *            <code>null</code>.
67      * @return The service, or <code>null</code> if no such service could be
68      *         found.
69      */
70     public <T> T peekService(Class<T> api);
71
72     /**
73      * Whether this service exists within the scope of this service locator.
74      * This does not include looking for the service within the scope of the
75      * parents. This method can be used to determine whether a particular
76      * service supports nesting in this scope.
77      * 
78      * @param api
79      *            This is the interface that the service implements. Must not be
80      *            <code>null</code>.
81      * @return <code>true</code> iff the service locator can find a service
82      *         for the given API; <code>false</code> otherwise.
83      */
84     public boolean hasService(Class<?> api);
85
86     /**
87      * @param api the api that must be implemented by the specified service
88      * @param service the service implementation
89      */
90     public <T> void registerService(Class<T> api, T service);
91
92 }