KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > osgi > EquinoxUtils


1 /*******************************************************************************
2  * Copyright (c) 2006 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 package org.eclipse.core.internal.registry.osgi;
12
13 import org.eclipse.osgi.service.environment.EnvironmentInfo;
14 import org.eclipse.osgi.service.resolver.PlatformAdmin;
15 import org.osgi.framework.*;
16
17 /**
18  * The class contains a set of Equinox-specific helper methods. The methods were isolated
19  * into separate class to prevent an attempt to load Equinox classes in a generic OSGi
20  * environment.
21  *
22  * This class uses OSGi services.
23  *
24  * @since org.eclipse.equinox.registry 3.2.100
25  */

26 public class EquinoxUtils {
27
28     /**
29      * Get the command line arguments from the EnvironmentInfo service
30      */

31     public static String JavaDoc[] getCommandLine(BundleContext context, ServiceReference ref) {
32         if (ref == null)
33             return null;
34         try {
35             EnvironmentInfo environmentInfo = (EnvironmentInfo) context.getService(ref);
36             return environmentInfo == null ? null : environmentInfo.getNonFrameworkArgs();
37         } finally {
38             context.ungetService(ref);
39         }
40     }
41
42     /**
43      * Get the time stamp from the PlatformAdmin service.
44      */

45     public static long getContainerTimestamp(BundleContext context, ServiceReference ref) {
46         if (ref == null)
47             return -1;
48         try {
49             PlatformAdmin admin = (PlatformAdmin) context.getService(ref);
50             return admin == null ? -1 : admin.getState(false).getTimeStamp();
51         } finally {
52             context.ungetService(ref);
53         }
54     }
55
56     public static ServiceRegistration registerCommandProvider(BundleContext context) {
57         // try to register the registry command provider
58
try {
59             // refer to the CommandProvider by name here so that even if VM
60
// decides to pre-fetch all referred classes the expection will occur
61
// inside the exception holder
62
return context.registerService("org.eclipse.osgi.framework.console.CommandProvider", new RegistryCommandProvider(), null); //$NON-NLS-1$
63
} catch (NoClassDefFoundError JavaDoc noClass) {
64             // expected if CommandProvider is not available
65
}
66         return null;
67     }
68 }
69
Popular Tags