org.apache.avalon.repository.main
Class DefaultInitialContextFactory

java.lang.Object
  extended byorg.apache.avalon.repository.main.DefaultInitialContextFactory
All Implemented Interfaces:
InitialContextFactory

public class DefaultInitialContextFactory
extends Object
implements InitialContextFactory

A utility class used to establish a new InitialContext instance. An initial context is normally created by simply instantiating the factory using a application key and a working directory.

 final String key = "demo";
 final File work = new File( System.getProperty( "user.dir" ) );
 final InitialContextFactory factory = 
   new DefaultInitialContextFactory( key, work );
 InitialContext context = factory.createInitialContext();
 

Version:
$Revision: 1.11 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.repository.provider.InitialContextFactory
KEYS
 
Constructor Summary
DefaultInitialContextFactory(String key)
          Creates an initial repository context factory relative to the current working directory.
DefaultInitialContextFactory(String key, File work)
          Creates an initial repository context factory.
 
Method Summary
 InitialContext createInitialContext()
          Creation of an inital context based on the system and working directory, parent classloader, repository cache manager implementation artifact, cache directory, and remote hosts sequence supplied to the factory.
 String getApplicationKey()
          Return the application key.
 File getCacheDirectory()
          Return the assigned or default cache directory.
 File getHomeDirectory()
          Return the home directory value direved from the application key.
 String[] getHosts()
          Return the assigned or default host sequence.
 Artifact getImplementation()
          Return the implementation artifact.
 boolean getOnlineMode()
          Return the application key.
 ClassLoader getParentClassLoader()
          Return the parent classloader.
 String getProxyHost()
          Get the proxy host name.
 String getProxyPassword()
          Set the proxy account password.
 int getProxyPort()
          Get the proxy host port.
 String getProxyUsername()
          Get the proxy username.
 Artifact[] getRegisteredArtifacts()
          Return the registory.
 File getWorkingDirectory()
          Return the working directory value.
 void setCacheDirectory(File cache)
          The cache directory is the directory into which resources such as jar files are loaded by a repository cache manager.
 void setFactoryArtifacts(Artifact[] artifacts)
          Register a set of factory artifacts.
 void setHosts(String[] hosts)
          Set the initial hosts to be used by a repository cache manager implementation and the initial context implementation when resolving dependent resources.
 void setImplementation(Artifact artifact)
          The initial context factory support the establishment of an initial context which is associated with a repository cache manager implementation.
 void setOnlineMode(boolean policy)
          Set the online mode of the repository.
 void setParentClassLoader(ClassLoader classloader)
          Set the parent classloader.
 void setProxyHost(String host)
          Set the proxy host name.
 void setProxyPassword(String password)
          Set the proxy account password.
 void setProxyPort(int port)
          Set the proxy host port.
 void setProxyUsername(String username)
          Set the proxy username.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultInitialContextFactory

public DefaultInitialContextFactory(String key)
                             throws IOException

Creates an initial repository context factory relative to the current working directory. This is equivalent to the following invocation:

   final String key = "demo";
   final File work = new File( System.getProperty( "user.dir" );
   InitialContextFactory factory = 
     new DefaultInitialContextFactory( key, work );
 

Parameters:
key - the application key
Throws:
IOException - if an error occurs during establishment
NullPointerException - if tyhe supplied key is null

DefaultInitialContextFactory

public DefaultInitialContextFactory(String key,
                                    File work)
                             throws IOException

Creates an initial repository context factory. The supplied key is used to establish the application root directory and property files at application, user and working directory levels. A key such as 'merlin' will be transformed to the environment symbol 'MERLIN_HOME' (i.e. uppercase of key plus _HOME) and resolved to a value. If the symbol is undefined, the application home directory defaults to a file path ${user.home}/.[key] (so for example, if MERLIN_HOME is undefined the default application home for Merlin is ${user.home}/.merlin. Based on the application root directory, a set of property files with the name [key].properties are resolved from the following locations:

The order in which properties are evaluated in in accordance the above list. The current working directory properties take precedence over properties defined in the user's home directory which in turn take precedence over properties defined under the application home directory. System properties take precedence over all properties.

Parameters:
key - the application key
work - the working directory
Throws:
IOException - if an error occurs during establishment
NullPointerException - if the supplied key or work arguments are null
Method Detail

setFactoryArtifacts

public void setFactoryArtifacts(Artifact[] artifacts)
Register a set of factory artifacts.

Specified by:
setFactoryArtifacts in interface InitialContextFactory
Parameters:
artifacts - the artifact references

setOnlineMode

public void setOnlineMode(boolean policy)
Set the online mode of the repository. The default policy is to to enable online access to remote repositories. Setting the onLine mode to false disables remote repository access.

Specified by:
setOnlineMode in interface InitialContextFactory
Parameters:
policy - the connected policy

setParentClassLoader

public void setParentClassLoader(ClassLoader classloader)
Set the parent classloader. If not defined, the default classloader is the classloader holding this class.

Specified by:
setParentClassLoader in interface InitialContextFactory
Parameters:
classloader - the parent classloader

setImplementation

public void setImplementation(Artifact artifact)
The initial context factory support the establishment of an initial context which is associated with a repository cache manager implementation. A client can override the default repository cache manager implementation by declaring an artifact referencing a compliant factory (not normally required).

Specified by:
setImplementation in interface InitialContextFactory
Parameters:
artifact - the repository cache manager artifact

setCacheDirectory

public void setCacheDirectory(File cache)
The cache directory is the directory into which resources such as jar files are loaded by a repository cache manager.

Specified by:
setCacheDirectory in interface InitialContextFactory
Parameters:
cache - the repository cache directory

setHosts

public void setHosts(String[] hosts)
Set the initial hosts to be used by a repository cache manager implementation and the initial context implementation when resolving dependent resources. If is resource is not present in a local cache, remote hosts are checked in the order presented in the supplied list. A host may be a file url or a http url.

Specified by:
setHosts in interface InitialContextFactory
Parameters:
hosts - a sequence of remote host urls

setProxyHost

public void setProxyHost(String host)
Set the proxy host name. If not supplied proxy usage will be disabled.

Specified by:
setProxyHost in interface InitialContextFactory
Parameters:
host - the proxy host name

setProxyPort

public void setProxyPort(int port)
Set the proxy host port.

Specified by:
setProxyPort in interface InitialContextFactory
Parameters:
port - the proxy port

setProxyUsername

public void setProxyUsername(String username)
Set the proxy username.

Specified by:
setProxyUsername in interface InitialContextFactory
Parameters:
username - the proxy username

setProxyPassword

public void setProxyPassword(String password)
Set the proxy account password.

Specified by:
setProxyPassword in interface InitialContextFactory
Parameters:
password - the proxy password

createInitialContext

public InitialContext createInitialContext()
Creation of an inital context based on the system and working directory, parent classloader, repository cache manager implementation artifact, cache directory, and remote hosts sequence supplied to the factory.

Specified by:
createInitialContext in interface InitialContextFactory
Returns:
a new initial context

getRegisteredArtifacts

public Artifact[] getRegisteredArtifacts()
Return the registory.


getOnlineMode

public boolean getOnlineMode()
Return the application key.


getApplicationKey

public String getApplicationKey()
Return the application key.


getHomeDirectory

public File getHomeDirectory()
Return the home directory value direved from the application key.

Specified by:
getHomeDirectory in interface InitialContextFactory
Returns:
the home directory.

getWorkingDirectory

public File getWorkingDirectory()
Return the working directory value.

Returns:
the working directory.

getParentClassLoader

public ClassLoader getParentClassLoader()
Return the parent classloader. The default classloader returned from this operation is the classloader containing this class.

Returns:
the parent classloader

getImplementation

public Artifact getImplementation()
Return the implementation artifact. If not overriden, a default artifact referencing avalon-repository-impl will be returned.

Returns:
the implementation artifact

getCacheDirectory

public File getCacheDirectory()
Return the assigned or default cache directory. If undefined the cache directory shall default to ${avalon.home}/repository.

Returns:
the cache directory

getHosts

public String[] getHosts()
Return the assigned or default host sequence.

Returns:
the remote host url sequence

getProxyHost

public String getProxyHost()
Get the proxy host name.

Returns:
the proxy host name

getProxyPort

public int getProxyPort()
Get the proxy host port.

Returns:
the proxy port

getProxyUsername

public String getProxyUsername()
Get the proxy username.

Returns:
the proxy username

getProxyPassword

public String getProxyPassword()
Set the proxy account password.

Returns:
the proxy password


Copyright © The Apache Software Foundation. All Rights Reserved.