1 26 27 package com.opensugar.cube; 28 29 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 ; 37 import java.io.IOException ; 38 import java.io.InputStream ; 39 import java.util.Properties ; 40 41 public class SystemBundle extends BundleImpl { 42 43 private BundleContextImpl bundleContext; 44 private int state; 45 46 protected SystemBundle( AbstractCube cube, File bundleJarFile ) throws IOException , ClassNotFoundException , IllegalAccessException , InstantiationException { 47 super( cube, (long)0, Constants.SYSTEM_BUNDLE_LOCATION, bundleJarFile ); 48 49 bundleContext = new BundleContextImpl( cube, this ); 50 state = ACTIVE; 51 52 Properties props = new Properties (); 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 props = new Properties (); 60 props.put( "Description", "OSGi compliant permission admin service by Opensugar" ); 61 bundleContext.registerService( PermissionAdmin.class.getName(), cube.getPermissionAdmin(), props ); 62 } 63 } 64 65 public BundleContextImpl getBundleContext() { 67 return bundleContext; 68 } 69 70 public int getState() { 72 return state; 73 } 74 75 public void start() { 76 } 78 79 public void stop() { 80 ( new Thread () { public void run() { getCube().shutdown( true ); state = RESOLVED; } } ).start(); 82 83 state = STOPPING; 84 } 86 87 public void update() { 88 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 getCube().startup( null ); 98 } 99 100 public void update( InputStream in ) throws BundleException { 101 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 |