KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > OSGi


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.osgi.framework.internal.core;
13
14 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
15
16 /**
17  * Main class for the OSGi framework. This class is used to start the framework for production use.
18  * Objects of this class represent an instance of the OSGi framework and
19  * can be used to control the framework.
20  */

21 public class OSGi {
22     protected Framework framework;
23
24     /**
25      * Constructs an OSGi object with the specified FrameworkAdaptor.
26      * This method creates an OSGi framework.
27      *
28      * @param adaptor An adaptor object for the framework to use.
29      */

30     public OSGi(FrameworkAdaptor adaptor) {
31         framework = createFramework(adaptor);
32     }
33
34     /**
35      * Destroy the OSGi framework. This method stops the framework if
36      * it has been started. All resources associated with the framework
37      * are release and the OSGi object is no longer usable.
38      *
39      */

40     public void close() {
41         framework.close();
42     }
43
44     /**
45      * Start the framework.
46      *
47      * The framework is started as described in the OSGi Framework
48      * specification.
49      */

50     public void launch() {
51         framework.launch();
52     }
53
54     /**
55      * Stop the framework.
56      *
57      * The framework is stopped as described in the OSGi Framework
58      * specification.
59      */

60     public void shutdown() {
61         framework.shutdown();
62     }
63
64     /**
65      * This method returns the state of the OSGi framework.
66      *
67      * @return true of the framework is launched, false if shutdown.
68      */

69     public boolean isActive() {
70         return (framework.isActive());
71     }
72
73     /**
74      * Retrieve the BundleContext for the system bundle.
75      *
76      * @return The system bundle's BundleContext.
77      */

78     public org.osgi.framework.BundleContext getBundleContext() {
79         return (framework.systemBundle.getContext());
80     }
81
82     /**
83      * Create the internal framework object.
84      * This method can be overridden to create a secure framework.
85      *
86      * @param adaptor FrameworkAdaptor object for the framework.
87      * @return New Framework object.
88      */

89     protected Framework createFramework(FrameworkAdaptor adaptor) {
90         return (new Framework(adaptor));
91     }
92
93     /**
94      * Display the banner to System.out.
95      *
96      */

97     protected void displayBanner() {
98         System.out.println();
99         System.out.print(Msg.ECLIPSE_OSGI_NAME);
100         System.out.print(" "); //$NON-NLS-1$
101
System.out.println(Msg.ECLIPSE_OSGI_VERSION);
102         System.out.println();
103         System.out.println(Msg.OSGI_VERSION);
104         System.out.println();
105         System.out.println(Msg.ECLIPSE_COPYRIGHT);
106     }
107 }
108
Popular Tags