gnu.beanfactory
Class BeanContext

java.lang.Object
  |
  +--gnu.beanfactory.BeanContext

public class BeanContext
extends java.lang.Object

BeanContext is the primary public interface to the runtime system.

Version:
$Id: BeanContext.java,v 1.82 2002/04/22 04:21:08 rschoening Exp $
Author:
Rob Schoening <rob@beanfactory.net>

Field Summary
static java.lang.String ANONYMOUS_URL
           
static int APPLICATION_SCOPE_CODE
           
static java.lang.String APPLICATION_SCOPE_NAME
           
static java.lang.String BEANFACTORY_BOOTSTRAP_CONFIGPATH_PROPERTY
           
static java.lang.String BEANFACTORY_BOOTSTRAP_RESOURCE_NAME
           
static java.lang.String BEANFACTORY_CONFIGPATH_PROPERTY
           
static java.lang.String BEANFACTORY_RESOURCE_NAME
           
static int REQUEST_SCOPE_CODE
           
static java.lang.String REQUEST_SCOPE_NAME
           
static int SESSION_SCOPE_CODE
           
static java.lang.String SESSION_SCOPE_NAME
           
static int STATIC_SCOPE_CODE
           
static java.lang.String STATIC_SCOPE_NAME
           
static int THREAD_SCOPE_CODE
           
static java.lang.String THREAD_SCOPE_NAME
           
static int TRANSIENT_SCOPE_CODE
           
static java.lang.String TRANSIENT_SCOPE_NAME
           
static int UNKNOWN_SCOPE_CODE
           
static java.lang.String URL_PREFIX
           
 
Constructor Summary
protected BeanContext()
          Default Constructor
 
Method Summary
 void bindScope()
          Binds the "thread" scope to the calling thread.
 void bindScope(javax.servlet.ServletContext ctx)
           
 void bindScope(javax.servlet.ServletContext ctx, javax.servlet.http.HttpSession ses, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Binds thread, request, session, and application scopes to the calling thread.
 boolean existsInstance(java.lang.String url)
          Returns true if the specified bean already exists in the BeanFactory container.
 java.lang.Object findInstance(java.lang.String url)
          Finds an existing bean in the container.
static BeanContext getBeanContext()
          Please use Container.getBeanContext() instead.
 gnu.beanfactory.BeanFactory getBeanFactory()
          Obtains a reference to the BeanFactory implementation.
 DefinitionLoader getDefinitionLoader()
          Obtains a reference to the DefintionLoader.
static BeanContext getInstance()
          Please use Container.getBeanContext() instead.
 java.lang.Object lookup(java.lang.String url)
          Finds a bean by its URL.
 Handle lookupHandle(java.lang.String url)
          Obtains a handle to a bean reference.
 java.lang.Object newAnonymousInstance(BeanDefinition def)
          Creates an anonymous instance.
 java.lang.Object newAnonymousInstance(java.lang.String parentUrl)
          Creates a new transient instance based on a parent bean.
 java.lang.Object newInstance(BeanDefinition def)
          Deprecated. use newAnonymousInstance instead
 java.lang.Object resolve(java.lang.String url)
          Resolves a nested property into an object.
 void unbindScope()
          Releases all thread-bound scopes from the calling thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEANFACTORY_RESOURCE_NAME

public static final java.lang.String BEANFACTORY_RESOURCE_NAME

BEANFACTORY_BOOTSTRAP_RESOURCE_NAME

public static final java.lang.String BEANFACTORY_BOOTSTRAP_RESOURCE_NAME

BEANFACTORY_CONFIGPATH_PROPERTY

public static final java.lang.String BEANFACTORY_CONFIGPATH_PROPERTY

BEANFACTORY_BOOTSTRAP_CONFIGPATH_PROPERTY

public static final java.lang.String BEANFACTORY_BOOTSTRAP_CONFIGPATH_PROPERTY

APPLICATION_SCOPE_CODE

public static final int APPLICATION_SCOPE_CODE

REQUEST_SCOPE_CODE

public static final int REQUEST_SCOPE_CODE

SESSION_SCOPE_CODE

public static final int SESSION_SCOPE_CODE

THREAD_SCOPE_CODE

public static final int THREAD_SCOPE_CODE

TRANSIENT_SCOPE_CODE

public static final int TRANSIENT_SCOPE_CODE

UNKNOWN_SCOPE_CODE

public static final int UNKNOWN_SCOPE_CODE

STATIC_SCOPE_CODE

public static final int STATIC_SCOPE_CODE

THREAD_SCOPE_NAME

public static final java.lang.String THREAD_SCOPE_NAME

APPLICATION_SCOPE_NAME

public static final java.lang.String APPLICATION_SCOPE_NAME

TRANSIENT_SCOPE_NAME

public static final java.lang.String TRANSIENT_SCOPE_NAME

REQUEST_SCOPE_NAME

public static final java.lang.String REQUEST_SCOPE_NAME

SESSION_SCOPE_NAME

public static final java.lang.String SESSION_SCOPE_NAME

STATIC_SCOPE_NAME

public static final java.lang.String STATIC_SCOPE_NAME

URL_PREFIX

public static java.lang.String URL_PREFIX

ANONYMOUS_URL

public static java.lang.String ANONYMOUS_URL
Constructor Detail

BeanContext

protected BeanContext()
Default Constructor
Method Detail

getBeanFactory

public gnu.beanfactory.BeanFactory getBeanFactory()
Obtains a reference to the BeanFactory implementation. Although this method is public, it should not be used.

getDefinitionLoader

public DefinitionLoader getDefinitionLoader()
                                     throws BeanFactoryException
Obtains a reference to the DefintionLoader.

lookup

public java.lang.Object lookup(java.lang.String url)
                        throws BeanFactoryException
Finds a bean by its URL. The runtime system will first attempt to locate the bean in the context of its defined scope. If an instance already exists, it will be returned. If no such instance exists, it will be constructed, initialized and added to the defined scope after which it will be returned to the caller.
Parameters:
url - Uniform Resource Locator for the bean
Returns:
reference to the bean instance

newAnonymousInstance

public java.lang.Object newAnonymousInstance(BeanDefinition def)
                                      throws BeanFactoryException
Creates an anonymous instance.

newInstance

public java.lang.Object newInstance(BeanDefinition def)
                             throws BeanFactoryException
Deprecated. use newAnonymousInstance instead

Creates an anonymous instance.

newAnonymousInstance

public java.lang.Object newAnonymousInstance(java.lang.String parentUrl)
                                      throws BeanFactoryException
Creates a new transient instance based on a parent bean.

getBeanContext

public static BeanContext getBeanContext()
Please use Container.getBeanContext() instead. That method will not incur synchronization overhead.
See Also:
Container.getBeanContext()

getInstance

public static BeanContext getInstance()
                               throws BeanFactoryException
Please use Container.getBeanContext() instead. This method must be synchronized in order to be MT-safe. Container.getBeanContext() is not synchronized, so it should be used in preference to this method.
See Also:
Container.getBeanContext()

bindScope

public void bindScope()
Binds the "thread" scope to the calling thread. Calling this method repeatedly without calling unbindScope() will not raise an exception.

unbindScope

public void unbindScope()
Releases all thread-bound scopes from the calling thread.

bindScope

public void bindScope(javax.servlet.ServletContext ctx,
                      javax.servlet.http.HttpSession ses,
                      javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
Binds thread, request, session, and application scopes to the calling thread.

bindScope

public void bindScope(javax.servlet.ServletContext ctx)

lookupHandle

public Handle lookupHandle(java.lang.String url)
                    throws BeanFactoryException
Obtains a handle to a bean reference. This method is useful in situations where casting the resulting object is not possible. The Handle provides an extra level of indirection.
Parameters:
url - Uniform Resource Name for the bean
Returns:
Handle for the bean.

resolve

public java.lang.Object resolve(java.lang.String url)
                         throws BeanFactoryException
Resolves a nested property into an object.
Parameters:
s - The URL to resolve.

existsInstance

public boolean existsInstance(java.lang.String url)
                       throws BeanFactoryException
Returns true if the specified bean already exists in the BeanFactory container.
Returns:
true if the bean exists; false if not

findInstance

public java.lang.Object findInstance(java.lang.String url)
                              throws BeanFactoryException
Finds an existing bean in the container. This method is similar to lookup() except that it will not instantiate a bean that does not exist.
Parameters:
url - the url of the bean to find
Returns:
reference to the existing bean; null if not instantiated