com.googlecode.openbeans
Class Beans

java.lang.Object
  extended by com.googlecode.openbeans.Beans

public class Beans
extends Object

This class Beans provides some methods for manipulting bean controls.


Constructor Summary
Beans()
          Constructs a Beans instance.
 
Method Summary
static Object getInstanceOf(Object bean, Class<?> targetType)
          Obtain an alternative type view of the given bean.
static Object instantiate(ClassLoader loader, String name)
          Obtains an instance of a JavaBean specified the bean name using the specified class loader.
static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext)
          Obtains an instance of a JavaBean specified the bean name using the specified class loader, and adds the instance into the specified bean context.
static Object instantiate(ClassLoader cls, String beanName, BeanContext context, AppletInitializer initializer)
          Obtains an instance of a JavaBean specified by the bean name using the specified class loader, and adds the instance into the specified bean context.
static boolean isDesignTime()
          Determine if it's in design-mode.
static boolean isGuiAvailable()
          Returns a boolean indication of whether or not a GUI is available for beans.
static boolean isInstanceOf(Object bean, Class<?> targetType)
          Determine if the the specified bean object can be viewed as the specified type.
static void setDesignTime(boolean isDesignTime)
          Used to indicate whether of not it's in an application construction environment.
static void setGuiAvailable(boolean isGuiAvailable)
          Set whether or not a GUI is available in the bean's current environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Beans

public Beans()
Constructs a Beans instance.

Method Detail

instantiate

public static Object instantiate(ClassLoader loader,
                                 String name)
                          throws IOException,
                                 ClassNotFoundException
Obtains an instance of a JavaBean specified the bean name using the specified class loader.

If the specified class loader is null, the system class loader is used.

Parameters:
loader - the specified class loader. It can be null.
name - the name of the JavaBean
Returns:
an isntance of the bean.
Throws:
IOException
ClassNotFoundException

instantiate

public static Object instantiate(ClassLoader cls,
                                 String beanName,
                                 BeanContext beanContext)
                          throws IOException,
                                 ClassNotFoundException
Obtains an instance of a JavaBean specified the bean name using the specified class loader, and adds the instance into the specified bean context.

If the specified class loader is null, the system class loader is used.

Parameters:
cls - the specified class loader. It can be null.
beanName - the name of the JavaBean
beanContext - the beancontext in which the bean instance will be added.
Returns:
an instance of the specified JavaBean.
Throws:
IOException
ClassNotFoundException

instantiate

public static Object instantiate(ClassLoader cls,
                                 String beanName,
                                 BeanContext context,
                                 AppletInitializer initializer)
                          throws IOException,
                                 ClassNotFoundException
Obtains an instance of a JavaBean specified by the bean name using the specified class loader, and adds the instance into the specified bean context.

The parameter name must be a qualified name relative to the specified class loader. For example, "java.awt.Button" and "x.y.z".

If the specified class loader is null, the system class loader is used.

Firstly, The class Beans regards the bean name as a serialized object name. The class Beans convert bean name into pathname, append a suffix ".ser" to the pathname. then try to load the resource using the specified class loader. If Beans fails to load the resource, Beans will regard the name as a class name and construct a new instance of the bean class.

For example, if the name is specified as "x.y.z", The class Beans will try to load the serialized object from the resource "x/y/z.ser"; If Beans fails to load the resource "x/y/z.ser", it will create a new instance of "x.y.z".

If the bean is an instance of java.applet.Applet, Beans will do some special initialization for this applet bean. First, Beans will set the default AppletStub and AppletContext for the applet bean (If the specified AppletInitializer is not null, Beans will call the AppletInitializer.initialize to set the default AppletStub and AppletContext for the applet bean). Second, Beans will call the init method of the applet. (If the applet bean is loaded as a serialized object, the init method will not be called.)

Parameters:
cls - the specified class loader. It can be null.
beanName - the name of the JavaBean
context - the beancontext in which the bean instance will be added.
initializer - the AppletInitializer for applet bean instance.
Returns:
Obtains an instance of the JavaBean.
Throws:
IOException
ClassNotFoundException

getInstanceOf

public static Object getInstanceOf(Object bean,
                                   Class<?> targetType)
Obtain an alternative type view of the given bean. The view type is specified by the parameter type.

If the type view cannot be obtained, the original bean object is returned.

Parameters:
bean - the original bean object.
targetType - the specified view type.
Returns:
a type view of the given bean.

isInstanceOf

public static boolean isInstanceOf(Object bean,
                                   Class<?> targetType)
Determine if the the specified bean object can be viewed as the specified type.

Parameters:
bean - the specified bean object.
targetType - the specifed view type.
Returns:
true if the specified bean object can be viewed as the specified type; otherwise, return false;

setGuiAvailable

public static void setGuiAvailable(boolean isGuiAvailable)
                            throws SecurityException
Set whether or not a GUI is available in the bean's current environment.

Parameters:
isGuiAvailable - should be true to signify that a GUI is available, false otherwise.
Throws:
SecurityException - if the caller does not have the required permission to access or modify system properties.

setDesignTime

public static void setDesignTime(boolean isDesignTime)
                          throws SecurityException
Used to indicate whether of not it's in an application construction environment.

Parameters:
isDesignTime - true to indicate that it's in application construction environment.
Throws:
SecurityException

isGuiAvailable

public static boolean isGuiAvailable()
Returns a boolean indication of whether or not a GUI is available for beans.

Returns:
true if a GUI is available, otherwise false.

isDesignTime

public static boolean isDesignTime()
Determine if it's in design-mode.

Returns:
true if it's in an application construction environment.


Copyright © 2013. All Rights Reserved.