org.sapia.soto
Class SotoContainer

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

public class SotoContainer
extends 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
 
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(String id, Object ref)
          Binds an object under a given identifier.
 void dispose()
          Internally shuts down all services and layers.
 SotoApplicationFactory getApplicationFactory()
           
 org.sapia.resource.ResourceHandler getResourceHandlerFor(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(File f)
          Loads the Soto XML descriptor whose file is given.
 SotoContainer load(File f, Map map)
          Loads the Soto XML descriptor whose file is given.
 SotoContainer load(InputStream is)
          Loads the Soto XML descriptor whose stream is given.
 SotoContainer load(InputStream is, Map vars)
          Loads the Soto XML descriptor whose stream is given.
 SotoContainer load(String resourceName)
          Loads the Soto XML descriptor whose resource is given.
 SotoContainer load(String resourceName, Map vars)
          Loads the Soto XML descriptor whose resource is given.
 SotoContainer load(URL url, Map map)
          Loads the Soto XML descriptor whose URL is given.
 Object lookup(Class instanceOf)
          Looks up for the object that is an instance of the specified interface.
 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.
 Object lookup(String id)
          Looks up for the object identified by the given ID and returns it.
 Object resolveRef(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,
                 Exception
Binds the given object to this instance, using the specified identifier.

Parameters:
meta - a ServiceMetaData.
Throws:
DuplicateException
Exception

bind

public void bind(String id,
                 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 Object resolveRef(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 Object lookup(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 Object lookup(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 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(InputStream is,
                          Map vars)
                   throws 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:
Exception

load

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

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

load

public SotoContainer load(String resourceName,
                          Map vars)
                   throws 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:
Exception

load

public SotoContainer load(String resourceName)
                   throws 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:
Exception

load

public SotoContainer load(File f,
                          Map map)
                   throws 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:
Exception

load

public SotoContainer load(URL url,
                          Map map)
                   throws 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:
Exception

load

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

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

start

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

Throws:
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(String uri)
Returns the resource handler that corresponds to the given scheme.

Returns:
a ResourceHander.

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 © 2002-2007 Sapia Open Community, Inc. All Rights Reserved.