1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import java.io.IOException ; 15 import java.net.URL ; 16 import java.util.Enumeration ; 17 import org.eclipse.osgi.framework.adaptor.BundleData; 18 import org.eclipse.osgi.framework.debug.Debug; 19 import org.eclipse.osgi.util.NLS; 20 import org.osgi.framework.*; 21 22 public class BundleFragment extends AbstractBundle { 23 24 25 protected BundleLoaderProxy[] hosts; 26 27 32 public BundleFragment(BundleData bundledata, Framework framework) throws BundleException { 33 super(bundledata, framework); 34 hosts = null; 35 } 36 37 40 protected void load() { 41 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 42 if ((state & (INSTALLED)) == 0) { 43 Debug.println("Bundle.load called when state != INSTALLED: " + this); Debug.printStackTrace(new Exception ("Stack trace")); } 46 } 47 48 if (framework.isActive()) { 49 SecurityManager sm = System.getSecurityManager(); 50 51 if (sm != null && framework.permissionAdmin != null) { 52 domain = framework.permissionAdmin.createProtectionDomain(this); 53 } 54 } 55 } 56 57 64 protected boolean reload(AbstractBundle newBundle) { 65 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 66 if ((state & (INSTALLED | RESOLVED)) == 0) { 67 Debug.println("Bundle.reload called when state != INSTALLED | RESOLVED: " + this); Debug.printStackTrace(new Exception ("Stack trace")); } 70 } 71 72 boolean exporting = false; 73 if (framework.isActive()) { 74 if (hosts != null) { 75 if (state == RESOLVED) { 76 exporting = true; hosts = null; 78 state = INSTALLED; 79 } 80 } 81 } else { 82 83 try { 84 this.bundledata.close(); 85 } catch (IOException e) { 86 } 88 } 89 if (!exporting) { 90 91 try { 92 this.bundledata.close(); 93 } catch (IOException e) { 94 } 96 } 97 98 this.bundledata = newBundle.bundledata; 99 this.bundledata.setBundle(this); 100 if (framework.isActive() && System.getSecurityManager() != null && framework.permissionAdmin != null) 102 domain = framework.permissionAdmin.createProtectionDomain(this); 103 return (exporting); 104 } 105 106 112 protected void refresh() { 113 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 114 if ((state & (UNINSTALLED | INSTALLED | RESOLVED)) == 0) { 115 Debug.println("Bundle.refresh called when state != UNINSTALLED | INSTALLED | RESOLVED: " + this); Debug.printStackTrace(new Exception ("Stack trace")); } 118 } 119 120 if (state == RESOLVED) { 121 hosts = null; 122 state = INSTALLED; 123 } 126 manifestLocalization = null; 127 } 128 129 135 protected boolean unload() { 136 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 137 if ((state & (UNINSTALLED | INSTALLED | RESOLVED)) == 0) { 138 Debug.println("Bundle.unload called when state != UNINSTALLED | INSTALLED | RESOLVED: " + this); Debug.printStackTrace(new Exception ("Stack trace")); } 141 } 142 143 boolean exporting = false; 144 if (framework.isActive()) { 145 if (hosts != null) { 146 if (state == RESOLVED) { 147 exporting = true; hosts = null; 149 state = INSTALLED; 150 } 151 domain = null; 152 } 153 } 154 if (!exporting) { 155 try { 156 this.bundledata.close(); 157 } catch (IOException e) { } 159 } 160 161 return (exporting); 162 } 163 164 172 protected Class loadClass(String name, boolean checkPermission) throws ClassNotFoundException { 173 if (checkPermission) { 174 try { 175 framework.checkAdminPermission(this, AdminPermission.CLASS); 176 } catch (SecurityException e) { 177 throw new ClassNotFoundException (); 178 } 179 checkValid(); 180 } 181 throw new ClassNotFoundException (NLS.bind(Msg.BUNDLE_FRAGMENT_CNFE, name)); 184 } 185 186 203 public URL getResource(String name) { 204 checkValid(); 205 return (null); 208 209 } 210 211 public Enumeration getResources(String name) { 212 checkValid(); 213 return null; 216 } 217 218 223 protected void startWorker(int options) throws BundleException { 224 throw new BundleException(NLS.bind(Msg.BUNDLE_FRAGMENT_START, this)); 225 } 226 227 232 protected void stopWorker(int options) throws BundleException { 233 throw new BundleException(NLS.bind(Msg.BUNDLE_FRAGMENT_STOP, this)); 234 } 235 236 252 public ServiceReference[] getRegisteredServices() { 253 checkValid(); 254 return null; 257 } 258 259 275 public ServiceReference[] getServicesInUse() { 276 checkValid(); 277 return null; 280 } 281 282 protected BundleLoaderProxy[] getHosts() { 283 return hosts; 284 } 285 286 protected boolean isFragment() { 287 return true; 288 } 289 290 294 protected boolean addHost(BundleLoaderProxy host) { 295 if (host == null) 296 return false; 297 try { 298 ((BundleHost) host.getBundleHost()).attachFragment(this); 299 } catch (BundleException be) { 300 framework.publishFrameworkEvent(FrameworkEvent.ERROR, host.getBundleHost(), be); 301 return false; 302 } 303 if (hosts == null) { 304 hosts = new BundleLoaderProxy[] {host}; 305 return true; 306 } 307 for (int i = 0; i < hosts.length; i++) { 308 if (host.getBundleHost() == hosts[i].getBundleHost()) 309 return true; } 311 BundleLoaderProxy[] newHosts = new BundleLoaderProxy[hosts.length + 1]; 312 System.arraycopy(hosts, 0, newHosts, 0, hosts.length); 313 newHosts[newHosts.length - 1] = host; 314 hosts = newHosts; 315 return true; 316 } 317 318 protected BundleLoader getBundleLoader() { 319 return null; 321 } 322 323 328 protected BundleContextImpl getContext() { 329 return null; 331 } 332 } 333 | Popular Tags |