org.knopflerfish.framework
Class AutoManifest

java.lang.Object
  extended by java.util.jar.Manifest
      extended by org.knopflerfish.framework.AutoManifest
All Implemented Interfaces:
java.lang.Cloneable

public class AutoManifest
extends java.util.jar.Manifest

Manifest subclass which modifies some of the attributes automatically. This can be used to add or remove manifest headers to any loaded bundle. For example, adding package import/export headers.

To enable automatic manifest generation, set the system property

  org.knopflerfish.framework.automanifest=true
 

The automatic manifest config can be specified as an URL using the system property:

  org.knopflerfish.framework.automanifest.config=[URL]
 

Default is "!!/automanifest.props" The "!!" part is used to refer to a resource on the system classloader, but any URL can be used.

The configuration file for automatic manifest generation is on java property file format with any number of sections as:

 [id].match.filter=[ldap filter]
 [id].export.filter=[ldap filter]
 [id].export.file.filter=[ldap filter]
 [id].header.[header-name]=[header-value]
 [id].header.[header-name]=[header-value]
 [id].header.[header-name]=[header-value]
 ...
 

The default config file only has one section, setting all installed bundles to automatically export all of their packages, and dynamically install every class. This is implemented by a single section:

 1.match.filter=(location=*)
 1.export.filter=(pkg=*)
 1.export.file.filter=(file=*.class)
 1.header.DynamicImport-Package=*
 1.header.Import-Package=[remove]
 1.header.Export-Package=[autoexport]
 

[id] is any string. The [id] is also used for sorting the sections. Matching is done is this sort order.

The match.filter value is an LDAP filter expression used to select which bundles the section applies to. Only the first matching section is applied to a bundle. All original bundle manifest attributes can be used in the matching, plus the special key "location" which represents the bundle location string.

The export.filter value is an LDAP filter expression which selects which resources are valid for automatic package export. The special key "pkg" represents the export candidate. E.g. a filter of "(pkg=*)" exports all packages.

The export.file.filter value is an optional LDAP filter expression which selects which files are considered for auto package generation. The special key key "file" represents the file candidate. E.g. a filter of "(name=*)" considers all files. Default is "(file=*.class)

The [header-name] values are stored directly in the generated manifest. Any number of header names can be specified.

Two special header values can be used:

  "[remove]"     -  Removes the header completely from the manifest
  "[autoexport]" -  Uses the generated package names as value.
                    Package names are only present if the passes
                    the export.filter
 

Note 1: An extra attribute "Bundle-AutoManifest-config" is always added to the manifest. The value is the URL of the config file

Note 2: Debug output of automatic manifest can be enabled by setting the system property

 org.knopflerfish.framework.debug.automanifest=true
 


Constructor Summary
AutoManifest(java.util.jar.Manifest mf, java.lang.String location)
          Create an AutoManifest instance based on an orginal manifest and a bundle location.
 
Method Summary
 void addFile(java.io.File file)
          Add a File for automatic package export consideration.
 void addFile(java.lang.String prefix, java.io.File file)
          Add a File for automatic package export consideration.
 void addFileName(java.lang.String f)
          Add a string file name for automatic package export consideration.
 void addZipFile(java.util.zip.ZipFile jar)
          Add contents of a ZipFile for automatic package export consideration.
 void clear()
          Delegate to original manifest.
 boolean equals(java.lang.Object obj)
          AutoManifests are equal if both the original manifest and the bundle location are equal.
 java.util.jar.Attributes getAttributes(java.lang.String name)
          Delegate to original manifest.
 java.util.Map getEntries()
          Delegate to original manifest.
 java.lang.String getLocation()
          Get the bundle location
 java.util.jar.Attributes getMainAttributes()
          Get the main manifest attributes, possibly modified.
 java.util.jar.Manifest getManifest()
          Get the original manifest
 int hashCode()
          Hash code base on original manifest and loation
 boolean isAuto()
          Check if manifest generation is enabled for this instance.
 void read(java.io.InputStream is)
          Delegate to original manifest.
 void write(java.io.OutputStream out)
          Delegate to original manifest.
 
Methods inherited from class java.util.jar.Manifest
clone
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoManifest

public AutoManifest(java.util.jar.Manifest mf,
                    java.lang.String location)
Create an AutoManifest instance based on an orginal manifest and a bundle location.

An AutoManifest instance is a proxy to the original manifest except in the case of getting the main attributes. In this case the result may be modified according the auto manifest configuration file.

Note: The first time an AutoManifest instance is created, the configuration file is read.

Parameters:
mf - original manifest. Must not be null.
location - bundle location. Must not be null.
Method Detail

isAuto

public boolean isAuto()
Check if manifest generation is enabled for this instance.


clear

public void clear()
Delegate to original manifest.

Overrides:
clear in class java.util.jar.Manifest

getAttributes

public java.util.jar.Attributes getAttributes(java.lang.String name)
Delegate to original manifest.

Overrides:
getAttributes in class java.util.jar.Manifest

getEntries

public java.util.Map getEntries()
Delegate to original manifest.

Overrides:
getEntries in class java.util.jar.Manifest

read

public void read(java.io.InputStream is)
          throws java.io.IOException
Delegate to original manifest.

Overrides:
read in class java.util.jar.Manifest
Throws:
java.io.IOException

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Delegate to original manifest.

Overrides:
write in class java.util.jar.Manifest
Throws:
java.io.IOException

getManifest

public java.util.jar.Manifest getManifest()
Get the original manifest


getLocation

public java.lang.String getLocation()
Get the bundle location


equals

public boolean equals(java.lang.Object obj)
AutoManifests are equal if both the original manifest and the bundle location are equal.

Overrides:
equals in class java.util.jar.Manifest

hashCode

public int hashCode()
Hash code base on original manifest and loation

Overrides:
hashCode in class java.util.jar.Manifest

getMainAttributes

public java.util.jar.Attributes getMainAttributes()
Get the main manifest attributes, possibly modified.

Overrides:
getMainAttributes in class java.util.jar.Manifest

addFile

public void addFile(java.io.File file)
             throws java.io.IOException
Add a File for automatic package export consideration.

Throws:
java.io.IOException

addFile

public void addFile(java.lang.String prefix,
                    java.io.File file)
             throws java.io.IOException
Add a File for automatic package export consideration.

Throws:
java.io.IOException

addZipFile

public void addZipFile(java.util.zip.ZipFile jar)
Add contents of a ZipFile for automatic package export consideration.


addFileName

public void addFileName(java.lang.String f)
Add a string file name for automatic package export consideration.