org.sapia.soto
Class SotoContainer

java.lang.Object
  extended by org.sapia.soto.SotoContainer
All Implemented Interfaces:
SotoConsts

public class SotoContainer
extends java.lang.Object
implements SotoConsts

An intance of this class contains service instances and manages their life-cycle.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software . All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Nested Class Summary
static class SotoContainer.EnvImpl
           
 
Field Summary
 
Fields inherited from interface org.sapia.soto.SotoConsts
SOTO_BOOTSTRAP, SOTO_DEBUG, SOTO_ENV_KEY, SOTO_INCLUDE_KEY, SOTO_LIFE_CYCLE
 
Constructor Summary
SotoContainer()
          Constructor for SotoContainer.
 
Method Summary
 void bind(ServiceMetaData meta)
          Binds the given object to this instance, using the specified identifier.
 void bind(java.lang.String id, java.lang.Object ref)
          Binds an object under a given identifier.
 void dispose()
          Internally shuts down all services and layers.
 SotoApplicationFactory getApplicationFactory()
           
 LifeCycleManager getDefaultLifeCycleManager()
           
 LifeCycleManager getLifeCycleManagerFor(java.lang.String name)
           
 org.sapia.resource.ResourceHandler getResourceHandlerFor(java.lang.String uri)
          Returns the resource handler that corresponds to the given scheme.
 SotoResourceHandlerChain getResourceHandlers()
          Returns the resource handlers held by this instance.
 Settings getSettings()
           
 SotoContainer load(java.io.File f)
          Loads the Soto XML descriptor whose file is given.
 SotoContainer load(java.io.File f, java.util.Map map)
          Loads the Soto XML descriptor whose file is given.
 SotoContainer load(java.io.InputStream is)
          Loads the Soto XML descriptor whose stream is given.
 SotoContainer load(java.io.InputStream is, java.util.Map vars)
          Loads the Soto XML descriptor whose stream is given.
 SotoContainer load(java.lang.String resourceName)
          Loads the Soto XML descriptor whose resource is given.
 SotoContainer load(java.lang.String resourceName, java.util.Map vars)
          Loads the Soto XML descriptor whose resource is given.
 SotoContainer load(java.net.URL url, java.util.Map map)
          Loads the Soto XML descriptor whose URL is given.
 java.lang.Object lookup(java.lang.Class instanceOf)
          Looks up for the object that is an instance of the specified interface.
 java.util.List lookup(ServiceSelector selector, boolean returnMetadata)
          Internally adds the services that have been accepted by the passed in selector and returns them in a list to the caller.
 java.lang.Object lookup(java.lang.String id)
          Looks up for the object identified by the given ID and returns it.
 void registerLifeCycleManager(java.lang.String name, LifeCycleManager manager)
          Registers the given life-cycle manager with this instance.
 java.lang.Object resolveRef(java.lang.String id)
           
 void start()
          Internally starts the services bound to this container.
 Env toEnv()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SotoContainer

public SotoContainer()
Constructor for SotoContainer.

Method Detail

getSettings

public Settings getSettings()
Returns:
this instance's settings.

bind

public void bind(ServiceMetaData meta)
          throws DuplicateException,
                 java.lang.Exception
Binds the given object to this instance, using the specified identifier.

Parameters:
meta - a ServiceMetaData.
Throws:
DuplicateException
java.lang.Exception

bind

public void bind(java.lang.String id,
                 java.lang.Object ref)
Binds an object under a given identifier. That object can be retrieved later on through configuration by using its identifier.

Parameters:
id - an arbitrary identifier.
ref - an Object

resolveRef

public java.lang.Object resolveRef(java.lang.String id)
                            throws NotFoundException
Parameters:
id - the identifier under which the expected object was registered.
Returns:
the Object corresponding to the given identifier.
Throws:
NotFoundException
See Also:
#register(java.lang.String, java.lang.Object)

lookup

public java.lang.Object lookup(java.lang.String id)
                        throws NotFoundException
Looks up for the object identified by the given ID and returns it.

Throws:
NotFoundException - if no object could be found.

lookup

public java.lang.Object lookup(java.lang.Class instanceOf)
                        throws NotFoundException
Looks up for the object that is an instance of the specified interface.

This method is suboptimal: all services are traversed and tested against the specified interface; therefore, this method should not be used to perform repetitive lookups, but to lookup services at initialization time.

Parameters:
instanceOf - an interface, specified as a Class instance.
Throws:
NotFoundException - if no object could be found.

lookup

public java.util.List lookup(ServiceSelector selector,
                             boolean returnMetadata)
Internally adds the services that have been accepted by the passed in selector and returns them in a list to the caller.

Parameters:
selector - a ServiceSelector.
returnMetadata - if true, this instance will return ServiceMetadata instances. Else, it will return Service instances.
Returns:
a List of Service or ServiceMetadata instances.

load

public SotoContainer load(java.io.InputStream is,
                          java.util.Map vars)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose stream is given.

Parameters:
is - an InputStream.
vars - a Map of name/value pairs that can be recuperated in the configuration using the ${varname} notation.
Returns:
this instance.
Throws:
java.lang.Exception

load

public SotoContainer load(java.io.InputStream is)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose stream is given.

Parameters:
is - an InputStream.
Returns:
this instance.
Throws:
java.lang.Exception

load

public SotoContainer load(java.lang.String resourceName,
                          java.util.Map vars)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose resource is given.

Parameters:
resourceName - the name of the classpath resource that contains the configuration.
vars - a Map of name/value pairs that can be recuperated in the configuration using the ${varname} notation.
Returns:
this instance.
Throws:
java.lang.Exception

load

public SotoContainer load(java.lang.String resourceName)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose resource is given.

Parameters:
resourceName - the name of the classpath resource that contains the configuration.
Returns:
this instance.
Throws:
java.lang.Exception

load

public SotoContainer load(java.io.File f,
                          java.util.Map map)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose file is given.

Parameters:
f - a File.
map - a Map of name/value pairs that can be recuperated in the configuration using the ${varname} notation.
Returns:
this instance
Throws:
java.lang.Exception

load

public SotoContainer load(java.net.URL url,
                          java.util.Map map)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose URL is given.

Parameters:
url - an URL.
map - a Map of name/value pairs that can be recuperated in the configuration using the ${varname} notation.
Returns:
this instance
Throws:
java.lang.Exception

load

public SotoContainer load(java.io.File f)
                   throws java.lang.Exception
Loads the Soto XML descriptor whose file is given.

Parameters:
f - a File.
Returns:
this instance.
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Internally starts the services bound to this container.

Throws:
java.lang.Exception
See Also:
Service.start()

dispose

public void dispose()
Internally shuts down all services and layers.

See Also:
Service.dispose(), Layer.dispose()

getResourceHandlers

public SotoResourceHandlerChain getResourceHandlers()
Returns the resource handlers held by this instance. New handlers can be added by client applications.

Returns:
the ResourceHandlerChain that this instance holds.

getResourceHandlerFor

public org.sapia.resource.ResourceHandler getResourceHandlerFor(java.lang.String uri)
Returns the resource handler that corresponds to the given scheme.

Returns:
a ResourceHander.

registerLifeCycleManager

public void registerLifeCycleManager(java.lang.String name,
                                     LifeCycleManager manager)
Registers the given life-cycle manager with this instance.

Parameters:
name - the unique name under which to bind the given LifeCycleManager in this container.
manager - a LifeCycleManager

getLifeCycleManagerFor

public LifeCycleManager getLifeCycleManagerFor(java.lang.String name)
                                        throws java.lang.IllegalArgumentException
Parameters:
name - the name of the LifeCycleManager to return.
Returns:
the LifeCycleManager corresponding to the given name.
Throws:
java.lang.IllegalArgumentException - if no such instance could be found.

getDefaultLifeCycleManager

public LifeCycleManager getDefaultLifeCycleManager()
Returns:
the default life-cycle manager of this container.

getApplicationFactory

public SotoApplicationFactory getApplicationFactory()
Returns:
the SotoApplicationFactory that is used to create objects from an XML configuration.

toEnv

public Env toEnv()
Returns:
the Env instance that corresponds to this container.


Copyright © 2010 Sapia OSS. All Rights Reserved.