livespace.osgi.bootstrap
Class BootstrapUtils

java.lang.Object
  extended by livespace.osgi.bootstrap.BootstrapUtils

public final class BootstrapUtils
extends Object

This class is mainly copies of methods from DFC and livespace.osgi that the bootstrap system can't use directly due to it, well, needing to bootstrap this stuff in the first place.


Method Summary
static void cache(URL sourceUrl, File targetFile)
          Cache a file from a source URL to a local file.
static File cacheBundle(URL remoteBundleUrl)
          Caches a remote bundle and returns a reference to the cached bundle.
static void copy(String sourceUrl, File targetFile)
           
static void diagnostic(String message)
           
static void error(String message)
           
static void error(String message, Throwable ex)
           
static String expandSymbols(String str, Map<String,String> symbols)
          Copied from StringUtility.expandSymbols(String, Map).
static String expandSymbols(String str, Map<String,String> symbols, String symbolPrefixes, boolean useDelimeters)
          Copied from StringUtility.expandSymbols(String, Map, String, boolean).
static URL getBundleURL(String bundleName)
          Gets the full URL to the bundle in the bundle repository.
static String getShortHostName()
          Orginally from OsgiUtil.getShortHostName().
static int indexOfChar(String str, String chars)
          Copied from StringUtility.indexOfChar(String, String).
static int indexOfChar(String str, String chars, int start)
          Copied from StringUtility.indexOfChar(String, String, int).
static void info(String message)
           
static org.osgi.framework.Bundle installBundle(org.osgi.framework.BundleContext bundleContext, String bundleName, int bundleStartlevel)
          Install a bundle from the bundle repository.
static boolean isRemoteUrl(String url)
           
static org.osgi.framework.Bundle istartBundle(org.osgi.framework.BundleContext bundleContext, String bundleName, int bundleStartlevel)
          Installs and starts a bundle from the bundle repository.
static String join(Object[] objects)
          Copy of StringUtility.join(Object[], String).
static Properties loadProperties(String url)
           
static Properties loadProperties(URL url)
           
static Properties loadProperties(URL url, Properties properties)
           
static InputStream openUrl(URL url)
          Copied from OsgiUtil.openUrl(URL).
static String readScriptLine(Reader input)
          Copied from Files.readScriptLine(Reader).
static String requiredProperty(Properties properties, String property)
           
static String requiredProperty(String property)
           
static URL toUrl(String path)
           
static String urlPrefix(String path)
           
static void warn(String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

expandSymbols

public static String expandSymbols(String str,
                                   Map<String,String> symbols)
Copied from StringUtility.expandSymbols(String, Map). Expand symbolic variables embedded within a string. Each occurrence of a variable such as ${var} (alternatively can use

Parameters:
str - The string to expand.
symbols - The symbol definitions.
Returns:
The expanded string.

expandSymbols

public static String expandSymbols(String str,
                                   Map<String,String> symbols,
                                   String symbolPrefixes,
                                   boolean useDelimeters)
Copied from StringUtility.expandSymbols(String, Map, String, boolean). Expand symbolic variables embedded within a string. Each occurrence of a variable such as ${var} in the string will be expanded to the result of symbols.get ("var") or "" if var is not defined in the property set.

Parameters:
str - The string to expand.
symbols - The symbol definitions.
symbolPrefixes - The set of character prefixes that variables may begin with (eg "$%").
useDelimeters - True if {}'s are allowed as symbol name delimeters, allowing multi-character names. When true, single character symbols may still be specified without {}'s.
Returns:
The expanded string.

indexOfChar

public static int indexOfChar(String str,
                              String chars)
Copied from StringUtility.indexOfChar(String, String). Return the first character index in a string that is one of a specified set of characters.

Parameters:
str - The string to search.
chars - The set of characters to match.
Returns:
The first index of one of chars in str, or -1 if no match.
See Also:
indexOfChar(String, String, int)

indexOfChar

public static int indexOfChar(String str,
                              String chars,
                              int start)
Copied from StringUtility.indexOfChar(String, String, int). Return the first character index in a string that is one of a specified set of characters.

Parameters:
str - The string to search.
chars - The set of characters to match.
start - The starting index to search from.
Returns:
The first index of one of chars in str, or -1 if no match.

readScriptLine

public static String readScriptLine(Reader input)
                             throws IOException
Copied from Files.readScriptLine(Reader). Read the next line from a "script-like stream", where script-like streams are line-oriented text streams with "#" comments and \ as a line-continuation operator, similar to Bourne shell scripts and Java .property files. White space at the start and end of the line is ignored, as are lines starting with "#".

Parameters:
input - The input stream.
Returns:
The next line read (will never be "") or null if at end of stream.
Throws:
IOException - if an error occurs reading the stream.

info

public static void info(String message)

diagnostic

public static void diagnostic(String message)

error

public static void error(String message)

error

public static void error(String message,
                         Throwable ex)

warn

public static void warn(String message)

loadProperties

public static Properties loadProperties(String url)
                                 throws IOException
Throws:
IOException

loadProperties

public static Properties loadProperties(URL url)
                                 throws IOException
Throws:
IOException

loadProperties

public static Properties loadProperties(URL url,
                                        Properties properties)
                                 throws IOException
Throws:
IOException

copy

public static void copy(String sourceUrl,
                        File targetFile)
                 throws IOException
Throws:
IOException

requiredProperty

public static String requiredProperty(String property)

requiredProperty

public static String requiredProperty(Properties properties,
                                      String property)
                               throws InvalidPropertyException
Throws:
InvalidPropertyException

toUrl

public static URL toUrl(String path)

isRemoteUrl

public static boolean isRemoteUrl(String url)

urlPrefix

public static String urlPrefix(String path)

openUrl

public static InputStream openUrl(URL url)
                           throws IOException
Copied from OsgiUtil.openUrl(URL). Open an input stream on a URL. Adds some logic to generate a FileNotFoundException for HTTP 404's.

Throws:
IOException

getShortHostName

public static String getShortHostName()
                               throws IOException,
                                      UnknownHostException
Orginally from OsgiUtil.getShortHostName(). This version always returns the host name minus the domain, since it's always used in a local context to reolve which config files apply to the host.

Throws:
IOException
UnknownHostException

join

public static String join(Object[] objects)
Copy of StringUtility.join(Object[], String).


installBundle

public static org.osgi.framework.Bundle installBundle(org.osgi.framework.BundleContext bundleContext,
                                                      String bundleName,
                                                      int bundleStartlevel)
                                               throws FileNotFoundException,
                                                      IOException,
                                                      org.osgi.framework.BundleException
Install a bundle from the bundle repository. If the system property "livespace.osgi.forceCache" is set to true, the caching system will be enabled even if we could use a local bundle repository: this is mainly useful for testing the caching system.

Parameters:
bundleContext - A valid bundle context.
bundleName - The bundle name (this should include the version number if the bundle is not the default version)
bundleStartlevel - The startlevel of the bundle.
Returns:
The installed Bundle
Throws:
FileNotFoundException - If the bundle is not found in the bundle repository.
IOException
org.osgi.framework.BundleException - If there is an error installing the bundle.

istartBundle

public static org.osgi.framework.Bundle istartBundle(org.osgi.framework.BundleContext bundleContext,
                                                     String bundleName,
                                                     int bundleStartlevel)
                                              throws FileNotFoundException,
                                                     IOException,
                                                     org.osgi.framework.BundleException
Installs and starts a bundle from the bundle repository.

Parameters:
bundleContext - A valid bundle context.
bundleName - The bundle name (this should include the version number if the bundle is not the default version)
bundleStartlevel - The startlevel of the bundle.
Returns:
The installed Bundle
Throws:
FileNotFoundException - If the bundle is not found in the bundle repository.
IOException
org.osgi.framework.BundleException - If there is an error installing the bundle.

getBundleURL

public static URL getBundleURL(String bundleName)
Gets the full URL to the bundle in the bundle repository.

Parameters:
bundleName - The name of the bundle, including the version number if it is not the default version.
Returns:
The full URL to the bundle location in the bundle repository.

cacheBundle

public static File cacheBundle(URL remoteBundleUrl)
                        throws IOException
Caches a remote bundle and returns a reference to the cached bundle.

This will check if a matching bundle already exists in the cache and if so will download an updated version of the bundle if the remote bundle has been changed. If the cached bundle is the same as the remote bundle then the remote bundle will not be downloaded and the cached copy will be used.

Parameters:
remoteBundleUrl - the URL of the remote bundle
Returns:
a cached (local) copy of the remote bundle
Throws:
IOException - if a problem occurs copying the remote bundle

cache

public static void cache(URL sourceUrl,
                         File targetFile)
                  throws IOException
Cache a file from a source URL to a local file. Does not copy if local file is up to date.

Parameters:
sourceUrl - An HTTP URL pointing to the source file.
targetFile - The file to copy to.
Throws:
IOException


Copyright © 2008 Commonwealth of Australia