KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > configurator > ConfiguratorUtils


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.update.configurator;
13
14 import java.io.*;
15 import java.net.*;
16
17 import org.eclipse.update.internal.configurator.ConfigurationActivator;
18 import org.eclipse.update.internal.configurator.Utils;
19 import org.osgi.framework.*;
20
21 /**
22  * Helper class to get platform configuration data without having to
23  * use BootLoader methods from the compatibility layer.
24  * <p>
25  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
26  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
27  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
28  * (repeatedly) as the API evolves.
29  * </p>
30  * @since 3.0
31  */

32 public class ConfiguratorUtils {
33     /**
34      * Returns the current platform configuration. This method replaces the one we used
35      * to call on BootLoader.
36      *
37      * @return platform configuration used in current instance of platform
38      * @since 3.0
39      */

40     public static IPlatformConfiguration getCurrentPlatformConfiguration() {
41         // acquire factory service first
42
BundleContext context = ConfigurationActivator.getBundleContext();
43         ServiceReference configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class.getName());
44         if (configFactorySR == null)
45             throw new IllegalStateException JavaDoc();
46         IPlatformConfigurationFactory configFactory = (IPlatformConfigurationFactory) context.getService(configFactorySR);
47         if (configFactory == null)
48             throw new IllegalStateException JavaDoc();
49         // get the configuration using the factory
50
IPlatformConfiguration currentConfig = configFactory.getCurrentPlatformConfiguration();
51         context.ungetService(configFactorySR);
52         return currentConfig;
53     }
54     
55     /**
56      * Returns a platform configuration object, optionally initialized with previously saved
57      * configuration information. We will use this method instead of the old one in BootLoader.
58      *
59      * @param url location of previously save configuration information. If <code>null</code>
60      * is specified, an empty configuration object is returned
61      * @return platform configuration used in current instance of platform
62      */

63     public static IPlatformConfiguration getPlatformConfiguration(URL url) throws IOException {
64         // acquire factory service first
65
BundleContext context = ConfigurationActivator.getBundleContext();
66         ServiceReference configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class.getName());
67         if (configFactorySR == null)
68             throw new IllegalStateException JavaDoc();
69         IPlatformConfigurationFactory configFactory = (IPlatformConfigurationFactory) context.getService(configFactorySR);
70         if (configFactory == null)
71             throw new IllegalStateException JavaDoc();
72         // get the configuration using the factory
73
IPlatformConfiguration config = configFactory.getPlatformConfiguration(url);
74         context.ungetService(configFactorySR);
75         return config;
76     }
77     
78     /**
79      * @return the URL of this eclispe installation
80      */

81     public static URL getInstallURL() {
82         return Utils.getInstallURL();
83     }
84 }
85
Popular Tags