--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db;\r
+\r
+import org.simantics.db.exception.ServiceNotFoundException;\r
+\r
+/**\r
+ * <p>\r
+ * A component with which one or more services are registered. The services can\r
+ * be retrieved from this locator using the class representing the interface the\r
+ * service must implement as a key. For example:\r
+ * </p>\r
+ * \r
+ * <pre>\r
+ * SomeService service = session.getService(SomeService.class);\r
+ * </pre>\r
+ * \r
+ * <p>\r
+ * If you want your service be disposed when the {@link ServiceLocator} is\r
+ * disposed, make your service implement {@link Disposable}.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Implementations must be thread-safe.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * This interface is not to be implemented or extended by clients.\r
+ * </p>\r
+ * \r
+ * <strong>NOTE:</strong> this is a blatant copy of IServiceLocator in\r
+ * org.eclipse.ui.services, but for the purposes of the DB connection interface.\r
+ * \r
+ * @see Disposable\r
+ * \r
+ * @author eclipse.org\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public interface ServiceLocator {\r
+\r
+ /**\r
+ * Retrieves the service corresponding to the given API.\r
+ * \r
+ * @param api This is the interface that the service implements and was\r
+ * registered with using {@link #registerService(Class, Object)}.\r
+ * Must not be <code>null</code>.\r
+ * @return the requested service\r
+ * @throws ServiceNotFoundException if a requested service is not available\r
+ */\r
+ public <T> T getService(Class<T> api) throws ServiceNotFoundException;\r
+\r
+ /**\r
+ * Tries to retrieve the service corresponding to the given API.\r
+ * \r
+ * @param api\r
+ * This is the interface that the service implements. Must not be\r
+ * <code>null</code>.\r
+ * @return The service, or <code>null</code> if no such service could be\r
+ * found.\r
+ */\r
+ public <T> T peekService(Class<T> api);\r
+\r
+ /**\r
+ * Whether this service exists within the scope of this service locator.\r
+ * This does not include looking for the service within the scope of the\r
+ * parents. This method can be used to determine whether a particular\r
+ * service supports nesting in this scope.\r
+ * \r
+ * @param api\r
+ * This is the interface that the service implements. Must not be\r
+ * <code>null</code>.\r
+ * @return <code>true</code> iff the service locator can find a service\r
+ * for the given API; <code>false</code> otherwise.\r
+ */\r
+ public boolean hasService(Class<?> api);\r
+\r
+ /**\r
+ * @param api the api that must be implemented by the specified service\r
+ * @param service the service implementation\r
+ */\r
+ public <T> void registerService(Class<T> api, T service);\r
+\r
+}\r