org.eclipse.osgi.internal.baseadaptor
Class BaseStorageHook

java.lang.Object
  extended by org.eclipse.osgi.internal.baseadaptor.BaseStorageHook
All Implemented Interfaces:
AdaptorHook, StorageHook, KeyedElement

public class BaseStorageHook
extends Object
implements StorageHook, AdaptorHook


Field Summary
static String COMPOSITE_BUNDLE
           
static String COMPOSITE_HEADER
           
static int DEL_BUNDLE_STORE
           
static int DEL_GENERATION
           
static String EXTERNAL_LIB_PREFIX
           
static int HASHCODE
           
static String KEY
           
static String SURROGATE_BUNDLE
           
static char VARIABLE_DELIM_CHAR
           
static String VARIABLE_DELIM_STRING
           
 
Constructor Summary
BaseStorageHook(BaseStorage storage)
           
 
Method Summary
 void addProperties(Properties properties)
          Gets called by the adaptor during FrameworkAdaptor.getProperties().
 boolean compare(KeyedElement other)
          Compares this element with a specified element
 void copy(StorageHook storageHook)
          Copies the data from the specified storage hook into this storage hook.
 StorageHook create(BaseData bundledata)
          Creates an uninitialized storage hook for the specified bundledata.
 FrameworkLog createFrameworkLog()
          Gets called by the adaptor during FrameworkAdaptor.getFrameworkLog().
 boolean forgetStartLevelChange(int startlevel)
          Gets called by a base data during BundleData.setStartLevel(int).
 boolean forgetStatusChange(int status)
          Gets called by a base data during BundleData.setStatus(int).
 void frameworkStart(BundleContext context)
          Gets called by the adaptor during FrameworkAdaptor.frameworkStart(BundleContext).
 void frameworkStop(BundleContext context)
          Gets called by the adaptor during FrameworkAdaptor.frameworkStop(BundleContext).
 void frameworkStopping(BundleContext context)
          Gets called by the adaptor during FrameworkAdaptor.frameworkStopping(BundleContext).
 File getBundleStore()
           
 File getDataFile(String path)
           
 String getFileName()
           
 int getGeneration()
           
 Object getKey()
          Returns the key for this element
 int getKeyHashCode()
          Returns the hash code of the key
 Dictionary<String,String> getManifest(boolean firstLoad)
          Returns the manifest for the data in this storage hook, or null if this hook does not provide the manifest.
 String[] getNativePaths()
           
 BaseStorage getStorage()
           
 int getStorageVersion()
          Returns the storage version of this storage hook.
 void handleRuntimeError(Throwable error)
          Gets called by the adaptor during FrameworkAdaptor.handleRuntimeError(Throwable).
 void initialize(BaseAdaptor adaptor)
          Gets called by the adaptor during FrameworkAdaptor.initialize(EventPublisher).
 void initialize(Dictionary<String,String> manifest)
          Initializes this storage hook with the content of the specified bundle manifest.
 void installNativePaths(String[] installPaths)
           
 boolean isReference()
           
 StorageHook load(BaseData target, DataInputStream in)
          Creates a new storage hook and loads the data from the specified input stream into the storage hook.
 URLConnection mapLocationToURLConnection(String location)
          Gets called by the adaptor during FrameworkAdaptor.mapLocationToURLConnection(String).
 void save(DataOutputStream out)
          Saves the data from this storage hook into the specified output stream.
 void setFileName(String fileName)
           
 void setReference(boolean reference)
           
static String substituteVars(String path)
           
 void validate()
          Validates the data in this storage hook, if the data is invalid then an illegal state exception is thrown
 void validateNativePaths(String[] paths)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY

public static final String KEY

HASHCODE

public static final int HASHCODE

DEL_BUNDLE_STORE

public static final int DEL_BUNDLE_STORE
See Also:
Constant Field Values

DEL_GENERATION

public static final int DEL_GENERATION
See Also:
Constant Field Values

EXTERNAL_LIB_PREFIX

public static final String EXTERNAL_LIB_PREFIX
See Also:
Constant Field Values

VARIABLE_DELIM_STRING

public static final String VARIABLE_DELIM_STRING
See Also:
Constant Field Values

VARIABLE_DELIM_CHAR

public static final char VARIABLE_DELIM_CHAR
See Also:
Constant Field Values

COMPOSITE_HEADER

public static String COMPOSITE_HEADER

COMPOSITE_BUNDLE

public static String COMPOSITE_BUNDLE

SURROGATE_BUNDLE

public static String SURROGATE_BUNDLE
Constructor Detail

BaseStorageHook

public BaseStorageHook(BaseStorage storage)
Method Detail

getStorageVersion

public int getStorageVersion()
Description copied from interface: StorageHook
Returns the storage version of this storage hook. This version is used by the storage to check the consistency of cached persistent data. Any time a storage hook changes the format of its persistent data the storage version should be incremented.

Specified by:
getStorageVersion in interface StorageHook
Returns:
the storage version of this storage hook

create

public StorageHook create(BaseData bundledata)
                   throws BundleException
Description copied from interface: StorageHook
Creates an uninitialized storage hook for the specified bundledata. This method is called when a bundle is installed or updated. The returned storage hook will be used for the new contents of the bundle. The returned hook will have its StorageHook.initialize(Dictionary) method called to initialize the storage hook.

Specified by:
create in interface StorageHook
Parameters:
bundledata - a base data the created storage hook will be associated with
Returns:
an uninitialized storage hook
Throws:
BundleException

initialize

public void initialize(Dictionary<String,String> manifest)
                throws BundleException
Description copied from interface: StorageHook
Initializes this storage hook with the content of the specified bundle manifest. This method is called when a bundle is installed or updated.

Specified by:
initialize in interface StorageHook
Parameters:
manifest - the bundle manifest to load into this storage hook
Throws:
BundleException - if any error occurs
See Also:
StorageHook.create(BaseData), StorageHook.copy(StorageHook)

load

public StorageHook load(BaseData target,
                        DataInputStream in)
                 throws IOException
Description copied from interface: StorageHook
Creates a new storage hook and loads the data from the specified input stream into the storage hook. This method is called during startup to load all the persistently installed bundles.

It is important that this method and the StorageHook.save(DataOutputStream) method stay in sync. This method must be able to successfully read the data saved by the StorageHook.save(DataOutputStream) method.

Specified by:
load in interface StorageHook
Parameters:
target - a base data the loaded storage hook will be associated with
in - an input stream used to load the storage hook's data from.
Returns:
a loaded storage hook
Throws:
IOException - if any error occurs
See Also:
StorageHook.save(DataOutputStream)

save

public void save(DataOutputStream out)
          throws IOException
Description copied from interface: StorageHook
Saves the data from this storage hook into the specified output stream. This method is called if some persistent data has changed for the bundle.

It is important that this method and the StorageHook.load(BaseData, DataInputStream) method stay in sync. This method must be able to save data which the StorageHook.load(BaseData, DataInputStream) method can ready successfully.

Specified by:
save in interface StorageHook
Parameters:
out - an output stream used to save the storage hook's data from.
Throws:
IOException - if any error occurs
See Also:
StorageHook.load(BaseData, DataInputStream)

getKeyHashCode

public int getKeyHashCode()
Description copied from interface: KeyedElement
Returns the hash code of the key

Specified by:
getKeyHashCode in interface KeyedElement
Returns:
the hash code of the key

compare

public boolean compare(KeyedElement other)
Description copied from interface: KeyedElement
Compares this element with a specified element

Specified by:
compare in interface KeyedElement
Parameters:
other - the element to compare with
Returns:
returns true if the specified element equals this element

getKey

public Object getKey()
Description copied from interface: KeyedElement
Returns the key for this element

Specified by:
getKey in interface KeyedElement
Returns:
the key for this element

getFileName

public String getFileName()

getGeneration

public int getGeneration()

getNativePaths

public String[] getNativePaths()

installNativePaths

public void installNativePaths(String[] installPaths)
                        throws BundleException
Throws:
BundleException

validateNativePaths

public void validateNativePaths(String[] paths)
                         throws BundleException
Throws:
BundleException

isReference

public boolean isReference()

getBundleStore

public File getBundleStore()

getDataFile

public File getDataFile(String path)

setReference

public void setReference(boolean reference)

setFileName

public void setFileName(String fileName)

copy

public void copy(StorageHook storageHook)
Description copied from interface: StorageHook
Copies the data from the specified storage hook into this storage hook. This method is called when a bundle is updated to copy the data from the original bundle to a new storage hook. Then this storage will be initialized with the new bundle's manifest using the StorageHook.initialize(Dictionary) method.

Specified by:
copy in interface StorageHook
Parameters:
storageHook - the original storage hook to copy data out of.
See Also:
StorageHook.create(BaseData), StorageHook.initialize(Dictionary)

validate

public void validate()
              throws IllegalArgumentException
Description copied from interface: StorageHook
Validates the data in this storage hook, if the data is invalid then an illegal state exception is thrown

Specified by:
validate in interface StorageHook
Throws:
IllegalArgumentException - if the data is invalid

getManifest

public Dictionary<String,String> getManifest(boolean firstLoad)
                                      throws BundleException
Description copied from interface: StorageHook
Returns the manifest for the data in this storage hook, or null if this hook does not provide the manifest. Most hooks should return null from this method. This method may be used to provide special handling of manifest loading. For example, to provide a cached manfest or to do automatic manifest generation.

Specified by:
getManifest in interface StorageHook
Parameters:
firstLoad - true if this is the very first time this manifest is being loaded.
Returns:
the manifest for the data in this storage hook, or null if this hook does not provide the manifest
Throws:
BundleException

forgetStatusChange

public boolean forgetStatusChange(int status)
Description copied from interface: StorageHook
Gets called by a base data during BundleData.setStatus(int). A base data will call this method for each configured storage hook it is associated with until one storage hook returns true. If all configured storage hooks return false then the BaseData will be marked dirty and will cause the status to be persistently saved.

Specified by:
forgetStatusChange in interface StorageHook
Parameters:
status - the new status of the base data
Returns:
false if the status is not to be persistently saved; otherwise true is returned

forgetStartLevelChange

public boolean forgetStartLevelChange(int startlevel)
Description copied from interface: StorageHook
Gets called by a base data during BundleData.setStartLevel(int). A base data will call this method for each configured storage hook it is associated with until one storage hook returns true. If all configured storage hooks return false then the BaseData will be marked dirty and will cause the start level to be persistently saved.

Specified by:
forgetStartLevelChange in interface StorageHook
Parameters:
startlevel - the new startlevel of the base data
Returns:
false if the startlevel is not to be persistently saved; otherwise true is returned

initialize

public void initialize(BaseAdaptor adaptor)
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.initialize(EventPublisher). This method allows an adaptor hook to save the adaptor object for later.

Specified by:
initialize in interface AdaptorHook
Parameters:
adaptor - the adaptor object associated with this AdaptorHook.

frameworkStart

public void frameworkStart(BundleContext context)
                    throws BundleException
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.frameworkStart(BundleContext). This method allows an adaptor hook to execute code when the framework is starting (e.g. to register services).

Specified by:
frameworkStart in interface AdaptorHook
Parameters:
context - the system bundle context
Throws:
BundleException

frameworkStop

public void frameworkStop(BundleContext context)
                   throws BundleException
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.frameworkStop(BundleContext). This method allows an adaptor hook to execute code when the framework is stopped (e.g. to unregister services).

Specified by:
frameworkStop in interface AdaptorHook
Parameters:
context - the system bundle context
Throws:
BundleException

frameworkStopping

public void frameworkStopping(BundleContext context)
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.frameworkStopping(BundleContext). This method allows an adaptor hook to execute code when the framework is about to start the shutdown process.

Specified by:
frameworkStopping in interface AdaptorHook
Parameters:
context - the system bundle context

addProperties

public void addProperties(Properties properties)
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.getProperties(). This method allows an adaptor hook to add property values to the adaptor properties object.

Specified by:
addProperties in interface AdaptorHook
Parameters:
properties - the adaptor properties object.

mapLocationToURLConnection

public URLConnection mapLocationToURLConnection(String location)
                                         throws IOException
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.mapLocationToURLConnection(String). The adaptor will call this method for each configured adaptor hook until one adaptor hook returns a non-null value. If no adaptor hook returns a non-null value then the adaptor will perform the default behavior.

Specified by:
mapLocationToURLConnection in interface AdaptorHook
Parameters:
location - a bundle location string to be converted to a URLConnection
Returns:
the URLConnection converted from the bundle location or null.
Throws:
IOException - if an error occured creating the URLConnection

handleRuntimeError

public void handleRuntimeError(Throwable error)
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.handleRuntimeError(Throwable). The adaptor will call this method for each configured adaptor hook.

Specified by:
handleRuntimeError in interface AdaptorHook
Parameters:
error - the unexpected error that occured.

createFrameworkLog

public FrameworkLog createFrameworkLog()
Description copied from interface: AdaptorHook
Gets called by the adaptor during FrameworkAdaptor.getFrameworkLog(). The adaptor will call this method for each configured adaptor hook until one adaptor hook returns a non-null value. If no adaptor hook returns a non-null value then the adaptor will return null.

Specified by:
createFrameworkLog in interface AdaptorHook
Returns:
a FrameworkLog object or null.

getStorage

public BaseStorage getStorage()

substituteVars

public static String substituteVars(String path)


Copyright © 2007–2014 The Apache Software Foundation. All rights reserved.