/*******************************************************************************
* Copyright (c) 2007, 2010 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
*******************************************************************************/
package fi.vtt.simantics.procore.internal;
import gnu.trove.map.hash.THashMap;
import java.util.Iterator;
import java.util.Map;
import org.simantics.db.Disposable;
import org.simantics.db.ServiceLocator;
import org.simantics.db.exception.ServiceNotFoundException;
/**
* @author Tuukka Lehtonen
*/
public class ServiceLocatorImpl implements ServiceLocator {
/**
* The parent for this service locator. If a service can't be found in this
* locator, then the parent is asked. This value may be null
* if there is no parent.
*/
private final ServiceLocator parent;
/**
* The map of services maintained by the workbench window. These services
* are initialized during workbench window during the
* {@link #configureShell(Shell)}. This value is null until
* a service is registered.
*/
private Map, Object> services = null;
/**
* Constructs a service locator with no parent.
*/
public ServiceLocatorImpl() {
this(null);
}
/**
* Constructs a service locator with the given parent.
*
* @param parent
* The parent for this service locator; this value may be
* null.
*/
public ServiceLocatorImpl(final ServiceLocator parent) {
this.parent = parent;
}
// public final void activate() {
// if (services != null) {
// final Iterator serviceItr = services.values().iterator();
// while (serviceItr.hasNext()) {
// final Object service = serviceItr.next();
// if (service instanceof INestable) {
// final INestable nestableService = (INestable) service;
// nestableService.activate();
// }
// }
// }
// }
//
// public final void deactivate() {
// if (services != null) {
// final Iterator serviceItr = services.values().iterator();
// while (serviceItr.hasNext()) {
// final Object service = serviceItr.next();
// if (service instanceof INestable) {
// final INestable nestableService = (INestable) service;
// nestableService.deactivate();
// }
// }
// }
// }
public final void dispose() {
Map, Object> s = null;
synchronized (this) {
s = services;
services = null;
}
if (s != null) {
final Iterator