org.apache.struts2.osgi

## Class DefaultBundleAccessor

- java.lang.Object
- - org.apache.struts2.osgi.DefaultBundleAccessor

- All Implemented Interfaces:
    BundleAccessor

      public class DefaultBundleAccessor
      extends Object
      implements BundleAccessor

  Helper class that find resources and loads classes from the list of bundles

- - ### Field Summary

    - ### Fields inherited from interface org.apache.struts2.osgi.BundleAccessor

      `CURRENT_BUNDLE_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultBundleAccessor()` This is a "defective" Singleton, possibly due to framework initialization requirements.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addPackageFromBundle(org.osgi.framework.Bundle bundle, String packageName)` Add as Bundle -> Package mapping
    `org.osgi.framework.ServiceReference[]` | `getAllServiceReferences(String className)`
    `static DefaultBundleAccessor` | `getInstance()`
    `Set<String>` | `getPackagesByBundle(org.osgi.framework.Bundle bundle)`
    `Object` | `getService(org.osgi.framework.ServiceReference ref)`
    `org.osgi.framework.ServiceReference` | `getServiceReference(String className)`
    `org.osgi.framework.ServiceReference[]` | `getServiceReferences(String className, String params)`
    `Class<?>` | `loadClass(String className)`
    `URL` | `loadResource(String name)`
    `URL` | `loadResource(String name, boolean translate)`
    `InputStream` | `loadResourceAsStream(String name)`
    `URL` | `loadResourceFromAllBundles(String name)`
    `InputStream` | `loadResourceFromAllBundlesAsStream(String name)`
    `List<URL>` | `loadResources(String name)`
    `List<URL>` | `loadResources(String name, boolean translate)`
    `void` | `setBundleContext(org.osgi.framework.BundleContext bundleContext)`
    `void` | `setOsgiHost(OsgiHost osgiHost)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultBundleAccessor

          public DefaultBundleAccessor()

      This is a "defective" Singleton, possibly due to framework initialization requirements. Do NOT call this constructor directly, use `instead`.

  - ### Method Detail

    - #### getInstance

          public static DefaultBundleAccessor getInstance()

    - #### getService

          public Object getService(org.osgi.framework.ServiceReference ref)

      Specified by:
        `getService` in interface `BundleAccessor`

    - #### getServiceReference

          public org.osgi.framework.ServiceReference getServiceReference(String className)

      Specified by:
        `getServiceReference` in interface `BundleAccessor`

    - #### getAllServiceReferences

          public org.osgi.framework.ServiceReference[] getAllServiceReferences(String className)

      Specified by:
        `getAllServiceReferences` in interface `BundleAccessor`

    - #### getServiceReferences

          public org.osgi.framework.ServiceReference[] getServiceReferences(String className,
                                                                   String params)
                                                                     throws org.osgi.framework.InvalidSyntaxException

      Specified by:
        `getServiceReferences` in interface `BundleAccessor`
      Throws:
        `org.osgi.framework.InvalidSyntaxException`

    - #### addPackageFromBundle

          public void addPackageFromBundle(org.osgi.framework.Bundle bundle,
                                  String packageName)

      Add as Bundle -> Package mapping
      Specified by:
        `addPackageFromBundle` in interface `BundleAccessor`
      Parameters:
        `bundle` - the bundle where the package was loaded from
        `packageName` - the name of the loaded package

    - #### loadClass

          public Class<?> loadClass(String className)
                             throws ClassNotFoundException

      Specified by:
        `loadClass` in interface `BundleAccessor`
      Throws:
        `ClassNotFoundException`

    - #### loadResources

          public List<URL> loadResources(String name)
                                  throws IOException

      Throws:
        `IOException`

    - #### loadResources

          public List<URL> loadResources(String name,
                                boolean translate)
                                  throws IOException

      Throws:
        `IOException`

    - #### loadResourceFromAllBundles

          public URL loadResourceFromAllBundles(String name)
                                         throws IOException

      Specified by:
        `loadResourceFromAllBundles` in interface `BundleAccessor`
      Throws:
        `IOException`

    - #### loadResourceFromAllBundlesAsStream

          public InputStream loadResourceFromAllBundlesAsStream(String name)
                                                         throws IOException

      Specified by:
        `loadResourceFromAllBundlesAsStream` in interface `BundleAccessor`
      Throws:
        `IOException`

    - #### loadResource

          public URL loadResource(String name)

    - #### loadResource

          public URL loadResource(String name,
                         boolean translate)

    - #### getPackagesByBundle

          public Set<String> getPackagesByBundle(org.osgi.framework.Bundle bundle)

      Specified by:
        `getPackagesByBundle` in interface `BundleAccessor`

    - #### loadResourceAsStream

          public InputStream loadResourceAsStream(String name)
                                           throws IOException

      Specified by:
        `loadResourceAsStream` in interface `BundleAccessor`
      Throws:
        `IOException`

    - #### setBundleContext

          public void setBundleContext(org.osgi.framework.BundleContext bundleContext)

      Specified by:
        `setBundleContext` in interface `BundleAccessor`

    - #### setOsgiHost

          public void setOsgiHost(OsgiHost osgiHost)

      Specified by:
        `setOsgiHost` in interface `BundleAccessor`

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.