Class ExtensionManager

  • All Implemented Interfaces:
    Content

    class ExtensionManager
    extends java.net.URLStreamHandler
    implements Content
    The ExtensionManager class is used in several ways.

    First, a private instance is added (as URL with the instance as URLStreamHandler) to the classloader that loaded the class. It is assumed that this is an instance of URLClassloader (if not extension bundles will not work). Subsequently, extension bundles can be managed by instances of this class (their will be one instance per framework instance).

    Second, it is used as module definition of the systembundle. Added extension bundles with exported packages will contribute their exports to the systembundle export.

    Third, it is used as content loader of the systembundle. Added extension bundles exports will be available via this loader.

    • Field Detail

      • m_logger

        private final Logger m_logger
      • m_configMap

        private final java.util.Map m_configMap
      • m_headerMap

        private final java.util.Map m_headerMap
      • m_systemBundleRevision

        private final BundleRevision m_systemBundleRevision
      • m_capabilities

        private volatile java.util.List<BundleCapability> m_capabilities
      • m_exportNames

        private volatile java.util.Set<java.lang.String> m_exportNames
      • m_securityContext

        private volatile java.lang.Object m_securityContext
      • m_extensions

        private final java.util.List m_extensions
      • m_extensionsCache

        private volatile Bundle[] m_extensionsCache
      • m_names

        private final java.util.Set m_names
      • m_sourceToExtensions

        private final java.util.Map m_sourceToExtensions
    • Constructor Detail

      • ExtensionManager

        private ExtensionManager()
      • ExtensionManager

        ExtensionManager​(Logger logger,
                         java.util.Map configMap,
                         Felix felix)
        This constructor is used to create one instance per framework instance. The general approach is to have one private static instance that we register with the parent classloader and one instance per framework instance that keeps track of extension bundles and systembundle exports for that framework instance.
        Parameters:
        logger - the logger to use.
        config - the configuration to read properties from.
        systemBundleInfo - the info to change if we need to add exports.
    • Method Detail

      • getSecurityContext

        public java.lang.Object getSecurityContext()
      • setSecurityContext

        public void setSecurityContext​(java.lang.Object securityContext)
      • addExtensionBundle

        void addExtensionBundle​(Felix felix,
                                BundleImpl bundle)
                         throws java.lang.SecurityException,
                                BundleException,
                                java.lang.Exception
        Add an extension bundle. The bundle will be added to the parent classloader and it's exported packages will be added to the module definition exports of this instance. Subsequently, they are available form the instance in it's role as content loader.
        Parameters:
        felix - the framework instance the given extension bundle comes from.
        bundle - the extension bundle to add.
        Throws:
        BundleException - if extension bundles are not supported or this is not a framework extension.
        java.lang.SecurityException - if the caller does not have the needed AdminPermission.EXTENSIONLIFECYCLE and security is enabled.
        java.lang.Exception - in case something goes wrong.
      • startExtensionBundle

        void startExtensionBundle​(Felix felix,
                                  BundleImpl bundle)
        This is a Felix specific extension mechanism that allows extension bundles to have activators and be started via this method.
        Parameters:
        felix - the framework instance the extension bundle is installed in.
        bundle - the extension bundle to start if it has a Felix specific activator.
      • startPendingExtensionBundles

        void startPendingExtensionBundles​(Felix felix)
      • stopExtensionBundles

        void stopExtensionBundles​(Felix felix)
      • removeExtensions

        void removeExtensions​(Felix felix)
        Remove all extension registered by the given framework instance. Note, it is not possible to unregister allready loaded classes form those extensions. That is why the spec requires a JVM restart.
        Parameters:
        felix - the framework instance whose extensions need to be unregistered.
      • getCapabilities

        private java.util.List<BundleCapability> getCapabilities​(java.lang.String namespace)
      • appendCapabilities

        private void appendCapabilities​(java.util.List<BundleCapability> caps)
      • convertCapabilitiesToHeaders

        private java.lang.String convertCapabilitiesToHeaders​(java.util.Map headers)
      • openConnection

        public java.net.URLConnection openConnection​(java.net.URL url)
                                              throws java.io.IOException
        Specified by:
        openConnection in class java.net.URLStreamHandler
        Throws:
        java.io.IOException
      • getHostAddress

        protected java.net.InetAddress getHostAddress​(java.net.URL u)
        Overrides:
        getHostAddress in class java.net.URLStreamHandler
      • addExtension

        private void addExtension​(java.lang.Object source,
                                  Bundle extension)
      • _removeExtensions

        private void _removeExtensions​(java.lang.Object source)
      • _add

        private void _add​(java.lang.String name,
                          Bundle extension)
      • close

        public void close()
        Description copied from interface: Content

        This method must be called when the content is no longer needed so that any resourses being used (e.g., open files) can be closed. Once this method is called, the content is no longer usable. If the content is already closed, then calls on this method should have no effect.

        Specified by:
        close in interface Content
      • getEntries

        public java.util.Enumeration getEntries()
        Description copied from interface: Content

        Returns an enumeration of entry names as String objects. An entry name is a path constructed with '/' as path element separators and is relative to the root of the content. Entry names for entries that represent directories should end with the '/' character.

        Specified by:
        getEntries in interface Content
      • hasEntry

        public boolean hasEntry​(java.lang.String name)
        Description copied from interface: Content

        This method determines if the specified named entry is contained in the associated content. The entry name is a relative path with '/' separators.

        Specified by:
        hasEntry in interface Content
        Parameters:
        name - The name of the entry to find.
        Returns:
        true if a corresponding entry was found, false otherwise.
      • getEntryAsBytes

        public byte[] getEntryAsBytes​(java.lang.String name)
        Description copied from interface: Content

        This method returns the named entry as an array of bytes.

        Specified by:
        getEntryAsBytes in interface Content
        Parameters:
        name - The name of the entry to retrieve as a byte array.
        Returns:
        An array of bytes if the corresponding entry was found, null otherwise.
      • getEntryAsStream

        public java.io.InputStream getEntryAsStream​(java.lang.String name)
                                             throws java.io.IOException
        Description copied from interface: Content

        This method returns the named entry as an input stream.

        Specified by:
        getEntryAsStream in interface Content
        Parameters:
        name - The name of the entry to retrieve as an input stream.
        Returns:
        An input stream if the corresponding entry was found, null otherwise.
        Throws:
        java.io.IOException
      • getEntryAsContent

        public Content getEntryAsContent​(java.lang.String name)
        Description copied from interface: Content

        This method returns the named entry as an IContent Typically, this method only makes sense for entries that correspond to some form of aggregated resource (e.g., an embedded JAR file or directory), but implementations are free to interpret this however makes sense. This method should return a new IContent instance for every invocation and the caller is responsible for opening and closing the returned content object.

        Specified by:
        getEntryAsContent in interface Content
        Parameters:
        name - The name of the entry to retrieve as an IContent.
        Returns:
        An IContent instance if a corresponding entry was found, null otherwise.
      • getEntryAsNativeLibrary

        public java.lang.String getEntryAsNativeLibrary​(java.lang.String name)
        Description copied from interface: Content

        This method returns the named entry as a file in the file system for use as a native library. It may not be possible for all content implementations (e.g., memory only) to implement this method, in which case it is acceptable to return null. Since native libraries can only be associated with a single class loader, this method should return a unique file per request.

        Specified by:
        getEntryAsNativeLibrary in interface Content
        Parameters:
        name - The name of the entry to retrieve as a file.
        Returns:
        A string corresponding to the absolute path of the file if a corresponding entry was found, null otherwise.
      • getEntryAsURL

        public java.net.URL getEntryAsURL​(java.lang.String name)
        Description copied from interface: Content

        This method allows retrieving an entry as a local URL.

        Specified by:
        getEntryAsURL in interface Content
        Parameters:
        name - The name of the entry to retrieve as a URL
        Returns:
        A URL using a local protocol such as file, jar or null if not possible.