1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db;
14 import org.simantics.db.exception.ServiceNotFoundException;
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:
24 * SomeService service = session.getService(SomeService.class);
28 * If you want your service be disposed when the {@link ServiceLocator} is
29 * disposed, make your service implement {@link Disposable}.
33 * Implementations must be thread-safe.
37 * This interface is not to be implemented or extended by clients.
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.
46 * @author Tuukka Lehtonen
48 public interface ServiceLocator {
51 * Retrieves the service corresponding to the given API.
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
59 public <T> T getService(Class<T> api) throws ServiceNotFoundException;
62 * Tries to retrieve the service corresponding to the given API.
65 * This is the interface that the service implements. Must not be
67 * @return The service, or <code>null</code> if no such service could be
70 public <T> T peekService(Class<T> api);
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.
79 * This is the interface that the service implements. Must not be
81 * @return <code>true</code> iff the service locator can find a service
82 * for the given API; <code>false</code> otherwise.
84 public boolean hasService(Class<?> api);
87 * @param api the api that must be implemented by the specified service
88 * @param service the service implementation
90 public <T> void registerService(Class<T> api, T service);