X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db%2Fsrc%2Forg%2Fsimantics%2Fdb%2FManager.java;h=df838eed914accdef7f9aa382bdaf38468716e03;hp=69b75e33759f43eb99a736e79ab85c36b5411b54;hb=HEAD;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db/src/org/simantics/db/Manager.java b/bundles/org.simantics.db/src/org/simantics/db/Manager.java index 69b75e337..df838eed9 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/Manager.java +++ b/bundles/org.simantics.db/src/org/simantics/db/Manager.java @@ -1,87 +1,87 @@ -/******************************************************************************* - * 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 org.simantics.db; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.simantics.db.internal.Activator; - -/** - * @author Antti Villberg - */ -public final class Manager { - - private Manager() {} - - /** - * Search for registered database driver by driver id. - * - * @param id for database driver. - * @return database driver or null. - */ - public static Driver getDriver(String id) { - Map drivers = collectDrivers(); - return drivers.get(id); - } - - private static Map collectDrivers() { - BundleContext context = Activator.getContext(); - Collection> serviceReferences; - try { - serviceReferences = context.getServiceReferences(Driver.class, null); - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - serviceReferences = Collections.emptyList(); - } - Map drivers = new HashMap<>(serviceReferences.size()); - for (ServiceReference reference : serviceReferences) { - Driver driver = context.getService(reference); - String driverName = driver.getName(); - if (driverName != null && !driverName.isEmpty()) { - drivers.put(driverName, driver); - } - } - return drivers; - } - - public static DatabaseUserAgent getUserAgent(String id) { - Map agents = collectUserAgents(); - return agents.get(id); - } - - private static Map collectUserAgents() { - BundleContext context = Activator.getContext(); - Collection> serviceReferences; - try { - serviceReferences = context.getServiceReferences(DatabaseUserAgent.class, null); - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - serviceReferences = Collections.emptyList(); - } - Map drivers = new HashMap<>(serviceReferences.size()); - for (ServiceReference reference : serviceReferences) { - DatabaseUserAgent dbua = context.getService(reference); - String driverName = dbua.getId(); - if (driverName != null && !driverName.isEmpty()) { - drivers.put(driverName, dbua); - } - } - return drivers; - } - -} +/******************************************************************************* + * 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 org.simantics.db; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; +import org.simantics.db.internal.Activator; + +/** + * @author Antti Villberg + */ +public final class Manager { + + private Manager() {} + + /** + * Search for registered database driver by driver id. + * + * @param id for database driver. + * @return database driver or null. + */ + public static Driver getDriver(String id) { + Map drivers = collectDrivers(); + return drivers.get(id); + } + + private static Map collectDrivers() { + BundleContext context = Activator.getContext(); + Collection> serviceReferences; + try { + serviceReferences = context.getServiceReferences(Driver.class, null); + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + serviceReferences = Collections.emptyList(); + } + Map drivers = new HashMap<>(serviceReferences.size()); + for (ServiceReference reference : serviceReferences) { + Driver driver = context.getService(reference); + String driverName = driver.getName(); + if (driverName != null && !driverName.isEmpty()) { + drivers.put(driverName, driver); + } + } + return drivers; + } + + public static DatabaseUserAgent getUserAgent(String id) { + Map agents = collectUserAgents(); + return agents.get(id); + } + + private static Map collectUserAgents() { + BundleContext context = Activator.getContext(); + Collection> serviceReferences; + try { + serviceReferences = context.getServiceReferences(DatabaseUserAgent.class, null); + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + serviceReferences = Collections.emptyList(); + } + Map drivers = new HashMap<>(serviceReferences.size()); + for (ServiceReference reference : serviceReferences) { + DatabaseUserAgent dbua = context.getService(reference); + String driverName = dbua.getId(); + if (driverName != null && !driverName.isEmpty()) { + drivers.put(driverName, dbua); + } + } + return drivers; + } + +}