⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oscar.java

📁 OSGI 的 源码实现,采用JAVA书写
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *          bundle has been uninstalled.    **/    protected boolean isBundlePersistentlyStarted(Bundle bundle)    {        if (bundle.getState() == Bundle.UNINSTALLED)        {            throw new IllegalArgumentException("Bundle is uninstalled.");        }        return            (((BundleImpl) bundle).getInfo().getPersistentState()                == Bundle.ACTIVE);    }    //    // Oscar framework attribute methods.    //    /**     * Returns the current status of Oscar; this information is     * used to determine which actions to perform during various     * execution activities.  For example, during startup a bundle's     * state should not be saved since the state was recorded at     * and at shutdown a bundle's state should not be saved since     * since the last active state is used.     *     * @return <tt>UNKNOWN_STATUS</tt> if Oscar is in a bad state,     *         <tt>RUNNING_STATUS</tt> if Oscar is up and running,     *         <tt>STARTING_STATUS</tt> if Oscar is in its startup sequence, or     *         <tt>STOPPING_STATUS</tt> if Oscar is in its shutdown sequence.    **/    public int getFrameworkStatus()    {        return m_oscarStatus;    }    /**     * Returns the framework flag that indicates whether Oscar is     * strictly adhering to the OSGi specification. If this is false,     * then Oscar may provides some extended functionality that is     * not part of the OSGi specification.     * @return <tt>true</tt> if Oscar is in strict mode, <tt>false</tt> otherwise.     * @deprecate use <tt>getConfigProperty(String name)</tt> instead.    **/    public boolean isStrictOSGi()    {        String strict = getConfigProperty(OscarConstants.STRICT_OSGI_PROP);        return (strict == null) ? true : strict.equals("true");    }    //    // Package management methods.    //    /**     * Returns the bundle that exports the specified package. If the     * package is not currently resolved, then it is resolved and the     * corresponding bundle is returned.     *     * @param name the name of the exported package to find.     * @return the exported package or null if no matching package was found.    **/    private BundleImpl findExportingBundle(String pkgName)    {        // Use the search policy utility method to try to        // resolve the package.        BundleImpl bundle = null;        ImportSearchPolicy search =            (ImportSearchPolicy) m_mgr.getSearchPolicy();        int[] version = { 0, 0, 0 };        Module exporter = search.resolveImportTarget(pkgName, version);        if (exporter != null)        {            bundle = (BundleImpl) getBundle(                BundleInfo.getBundleIdFromModuleId(exporter.getId()));        }        return bundle;    }    /**     * Returns the exported package associated with the specified     * package name. This is used by the PackageAdmin service     * implementation.     *     * @param name the name of the exported package to find.     * @return the exported package or null if no matching package was found.    **/    protected ExportedPackage getExportedPackage(String name)    {        BundleImpl bundle = findExportingBundle(name);        if (bundle != null)        {            // We need to find the version of the exported package, but this            // is tricky since there may be multiple versions of the package            // offered by a given bundle, since multiple revisions of the            // bundle JAR file may exist if the bundle was updated without            // refreshing the framework. In this case, each revision of the            // bundle JAR file is represented as a module in the BundleInfo            // module array, which is ordered from oldest to newest. We assume            // that the first module found to be exporting the package is the            // provider of the package, which makes sense since it must have            // been resolved first.            Module[] modules = bundle.getInfo().getModules();            for (int modIdx = 0; modIdx < modules.length; modIdx++)            {                Object version =                    ImportSearchPolicy.getExportVersion(modules[modIdx], name);                if (version != null)                {                    return new ExportedPackageImpl(                        this, bundle, name, (int[]) version);                }            }        }        return null;    }    /**     * Returns an array of all actively exported packages from the specified     * bundle or if the specified bundle is <tt>null</tt> an array     * containing all actively exported packages by all bundles.     *     * @param b the bundle whose exported packages are to be retrieved     *        or <tt>null</tt> if the exported packages of all bundles are     *        to be retrieved.     * @return an array of exported packages.    **/    protected ExportedPackage[] getExportedPackages(Bundle b)    {        ExportedPackage[] pkgs = null;        List list = new ArrayList();        // If a bundle is specified, then return its        // exported packages.        if (b != null)        {            BundleImpl bundle = (BundleImpl) b;            getExportedPackages(bundle, list);        }        // Otherwise return all exported packages.        else        {            // First get exported packages from uninstalled bundles.            for (int bundleIdx = 0;                (m_uninstalledBundles != null) && (bundleIdx < m_uninstalledBundles.length);                bundleIdx++)            {                BundleImpl bundle = m_uninstalledBundles[bundleIdx];                getExportedPackages(bundle, list);            }            // Now get exported packages from installed bundles.            Bundle[] bundles = getBundles();            for (int bundleIdx = 0; bundleIdx < bundles.length; bundleIdx++)            {                BundleImpl bundle = (BundleImpl) bundles[bundleIdx];                getExportedPackages(bundle, list);            }        }        return (ExportedPackage[]) list.toArray(new ExportedPackage[list.size()]);    }    /**     * Adds any current active exported packages from the specified bundle     * to the passed in list.     * @param bundle the bundle from which to retrieve exported packages.     * @param list the list to which the exported packages are added    **/    private void getExportedPackages(BundleImpl bundle, List list)    {        // Since a bundle may have many modules associated with it,        // one for each revision in the cache, search each module        // for each revision to get all exports.        Module[] modules = bundle.getInfo().getModules();        for (int modIdx = 0; modIdx < modules.length; modIdx++)        {            Object[][] exports =                ImportSearchPolicy.getExportsAttribute(modules[modIdx]);            if (exports.length > 0)            {                for (int expIdx = 0; expIdx < exports.length; expIdx++)                {                    // If the resolving module is the same as the current                    // module, then this bundle exports the package so add                    // the package to the list of exported packages.                    if (exports[expIdx][ImportSearchPolicy.RESOLVING_MODULE_IDX]                        == modules[modIdx])                    {                        list.add(new ExportedPackageImpl(                            this, bundle,                            (String) exports[expIdx][ImportSearchPolicy.IDENTIFIER_IDX],                            (int[]) exports[expIdx][ImportSearchPolicy.VERSION_IDX]));                    }                }            }        }    }    protected Bundle[] getImportingBundles(ExportedPackage ep)    {        // Get exporting bundle; we need to use this internal        // method because the spec says ep.getExportingBundle()        // should return null if the package is stale.        BundleImpl exporter = (BundleImpl)            ((ExportedPackageImpl) ep).getExportingBundleInternal();        BundleInfo exporterInfo = exporter.getInfo();        String exportName = ep.getName();        // Create list for storing importing bundles.        List list = new ArrayList();        Bundle[] bundles = getBundles();        // Check all bundles to see who imports the package.        for (int bundleIdx = 0; bundleIdx < bundles.length; bundleIdx++)        {            BundleImpl bundle = (BundleImpl) bundles[bundleIdx];            // Flag to short-circuit the loops if we find that            // the current bundle does import the package.            boolean doesImport = false;            // Check the imports and exports of each bundle.            String[] searchAttrs = {                ImportSearchPolicy.IMPORTS_ATTR,                ImportSearchPolicy.EXPORTS_ATTR            };            for (int attrIdx = 0;                (!doesImport) && (attrIdx < searchAttrs.length);                attrIdx++)            {                // Check all revisions of each bundle.                Module[] modules = bundle.getInfo().getModules();                for (int modIdx = 0;                    (!doesImport) && (modIdx < modules.length);                    modIdx++)                {                    Object[][] imports =                        ImportSearchPolicy.getImportsOrExports(                            modules[modIdx], searchAttrs[attrIdx]);                    for (int importIdx = 0;                        (!doesImport) && (importIdx < imports.length);                        importIdx++)                    {                        // Get import package name.                        String importName = (String)                            imports[importIdx][ImportSearchPolicy.IDENTIFIER_IDX];                        // Get resolving module.                        Module resolvingModule = (Module)                            imports[importIdx][ImportSearchPolicy.RESOLVING_MODULE_IDX];                        // If the export and import package names are the same                        // and the resolving module is associated with the                        // exporting, then add current bundle to list.                        if (exportName.equals(importName) &&                            exporterInfo.hasModule(resolvingModule))                        {                            // Add the bundle to the list of importers.                            list.add(bundles[bundleIdx]);                            // Set the import flag so we exit the loops.                            doesImport = true;                        }                    }                }            }        }        // Return the results.        if (list.size() > 0)        {            return (Bundle[]) list.toArray(new Bundle[list.size()]);        }        return null;    }    protected void refreshPackages(Bundle[] targets)    {        if (System.getSecurityManager() != null)        {            AccessController.checkPermission(m_adminPerm);        }        synchronized (m_adminLock)        {            // If targets is null, then refresh all pending bundles.            if (targets == null)            {                ArrayList list = new ArrayList();                // First add all uninstalled bundles.                for (int i = 0;                    (m_uninstalledBundles != null) && (i < m_uninstalledBundles.length);                    i++)                {                    list.add(m_uninstalledBundles[i]);                }                m_uninstalledBundles = null;                // Then add all updated bundles.                Iterator iter = m_installedBundleMap.values().iterator();                while (iter.hasNext())                {                    BundleImpl bundle = (BundleImpl) iter.next();                    if (bundle.getInfo().isRemovalPending())                    {                        list.add(bundle);                    }                }                // Create an array.                if (list.size() > 0)                {                    targets = (Bundle[]) list.toArray(new Bundle[list.size()]);                }            }            // If there are targets, then find all dependencies            // for each one.            if (targets != null)            {                // Create map of bundles that import the packages                // from the target bundles.                HashMap map = new HashMap();                for (int targetIdx = 0; targetIdx < targets.length; targetIdx++)                {                    BundleImpl target = (BundleImpl) targets[targetIdx];                    // Add the current target bundle to the map of                    // bundles to be refreshed using a RefreshHelper.                    // Only these target bundles should be refreshed.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -