KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensugar > cube > SystemBundle


1 /*
2  * JEFFREE: Java(TM) Embedded Framework FREE
3  * Copyright (C) 1999-2003 - Opensugar
4  *
5  * The contents of this file are subject to the Jeffree Public License,
6  * as defined by the file JEFFREE_LICENSE.TXT
7  *
8  * You may not use this file except in compliance with the License.
9  * You may obtain a copy of the License on the Objectweb web site
10  * (www.objectweb.org).
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14  * the specific terms governing rights and limitations under the License.
15  *
16  * The Original Code is JEFFREE, including the java package com.opensugar.cube,
17  * released January 1, 2003.
18  *
19  * The Initial Developer of the Original Code is Opensugar.
20  * The Original Code is Copyright Opensugar.
21  * All Rights Reserved.
22  *
23  * Initial developer(s): Pierre Scokaert (Opensugar)
24  * Contributor(s):
25  */

26
27 package com.opensugar.cube;
28
29 //import com.opensugar.cube.permissionAdmin.PermissionAdminImpl;
30

31 import org.osgi.framework.Constants;
32 import org.osgi.framework.BundleException;
33 import org.osgi.service.packageadmin.PackageAdmin;
34 import org.osgi.service.permissionadmin.PermissionAdmin;
35
36 import java.io.File JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.io.InputStream JavaDoc;
39 import java.util.Properties JavaDoc;
40
41 public class SystemBundle extends BundleImpl {
42
43    private BundleContextImpl bundleContext;
44    private int state;
45
46    protected SystemBundle( AbstractCube cube, File JavaDoc bundleJarFile ) throws IOException JavaDoc, ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, InstantiationException JavaDoc {
47       super( cube, (long)0, Constants.SYSTEM_BUNDLE_LOCATION, bundleJarFile );
48
49       bundleContext = new BundleContextImpl( cube, this );
50       state = ACTIVE;
51
52       // register package admin service
53
Properties JavaDoc props = new Properties JavaDoc();
54       props.put( "Description", "OSGi compliant package admin service by Opensugar" );
55       bundleContext.registerService( PackageAdmin.class.getName(), cube.getPackageAdmin(), props );
56
57       if ( cube.enforcesPermissions() ) {
58          // register permission admin service
59
props = new Properties JavaDoc();
60          props.put( "Description", "OSGi compliant permission admin service by Opensugar" );
61          bundleContext.registerService( PermissionAdmin.class.getName(), cube.getPermissionAdmin(), props );
62       }
63    }
64
65    // redefinition of getBundleContext() method
66
public BundleContextImpl getBundleContext() {
67       return bundleContext;
68    }
69
70    // redefinition of getState() method
71
public int getState() {
72       return state;
73    }
74
75    public void start() {
76       // Do nothing, framework already started
77
}
78
79    public void stop() {
80       // shut down framework on another thread
81
( new Thread JavaDoc() { public void run() { getCube().shutdown( true ); state = RESOLVED; } } ).start();
82
83       state = STOPPING;
84       // return immediately
85
}
86
87    public void update() {
88       // stop framework
89
getCube().shutdown( false );
90
91       int threadCount = Thread.activeCount() - 1;
92       if ( threadCount > 0 ) {
93          getCube().log( getCube().LOG_WARNING, "Framework is stopped but " + threadCount + " bundle threads are still running\n Some bundles are not shutting down all their threads when stopping" );
94       }
95
96       // restart framework
97
getCube().startup( null );
98    }
99
100    public void update( InputStream JavaDoc in ) throws BundleException {
101       // should flash cube
102
throw new BundleException( "Cube flashing not implemented yet" );
103    }
104
105    public void uninstall() throws BundleException {
106       throw new BundleException( "System Bundle cannot be uninstalled" );
107    }
108
109 }
110
Popular Tags