📄 oscar.java
字号:
map.put(new Long(target.getBundleId()), new RefreshHelper(target)); // Add all importing bundles to map. populateImportGraph(target, map); } // At this point the map contains every bundle that has been // updated and/or removed as well as all bundles that import // packages from these bundles. for (Iterator iter = map.values().iterator(); iter.hasNext(); ) { RefreshHelper helper = (RefreshHelper) iter.next(); helper.stop(); helper.purgeOrRemove(); helper.reinitialize(); } // Now restart bundles that were previously running. for (Iterator iter = map.values().iterator(); iter.hasNext(); ) { RefreshHelper helper = (RefreshHelper) iter.next(); helper.restart(); } } } fireFrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, getBundle(0), null); } private void populateImportGraph(BundleImpl target, HashMap map) { // Get the exported packages for the specified bundle. ExportedPackage[] pkgs = getExportedPackages(target); for (int pkgIdx = 0; (pkgs != null) && (pkgIdx < pkgs.length); pkgIdx++) { // Get all imports of this package. Bundle[] importers = getImportingBundles(pkgs[pkgIdx]); // Add importing bundle to map if not already present. for (int impIdx = 0; (importers != null) && (impIdx < importers.length); impIdx++) { Long id = new Long(importers[impIdx].getBundleId()); if (map.get(id) == null) { map.put(id, new RefreshHelper(importers[impIdx])); // Now recurse into each bundle to get its importers. populateImportGraph( (BundleImpl) importers[impIdx], map); } } } } /** * This method adds a import target to the IMPORTS_ATTR attribute * array associated with the specified module. If the module is * already validated, then this method will not add the new * import target if it will cause the specified module to become * invalidate. It is possible to "force" the method to add the * new import target, but doing so might cause module and modules * that depend on it to be invalidated. * @param module the module whose IMPORTS_ATTR meta-data is to be modified. * @param target the target to import. * @param version the version of the target to import. * @param force indicates whether to force the operation, even in the * case where the module will be invalidated. * @return <tt>true</tt> if the import target was added, <tt>false</tt> * otherwise. **/ protected boolean addImport( Module module, Object target, Object version, boolean force) {// TODO: Import permission check // Synchronize on the module manager, because we don't want // anything to change while we are in the middle of this // operation.// TODO: Is this lock sufficient? synchronized (m_mgr) { ImportSearchPolicy search = (ImportSearchPolicy) m_mgr.getSearchPolicy(); boolean added = false; Module exporter = null; // Get the valid attribute. boolean valid = ImportSearchPolicy.getValidAttribute(module).booleanValue(); // Only attempt to resolve the new import target if the // module is already valid. if (valid) { exporter = search.resolveImportTarget(target, version); } // There are three situations that will cause us to add the // new import target to the existing module: 1) we are // being forced to do so, 2) the module is not currently // validated so adding imports is okay, or 3) the module // is currently valid and we were able to resolve the new // import target. The follow if-statement checks for these // three cases. if (force || !valid || (valid && (exporter != null))) { // Create a new imports attribute array and // copy the old values into it. Object[][] imports = ImportSearchPolicy.getImportsAttribute(module); Object[][] newImports = new Object[imports.length + 1][3]; for (int i = 0; i < imports.length; i++) { newImports[i] = imports[i]; } // This is the new import target. newImports[newImports.length - 1] = new Object[] { target, version, exporter }; module.setAttribute(ImportSearchPolicy.IMPORTS_ATTR, newImports); added = true; // If it was not possible to resolve the new import target // and the module is currently valid, then the module must // be invalidated. if ((exporter == null) && valid) { search.invalidate( module, module.getAttributes(), module.getResourceSources(), module.getLibrarySources()); } } return added; } } // // Implementations for Bundle interface methods. // /** * Implementation for Bundle.getBundleId(). **/ protected long getBundleId(BundleImpl bundle) { return bundle.getInfo().getBundleId(); } /** * Implementation for Bundle.getHeaders(). **/ protected Dictionary getBundleHeaders(BundleImpl bundle) { if (System.getSecurityManager() != null) { AccessController.checkPermission(m_adminPerm); } return new MapToDictionary(bundle.getInfo().getCurrentHeader()); } /** * Implementation for Bundle.getLocation(). **/ protected String getBundleLocation(BundleImpl bundle) { if (System.getSecurityManager() != null) { AccessController.checkPermission(m_adminPerm); } return bundle.getInfo().getLocation(); } /** * Implementation for Bundle.getResource(). **/ protected URL getBundleResource(BundleImpl bundle, String name) { if (bundle.getInfo().getState() == Bundle.UNINSTALLED) { throw new IllegalStateException("The bundle is uninstalled."); } else if (System.getSecurityManager() != null) { AccessController.checkPermission(m_adminPerm); } return bundle.getInfo().getCurrentModule().getClassLoader().getResource(name);// We previously search the old revisions of the bundle for resources// first, but this caused multiple resolves when a bundle was updated// but not resolved yet. I think the following is the better way, but// other frameworks do it like above.// Module[] modules = bundle.getInfo().getModules();// for (int modIdx = 0; modIdx < modules.length; modIdx++)// {// URL url = modules[modIdx].getClassLoader().getResource(name);// if (url != null)// {// return url;// }// }// return null; } /** * Implementation for Bundle.getRegisteredServices(). **/ protected ServiceReference[] getBundleRegisteredServices(BundleImpl bundle) { if (bundle.getInfo().getState() == Bundle.UNINSTALLED) { throw new IllegalStateException("The bundle is uninstalled."); } synchronized (m_quickLock) { BundleInfo info = bundle.getInfo(); if (info.getServiceRegistrationCount() > 0) { // Create a list of service references. ArrayList list = new ArrayList(); for (int regIdx = 0; regIdx < info.getServiceRegistrationCount(); regIdx++) { // Get service registration. ServiceRegistrationImpl reg = (ServiceRegistrationImpl) info.getServiceRegistration(regIdx); // Check that the current security context has permission // to get at least one of the service interfaces; the // objectClass property of the service stores its service // interfaces. boolean hasPermission = false; if (System.getSecurityManager() != null) { String[] objectClass = (String[]) reg.getProperty(Constants.OBJECTCLASS); if (objectClass == null) { return null; } for (int ifcIdx = 0; !hasPermission && (ifcIdx < objectClass.length); ifcIdx++) { try { ServicePermission perm = new ServicePermission( objectClass[ifcIdx], ServicePermission.GET); AccessController.checkPermission(perm); hasPermission = true; } catch (Exception ex) { } } } else { hasPermission = true; } if (hasPermission) { list.add(reg.getReference()); } } if (list.size() > 0) { return (ServiceReference[]) list.toArray(new ServiceReference[list.size()]); } } } return null; } /** * Implementation for Bundle.getServicesInUse(). **/ protected ServiceReference[] getBundleServicesInUse(BundleImpl bundle) { synchronized (m_quickLock) { BundleInfo info = bundle.getInfo(); Iterator iter = info.getServiceUsageCounters(); if (iter.hasNext()) { // Create a list of service references. ArrayList list = new ArrayList(); while (iter.hasNext()) { // Get service reference. ServiceReference ref = (ServiceReference) iter.next(); // Check that the current security context has permission // to get at least one of the service interfaces; the // objectClass property of the service stores its service // interfaces. boolean hasPermission = false; if (System.getSecurityManager() != null) { String[] objectClass = (String[]) ref.getProperty(Constants.OBJECTCLASS); if (objectClass == null) { return null; } for (int i = 0; !hasPermission && (i < objectClass.length); i++) { try { ServicePermission perm = new ServicePermission( objectClass[i], ServicePermission.GET); AccessController.checkPermission(perm); hasPermission = true; } catch (Exception ex) { } } } else { hasPermission = true; } if (hasPermission)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -