java.lang.Object
de.uni_hildesheim.sse.easy.loader.framework.BundleInfo

public class BundleInfo extends Object
Maintains information about an OSGi bundle. In addition, bundle information object support tagging, i.e., additional information such as a loading stage may be attached and retrieved.
Author:
Holger Eichelberger
  • Field Details

    • XML_FACTORY

      private static final DocumentBuilderFactory XML_FACTORY
    • resolved

      private File resolved
    • name

      private String name
    • singleton

      private boolean singleton
    • version

      private Version version
    • activator

      private String activator
    • activationPolicy

      private String activationPolicy
    • dsSpec

      private String dsSpec
    • dsClasses

      private String[] dsClasses
    • requiredBundles

      private BundleInfo[] requiredBundles
    • importPackages

      private String[] importPackages
    • exportPackages

      private String[] exportPackages
    • tag

      private Object tag
    • sampleClass

      private String sampleClass
    • loader

      private ClassLoader loader
    • doBundleClassPath

      private boolean doBundleClassPath
    • classpath

      private String[] classpath
    • origClasspath

      private String[] origClasspath
  • Constructor Details

    • BundleInfo

      private BundleInfo(File file, Manifest manifest) throws BundleException
      Creates a bundle information object from a given JAR manifest. Please note that the DS specification must be loaded via parseDsSpec(InputStream).
      Parameters:
      file - the JAR file resolving this bundle
      manifest - the JAR manifest to analyze
      Throws:
      BundleException - if a non-OSGi manifest shall be analyzed, i.e., information in missing (or if the bundle shall be ignored)
    • BundleInfo

      private BundleInfo(String name, EasyDependency versionRestriction) throws BundleException
      Creates an unresolved bundle information object from the given symbolic name.
      Parameters:
      name - the name of the bundle
      versionRestriction - the version restriction specification
      Throws:
      BundleException - in case that the name is illegal (or if the bundle shall be ignored)
  • Method Details

    • createInstance

      public static BundleInfo createInstance(String name, EasyDependency versionSpec) throws BundleException
      Creates an bundle information instance. Successfully created instances are automatically registered in the BundleRegistry.
      Parameters:
      name - the name of the bundle
      versionSpec - the version or version specification to be fulfilled
      Returns:
      the corresponding bundle information object (or null)
      Throws:
      BundleException - in case that relevant information is missing
    • createInstance

      public static BundleInfo createInstance(File file) throws BundleException
      Creates an bundle information instance from a JAR file. Successfully created instances are automatically registered in the BundleRegistry.
      Parameters:
      file - the file to be analyzed
      Returns:
      the corresponding bundle information object (or null)
      Throws:
      BundleException - in case that reading the bundle manifest fails
    • getSampleClass

      public static String getSampleClass(JarFile jarFile)
      Returns the name of a representative class in the given JAR file.
      Parameters:
      jarFile - the JAR file
      Returns:
      the name of the representative class (just the first identified one)
    • getAttributes

      static Attributes getAttributes(Manifest manifest)
      Returns the attributes of the manifest to be considered.
      Parameters:
      manifest - the manifest to be analyzed
      Returns:
      the attributes to be considered
    • parseVersion

      static Version parseVersion(Attributes attributes) throws BundleException
      Parses the bundle version from the attributes.
      Parameters:
      attributes - the attributes to parse from
      Returns:
      the bundle version or null if none is given
      Throws:
      BundleException - in case that the version number cannot be parsed
    • parsePackageList

      private static String[] parsePackageList(Attributes attributes, String key)
      Parses a package list from the given Manifest attributes.
      Parameters:
      attributes - the attributes to be considered
      key - the attribute key
      Returns:
      the parsed package list, may be null
    • parseClasspath

      private static String[] parseClasspath(Attributes attributes)
      Parses the bundle classpath.
      Parameters:
      attributes - the attributes to be considered
      Returns:
      the bundle classpath (may be null)
    • splitBundleList

      private List<String> splitBundleList(String text)
      Splits a bundle list specificiation into bundle names with version information etc.
      Parameters:
      text - the text to be splitted
      Returns:
      the bundle lists
    • parseBundleList

      private BundleInfo[] parseBundleList(Attributes attributes, String key) throws BundleException
      Parses a bundle list from attributes.
      Parameters:
      attributes - the attributes to be considered
      key - the attribute key
      Returns:
      the parsed bundle list, may be null
      Throws:
      BundleException - in case that the bundle information object cannot be created due to missing or illegal information
    • parseSymbolicName

      static String parseSymbolicName(Attributes attributes) throws BundleException
      Parses the symbolic name and the singleton attribute.
      Parameters:
      attributes - the Manifest attributes to be analyzed
      Returns:
      the symbolic name
      Throws:
      BundleException - in case that the analysis fails, in particular if no symbolic name is given
    • parseSingleton

      private static boolean parseSingleton(Attributes attributes) throws BundleException
      Parses the attributes whether the current bundle is a singleton.
      Parameters:
      attributes - the Manifest attributes to be analyzed
      Returns:
      true if this bundle is a singleton, false else
      Throws:
      BundleException - in case that the analysis fails, in particular if no symbolic name is given
    • getName

      public String getName()
      Returns the symbolic name of the bundle.
      Returns:
      the symbolic name
    • isSingleton

      public boolean isSingleton()
      Returns whether the represented bundle is a singleton.
      Returns:
      true if it is a singleton, false else
    • getVersion

      public Version getVersion()
      Returns the version of the represented bundle.
      Returns:
      the version, may be null
    • getActivatorClassName

      public String getActivatorClassName()
      Returns the activator class name.
      Returns:
      the class name of the activator, may be null if not present
    • getActivationPolicy

      public String getActivationPolicy()
      Returns the activation policy.
      Returns:
      the activation policy, may be null if not stated
    • getDsSpec

      public String getDsSpec()
      Returns the path to the DS specification within the JAR file.
      Returns:
      the path to the DS specification, may be null if not present
    • getResolvedJar

      public File getResolvedJar()
      Returns the underlying JAR file.
      Returns:
      the underlying JAR file if this bundle is actually resolved, null else
    • tag

      public void tag(Object tag)
      Tags this bundle information object with an arbitrary tag object.
      Parameters:
      tag - the tag (may be null)
    • getTag

      public Object getTag()
      Returns the tag of this bundle information object.
      Returns:
      the tag (may be null)
    • setClassloader

      public void setClassloader(ClassLoader loader)
      Returns the class loader being responsible for loading this bundle.
      Parameters:
      loader - the responsible class loader
    • getClassloader

      public ClassLoader getClassloader()
      Returns the responsible class loader.
      Returns:
      the class loader (may be null)
    • resolve

      public void resolve(File file, Manifest manifest) throws BundleException
      Resolves this bundle.
      Parameters:
      file - the JAR file resolving this bundle
      manifest - the manifest containing the bundle information
      Throws:
      BundleException - in case that analyzing the manifest fails
    • excludeFromJar

      public Set<String> excludeFromJar()
      Returns those paths in the bundle that shall be excluded from a Jar.
      Returns:
      the paths to be excluded, null if all shall be included
    • parseDoBundleClassPath

      private static boolean parseDoBundleClassPath(Attributes attributes)
      Parses the the EASy-specific flag whether the class path shall be bundled.
      Parameters:
      attributes - the attributes
      Returns:
      true if the classpath shall be bundled
    • getRequiredBundlesCount

      public int getRequiredBundlesCount()
      Returns the number of bundles required by this bundle.
      Returns:
      the number of required bundles
    • getRequiredBundle

      public BundleInfo getRequiredBundle(int index)
      Returns the specified required bundle.
      Parameters:
      index - the 0-based index of the required bundle
      Returns:
      the specified bundle
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >=getRequiredBundlesCount()
    • getDsClassesCount

      public int getDsClassesCount()
      Returns the number of DS classes to be loaded by this bundle.
      Returns:
      the number of required bundles
    • getDsClass

      public String getDsClass(int index)
      Returns the specified DS class.
      Parameters:
      index - the 0-based index of the required bundle
      Returns:
      the specified DS class name
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >=getDsClassesCount()
    • getClasspathEntryCount

      public int getClasspathEntryCount()
      Returns the number of classpath entries in this bundle.
      Returns:
      the number of classpath entries
    • getClasspathEntry

      public String getClasspathEntry(int index)
      Returns the specified classpath entry.
      Parameters:
      index - the 0-based index of the required bundle
      Returns:
      the specified classpath entry
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >=getClasspathEntryCount()
    • getDsClasses

      public String[] getDsClasses()
      Returns (a copy of) the DS class names.
      Returns:
      the DS class names (may be null)
    • parseDsSpec

      void parseDsSpec(InputStream is) throws IOException
      Parses a DS specification into class names to be loaded and instantiated. Currently, we ignore the more sophisticated capabilities of DS and rely on the implementation element only.
      Parameters:
      is - the input stream to load (will not be closed by this method)
      Throws:
      IOException - in case that loading or parsing fails
    • analyzeForCyclicDependencies

      public List<String> analyzeForCyclicDependencies()
      Analyzes this bundle for cyclic dependencies.
      Returns:
      messages pointing to cyclic dependencies
    • analyzeForCyclicDependencies

      private void analyzeForCyclicDependencies(Set<BundleInfo> known, List<String> messages, String path)
      Analyzes this bundle for cyclic dependencies.
      Parameters:
      known - already visited and known bundles
      messages - messages collected so far
      path - the dependency path to this bundle visited so far
    • getSampleClass

      public String getSampleClass()
      Returns the sample class of this bundle.
      Returns:
      the sample class, i.e., one of the classes defined by this bundle (may be null)
    • setSampleClass

      private void setSampleClass(String sampleClass)
      Changes the sample class.
      Parameters:
      sampleClass - the new sample class
    • toString

      public String toString()
      Overrides:
      toString in class Object