org.eclipse.osgi.internal.resolver
Class StateImpl

java.lang.Object
  extended by org.eclipse.osgi.internal.resolver.StateImpl
All Implemented Interfaces:
State
Direct Known Subclasses:
SystemState, UserState

public abstract class StateImpl
extends java.lang.Object
implements State


Field Summary
static java.lang.String[] PROPS
           
 
Constructor Summary
protected StateImpl()
           
 
Method Summary
 boolean addBundle(BundleDescription description)
          Adds the given bundle to this state.
 void addDisabledInfo(DisabledInfo disabledInfo)
          Adds the disabled info to this state.
 void addResolverError(BundleDescription bundle, int type, java.lang.String data, VersionConstraint unsatisfied)
          Adds a new ResolverError for the specified bundle.
 boolean dynamicCacheChanged()
           
 void fullyLoad()
           
 BundleDescription getBundle(long id)
          Returns the bundle descriptor for the bundle with the given id.
 BundleDescription getBundle(java.lang.String name, Version version)
          Returns the bundle descriptor for the bundle with the given name and version.
 BundleDescription getBundleByLocation(java.lang.String location)
          Returns the bundle descriptor for the bundle with the given location identifier.
 BundleDescription[] getBundles()
          Returns descriptions for all bundles known to this state.
 BundleDescription[] getBundles(java.lang.String symbolicName)
          Returns all bundle descriptions with the given bundle symbolic name.
 StateDelta getChanges()
          Returns the delta representing the changes from the time this state was first captured until now.
 BundleDescription[] getDisabledBundles()
          Returns an array of BundleDescriptions for the bundles that are disabled in the system.
 DisabledInfo getDisabledInfo(BundleDescription bundle, java.lang.String policyName)
          Returns the disabled info for the specified bundle with the specified policy name.
 DisabledInfo[] getDisabledInfos(BundleDescription bundle)
          Returns an array of disabled info for the specified bundle.
 ExportPackageDescription[] getExportedPackages()
          Returns all exported packages in this state, according to the OSGi rules for resolution.
 StateObjectFactory getFactory()
          Returns the factory that created this state.
 long getHighestBundleId()
          Returns the highest bundle ID.
 java.util.Dictionary[] getPlatformProperties()
          Returns the list of platform properties currently set for this state.
 BundleDescription[] getRemovalPendings()
          Returns the latest versions BundleDescriptions which have old removal pending versions.
 BundleDescription[] getResolvedBundles()
          Returns descriptions for all bundles currently resolved in this state.
 Resolver getResolver()
          Returns the resolver associated with this state.
 ResolverError[] getResolverErrors(BundleDescription bundle)
          Returns all ResolverErrors for the given bundle
 StateHelper getStateHelper()
          Returns a state helper object.
 java.lang.String getSystemBundle()
           
 ExportPackageDescription[] getSystemPackages()
          Returns the list of system packages which are exported by the system bundle.
 long getTimeStamp()
          Returns the timestamp for this state.
 boolean isEmpty()
          Returns whether this state is empty.
 boolean isResolved()
          Returns true if there have been no modifications to this state since the last time resolve() was called.
 ExportPackageDescription linkDynamicImport(BundleDescription importingBundle, java.lang.String requestedPackage)
          Attempts to find an ExportPackageDescription that will satisfy a dynamic import for the specified requestedPackage for the specified importingBundle.
 boolean removeBundle(BundleDescription toRemove)
          Removes the given bundle description.
 BundleDescription removeBundle(long bundleId)
          Removes a bundle description with the given bundle id.
 void removeBundleComplete(BundleDescription bundle)
          Sets the given removal pending bundle to removal complete for this state.
 void removeDisabledInfo(DisabledInfo disabledInfo)
          Removes the disabled info from the state.
 void removeResolverErrors(BundleDescription bundle)
          Removes all ResolverErrors for the specified bundle.
 StateDelta resolve()
          Same as State.resolve(true);
 StateDelta resolve(boolean incremental)
          Resolves the constraints contained in this state using the resolver currently associated with the state and returns a delta describing the changes in resolved states and dependencies in the state.
 StateDelta resolve(BundleDescription[] reResolve)
          Resolves the constraints contained in this state using the resolver currently associated with the state in a incremental, "least-perturbing" mode, and returns a delta describing the changes in resolved states and dependencies in the state.
 void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports)
          Sets whether or not the given bundle is selected in this state.
 void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports)
          Sets whether or not the given bundle is selected in this state.
 void resolveConstraint(VersionConstraint constraint, BaseDescription supplier)
          Resolves the given version constraint with the given supplier.
 void setNativePathsInvalid(NativeCodeDescription nativeCodeDescription, boolean hasInvalidNativePaths)
          Sets the native code paths of a native code description as invalid.
 void setOverrides(java.lang.Object value)
          Sets the version overrides which are to be applied during the resolutoin of this state.
 boolean setPlatformProperties(java.util.Dictionary platformProperties)
          Sets the platform properties of the state.
 boolean setPlatformProperties(java.util.Dictionary[] platformProperties)
          Sets the platform properties of the state to a list of platform properties.
 void setResolver(Resolver newResolver)
          Sets the resolver associated with this state.
 void setTimeStamp(long newTimeStamp)
          Sets the timestamp for this state
 void unloadLazyData()
           
 boolean updateBundle(BundleDescription newDescription)
          Updates an existing bundle description with the given description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.osgi.service.resolver.State
compare
 

Field Detail

PROPS

public static final java.lang.String[] PROPS
Constructor Detail

StateImpl

protected StateImpl()
Method Detail

addBundle

public boolean addBundle(BundleDescription description)
Description copied from interface: State
Adds the given bundle to this state.

If the bundle already exists in another state then an IllegalStateException will be thrown. Note that even if you remove a BundleDescription from one State object using State.removeBundle(BundleDescription) it may still be considered as removing pending if other bundles in that state depend on the bundle you removed. To complete a pending removal a call must be done to State.resolve(BundleDescription[]) with the removed bundle.

Specified by:
addBundle in interface State
Parameters:
description - the description to add
Returns:
a boolean indicating whether the bundle was successfully added

updateBundle

public boolean updateBundle(BundleDescription newDescription)
Description copied from interface: State
Updates an existing bundle description with the given description.

Specified by:
updateBundle in interface State
Parameters:
newDescription - the bundle description to replace an existing one
Returns:
true, if if the bundle description was updated, false otherwise

removeBundle

public BundleDescription removeBundle(long bundleId)
Description copied from interface: State
Removes a bundle description with the given bundle id.

Specified by:
removeBundle in interface State
Parameters:
bundleId - the id of the bundle description to be removed
Returns:
the removed bundle description, or null, if a bundle with the given id does not exist in this state

removeBundle

public boolean removeBundle(BundleDescription toRemove)
Description copied from interface: State
Removes the given bundle description.

Specified by:
removeBundle in interface State
Parameters:
toRemove - the bundle description to be removed
Returns:
true, if if the bundle description was removed, false otherwise

getChanges

public StateDelta getChanges()
Description copied from interface: State
Returns the delta representing the changes from the time this state was first captured until now.

Specified by:
getChanges in interface State
Returns:
the state delta

getBundles

public BundleDescription[] getBundles(java.lang.String symbolicName)
Description copied from interface: State
Returns all bundle descriptions with the given bundle symbolic name.

Specified by:
getBundles in interface State
Parameters:
symbolicName - symbolic name of the bundles to query
Returns:
the descriptors for all bundles known to this state with the specified symbolic name.

getBundles

public BundleDescription[] getBundles()
Description copied from interface: State
Returns descriptions for all bundles known to this state.

Specified by:
getBundles in interface State
Returns:
the descriptions for all bundles known to this state.

getBundle

public BundleDescription getBundle(long id)
Description copied from interface: State
Returns the bundle descriptor for the bundle with the given id. null is returned if no such bundle is found in this state.

Specified by:
getBundle in interface State
Returns:
the descriptor for the identified bundle
See Also:
BundleDescription.getBundleId()

getBundle

public BundleDescription getBundle(java.lang.String name,
                                   Version version)
Description copied from interface: State
Returns the bundle descriptor for the bundle with the given name and version. A null value is returned if no such bundle is found in this state. A resolved bundle is always preferably returned over an unresolved bundle. If multiple bundles with the same resolution state are available, the bundle with the highest version number is returned if the version is null.

Specified by:
getBundle in interface State
Parameters:
name - symbolic name of the bundle to query
version - version of the bundle to query. null matches any bundle
Returns:
the descriptor for the identified bundle

getTimeStamp

public long getTimeStamp()
Description copied from interface: State
Returns the timestamp for this state. This correlates this timestamp to the system state. For example, if the system state timestamp is 4 but then some bundles are installed, the system state timestamp is updated. By comparing 4 to the current system state timestamp it is possible to detect if the states are out of sync.

Specified by:
getTimeStamp in interface State
Returns:
the timestamp of this state

isResolved

public boolean isResolved()
Description copied from interface: State
Returns true if there have been no modifications to this state since the last time resolve() was called.

Specified by:
isResolved in interface State
Returns:
whether or not this state has changed since last resolved.

resolveConstraint

public void resolveConstraint(VersionConstraint constraint,
                              BaseDescription supplier)
Description copied from interface: State
Resolves the given version constraint with the given supplier. The given constraint object is destructively modified to reflect its new resolved state. Note that a constraint can be unresolved by passing null for the supplier.

This method is intended to be used by resolvers in the process of determining which constraints are satisfied by which components.

Specified by:
resolveConstraint in interface State
Parameters:
constraint - the version constraint to update
supplier - the supplier which satisfies the constraint. May be null if the constraint is to be unresolved.

resolveBundle

public void resolveBundle(BundleDescription bundle,
                          boolean status,
                          BundleDescription[] hosts,
                          ExportPackageDescription[] selectedExports,
                          BundleDescription[] resolvedRequires,
                          ExportPackageDescription[] resolvedImports)
Description copied from interface: State
Sets whether or not the given bundle is selected in this state.

This method is intended to be used by resolvers in the process of determining which constraints are satisfied by which components.

Specified by:
resolveBundle in interface State
Parameters:
bundle - the bundle to update
status - whether or not the given bundle is resolved, if false the other parameters are ignored
hosts - the host for the resolve fragment, can be null
selectedExports - the selected exported packages for this resolved bundle, can be null
resolvedRequires - the BundleDescriptions that resolve the required bundles for this bundle, can be null
resolvedImports - the exported packages that resolve the imports for this bundle, can be null

resolveBundle

public void resolveBundle(BundleDescription bundle,
                          boolean status,
                          BundleDescription[] hosts,
                          ExportPackageDescription[] selectedExports,
                          ExportPackageDescription[] substitutedExports,
                          BundleDescription[] resolvedRequires,
                          ExportPackageDescription[] resolvedImports)
Description copied from interface: State
Sets whether or not the given bundle is selected in this state.

This method is intended to be used by resolvers in the process of determining which constraints are satisfied by which components.

Specified by:
resolveBundle in interface State
Parameters:
bundle - the bundle to update
status - whether or not the given bundle is resolved, if false the other parameters are ignored
hosts - the host for the resolve fragment, can be null
selectedExports - the selected exported packages for this resolved bundle, can be null
substitutedExports - the exported packages that resolve imports for this bundle and substitute exports, can be null
resolvedRequires - the BundleDescriptions that resolve the required bundles for this bundle, can be null
resolvedImports - the exported packages that resolve the imports for this bundle, can be null

removeBundleComplete

public void removeBundleComplete(BundleDescription bundle)
Description copied from interface: State
Sets the given removal pending bundle to removal complete for this state.

This method is intended to be used by resolvers in the process of resolving bundles.

Specified by:
removeBundleComplete in interface State
Parameters:
bundle - the bundle to set a removal complete.

resolve

public StateDelta resolve()
Description copied from interface: State
Same as State.resolve(true);

Specified by:
resolve in interface State

resolve

public StateDelta resolve(boolean incremental)
Description copied from interface: State
Resolves the constraints contained in this state using the resolver currently associated with the state and returns a delta describing the changes in resolved states and dependencies in the state.

Note that this method is typically implemented using

  this.getResolver().resolve();
 
and is the preferred path for invoking resolution. In particular, states should refuse to perform updates (@see #select() and #resolveConstraint()) if they are not currently involved in a resolution cycle.

Note the given state is destructively modified to reflect the results of resolution.

Specified by:
resolve in interface State
Parameters:
incremental - a flag controlling whether resolution should be incremental
Returns:
a delta describing the changes in resolved state and interconnections

resolve

public StateDelta resolve(BundleDescription[] reResolve)
Description copied from interface: State
Resolves the constraints contained in this state using the resolver currently associated with the state in a incremental, "least-perturbing" mode, and returns a delta describing the changes in resolved states and dependencies in the state.

Specified by:
resolve in interface State
Parameters:
reResolve - an array containing descriptions for bundles whose current resolution state should be forgotten. If null then all the current removal pending BundleDescriptions are refreshed.
Returns:
a delta describing the changes in resolved state and interconnections

setOverrides

public void setOverrides(java.lang.Object value)
Description copied from interface: State
Sets the version overrides which are to be applied during the resolutoin of this state. Version overrides allow external forces to refine/override the version constraints setup by the components in the state.

Specified by:
setOverrides in interface State

getResolvedBundles

public BundleDescription[] getResolvedBundles()
Description copied from interface: State
Returns descriptions for all bundles currently resolved in this state.

Specified by:
getResolvedBundles in interface State
Returns:
the descriptions for all bundles currently resolved in this state.

isEmpty

public boolean isEmpty()
Description copied from interface: State
Returns whether this state is empty.

Specified by:
isEmpty in interface State
Returns:
true if this state is empty, false otherwise

getExportedPackages

public ExportPackageDescription[] getExportedPackages()
Description copied from interface: State
Returns all exported packages in this state, according to the OSGi rules for resolution.

Specified by:
getExportedPackages in interface State
See Also:
PackageAdmin.getExportedPackages(org.osgi.framework.Bundle)

setTimeStamp

public void setTimeStamp(long newTimeStamp)
Description copied from interface: State
Sets the timestamp for this state

Specified by:
setTimeStamp in interface State
Parameters:
newTimeStamp - the new timestamp for this state

getFactory

public StateObjectFactory getFactory()
Description copied from interface: State
Returns the factory that created this state.

Specified by:
getFactory in interface State
Returns:
the state object factory that created this state

getBundleByLocation

public BundleDescription getBundleByLocation(java.lang.String location)
Description copied from interface: State
Returns the bundle descriptor for the bundle with the given location identifier. null is returned if no such bundle is found in this state.

Specified by:
getBundleByLocation in interface State
Parameters:
location - location identifier of the bundle to query
Returns:
the descriptor for the identified bundle

getResolver

public Resolver getResolver()
Description copied from interface: State
Returns the resolver associated with this state. A state can work with at most one resolver at any given time. Similarly, a resolver can work with at most one state at a time.

Specified by:
getResolver in interface State
Returns:
the resolver for this state. null is returned if the state does not have a resolver

setResolver

public void setResolver(Resolver newResolver)
Description copied from interface: State
Sets the resolver associated with this state. A state can work with at most one resolver at any given time. Similarly, a resolver can work with at most one state at a time.

To ensure that this state and the given resovler are properly linked, the following expression must be included in this method if the given resolver (value) is not identical to the result of this.getResolver().

  if (this.getResolver() != value) value.setState(this);
 

Specified by:
setResolver in interface State

setPlatformProperties

public boolean setPlatformProperties(java.util.Dictionary platformProperties)
Description copied from interface: State
Sets the platform properties of the state. The platform properties are used to resolve the following constraints:
  • The execution environment requirements (i.e. Bundle-RequiredExecutionEnvironment).
  • The platform filter requirements (i.e. Eclipse-PlatformFilter).
  • The native code requirements (i.e. Bundle-NativeCode).
Arbitrary keys may be used in the platform properties but the following keys have a specified meaning:
  • osgi.nl - the platform language setting.
  • osgi.os - the platform operating system.
  • osgi.arch - the platform architecture.
  • osgi.ws - the platform windowing system.
  • osgi.resolverMode - the resolver mode. A value of "strict" will set the resolver mode to strict.
  • org.osgi.framework.system.packages - the packages exported by the system bundle.
  • org.osgi.framework.executionenvironment - the comma separated list of supported execution environments. This property is then used to resolve the required execution environment the bundles in a state.
  • org.osgi.framework.os.name - the name of the operating system. This property is used to resolve the osname attribute of bundle native code (i.e. Bundle-NativeCode).
  • org.osgi.framework.os.version - the version of the operating system. This property is used to resolve the osversion attribute of bundle native code (i.e. Bundle-NativeCode).
  • org.osgi.framework.processor - the processor name. This property is used to resolve the processor attribute of bundle native code (i.e. Bundle-NativeCode).
  • org.osgi.framework.language - the language being used. This property is used to resolve the language attribute of bundle native code (i.e. Bundle-NativeCode).

The values used for the supported properties can be String type to specify a single value for the property or they can by String[] to specify a list of values for the property.

Specified by:
setPlatformProperties in interface State
Parameters:
platformProperties - the platform properties of the state
Returns:
false if the platformProperties specified do not change any of the supported properties already set. If any of the supported property values are changed as a result of calling this method then true is returned.

setPlatformProperties

public boolean setPlatformProperties(java.util.Dictionary[] platformProperties)
Description copied from interface: State
Sets the platform properties of the state to a list of platform properties.

Specified by:
setPlatformProperties in interface State
Parameters:
platformProperties - a set of platform properties for the state
Returns:
false if the platformProperties specified do not change any of the supported properties already set. If any of the supported property values are changed as a result of calling this method then true is returned.
See Also:
State.setPlatformProperties(Dictionary)

getPlatformProperties

public java.util.Dictionary[] getPlatformProperties()
Description copied from interface: State
Returns the list of platform properties currently set for this state.

Specified by:
getPlatformProperties in interface State
Returns:
the list of platform properties currently set for this state.

getSystemBundle

public java.lang.String getSystemBundle()

getRemovalPendings

public BundleDescription[] getRemovalPendings()
Returns the latest versions BundleDescriptions which have old removal pending versions.

Returns:
the BundleDescriptions that have removal pending versions.

linkDynamicImport

public ExportPackageDescription linkDynamicImport(BundleDescription importingBundle,
                                                  java.lang.String requestedPackage)
Description copied from interface: State
Attempts to find an ExportPackageDescription that will satisfy a dynamic import for the specified requestedPackage for the specified importingBundle. If no ExportPackageDescription is available that satisfies a dynamic import for the importingBundle then null is returned.

Specified by:
linkDynamicImport in interface State
Parameters:
importingBundle - the BundleDescription that is requesting a dynamic package
requestedPackage - the name of the package that is being requested
Returns:
the ExportPackageDescription that satisfies the dynamic import request; a value of null is returned if none is available.

fullyLoad

public final void fullyLoad()

unloadLazyData

public final void unloadLazyData()

getSystemPackages

public ExportPackageDescription[] getSystemPackages()
Description copied from interface: State
Returns the list of system packages which are exported by the system bundle. The list of system packages is set by the org.osgi.framework.system.packages value in the platform properties for this state.

Specified by:
getSystemPackages in interface State
Returns:
the list of system packages
See Also:
State.setPlatformProperties(Dictionary)

getResolverErrors

public ResolverError[] getResolverErrors(BundleDescription bundle)
Description copied from interface: State
Returns all ResolverErrors for the given bundle

Specified by:
getResolverErrors in interface State
Parameters:
bundle - the bundle to get all ResolverErrors for
Returns:
all ResolverErrors for the given bundle

addResolverError

public void addResolverError(BundleDescription bundle,
                             int type,
                             java.lang.String data,
                             VersionConstraint unsatisfied)
Description copied from interface: State
Adds a new ResolverError for the specified bundle.

This method is intended to be used by resolvers in the process of resolving.

Specified by:
addResolverError in interface State
Parameters:
bundle - the bundle to add a new ResolverError for
type - the type of ResolverError to add
data - the data for the ResolverError
unsatisfied - the unsatisfied constraint or null if the resolver error was not caused by an unsatisfied constraint.

removeResolverErrors

public void removeResolverErrors(BundleDescription bundle)
Description copied from interface: State
Removes all ResolverErrors for the specified bundle.

This method is intended to be used by resolvers in the process of resolving.

Specified by:
removeResolverErrors in interface State
Parameters:
bundle - the bundle to remove all ResolverErrors for

dynamicCacheChanged

public boolean dynamicCacheChanged()

getStateHelper

public StateHelper getStateHelper()
Description copied from interface: State
Returns a state helper object. State helpers provide convenience methods for manipulating states.

A possible implementation for this method would provide the same single StateHelper instance to all clients.

Specified by:
getStateHelper in interface State
Returns:
a state helper
See Also:
StateHelper

getHighestBundleId

public long getHighestBundleId()
Description copied from interface: State
Returns the highest bundle ID. The value -1 is returned if no bundles exist in this state.

Note that this method returns the highest bundle ID the ever existed in this this state object. This bundle may have been removed from the state.

Specified by:
getHighestBundleId in interface State
Returns:
the highest bundle ID.

setNativePathsInvalid

public void setNativePathsInvalid(NativeCodeDescription nativeCodeDescription,
                                  boolean hasInvalidNativePaths)
Description copied from interface: State
Sets the native code paths of a native code description as invalid. Native code paths are invalid if they can not be found in the bundle content.

The framework, or some other entity which has access to bundle content, will call this method to validate or invalidate native code paths.

Specified by:
setNativePathsInvalid in interface State
Parameters:
nativeCodeDescription - the native code description.
hasInvalidNativePaths - true if the native code paths are invalid; false otherwise.

getDisabledBundles

public BundleDescription[] getDisabledBundles()
Description copied from interface: State
Returns an array of BundleDescriptions for the bundles that are disabled in the system. Use State.getDisabledInfos(BundleDescription) to interrogate the reason that each bundle is disabled.

Specified by:
getDisabledBundles in interface State
Returns:
the array of disabled bundles. An empty array is returned if no bundles are disabled.
See Also:
DisabledInfo

addDisabledInfo

public void addDisabledInfo(DisabledInfo disabledInfo)
Description copied from interface: State
Adds the disabled info to this state. If a disable info already exists for the specified policy and the specified bundle then it is replaced with the given disabled info.

Specified by:
addDisabledInfo in interface State
Parameters:
disabledInfo - the disabled info to add.

removeDisabledInfo

public void removeDisabledInfo(DisabledInfo disabledInfo)
Description copied from interface: State
Removes the disabled info from the state.

Specified by:
removeDisabledInfo in interface State
Parameters:
disabledInfo - the disabled info to remove

getDisabledInfo

public DisabledInfo getDisabledInfo(BundleDescription bundle,
                                    java.lang.String policyName)
Description copied from interface: State
Returns the disabled info for the specified bundle with the specified policy name. If no disabled info exists then null is returned.

Specified by:
getDisabledInfo in interface State
Parameters:
bundle - the bundle to get the disabled info for
Returns:
the disabled info.

getDisabledInfos

public DisabledInfo[] getDisabledInfos(BundleDescription bundle)
Description copied from interface: State
Returns an array of disabled info for the specified bundle. If no disabled info exist then an empty array is returned.

Specified by:
getDisabledInfos in interface State
Parameters:
bundle - the bundle to get the disabled info for.
Returns:
the array of disabled info.


Copyright © 2007-2012 FuseSource, Corp.. All Rights Reserved.