java.lang.Object java.beans.BeansBeans provides some helper methods that allow the basic
operations of Bean-ness.
Beans()static Object getInstanceOf(Object bean, Class> newClass)static Object instantiate(ClassLoader cl, String beanName)static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext)static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext, AppletInitializer initializer)static boolean isDesignTime()static boolean isGuiAvailable()static boolean isInstanceOf(Object bean, Class> newBeanClass)static void setDesignTime(boolean designTime)static void setGuiAvailable(boolean guiAvailable)public Beans()
Once again, we have a java.beans class with only static methods that can be instantiated. When will the madness end? :)
public static Object getInstanceOf(Object bean, Class> newClass)
Returns the Bean as a different class type. This should be used instead of casting to get a new type view of a Bean, because in the future there may be new types of Bean, even Beans spanning multiple Objects.
- Parameters:
bean- the Bean to cast.newClass- the Class to cast it to.
- Returns:
- the Bean as a new view, or if the operation could not be performed, the Bean itself.
public static Object instantiate(ClassLoader cl, String beanName) throws IOException, ClassNotFoundException
Creates a bean. This is a convenience method that callsinstantiate(cl, beanName, null, null).
- Parameters:
cl- ClassLoader to be used ornullfor the system classloader.beanName- Name of a serialized bean or class name.
- Returns:
- A newly created bean.
- Throws:
IOException- If access of an IO resource failed.ClassNotFoundException- If the class name is not known or does not lead to a proper bean class.
- See Also:
instantiate(ClassLoader, String, BeanContext, AppletInitializer)
public static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException
Creates a bean. This is a convenience method that callsinstantiate(cl, beanName, beanContext, null).
- Parameters:
cl- ClassLoader to be used ornullfor the system classloader.beanName- Name of a serialized bean or class name.beanContext- Context to which the newly created Bean should be added.
- Returns:
- A newly created bean.
- Throws:
IOException- If access of an IO resource failed.ClassNotFoundException- If the class name is not known or does not lead to a proper bean class.
- See Also:
instantiate(ClassLoader, String, BeanContext, AppletInitializer)
public static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext, AppletInitializer initializer) throws IOException, ClassNotFoundException
Instantiates a bean according to Beans 1.0. In Beans 1.0 the instantiation scheme is as follows: The name should be dot-separated (e.g "place.for.beans.myBean") and indicate either a serialized object or a class name. In the first case all dots in the name are replaced with slashes ('/') and ".ser" is appended ("place.for.beans.myBean" becomes "place/for/beans/myBean.ser"). The bean is then loaded as an application or system resource depending on whether aClassLoaderwas provided. If no such resource exists or if it contains no bean the name is interpreted as a class name of which an instance is then created. If aBeanContextinstance is available the created bean is added to it. If the created Bean is anAppletor subclass and anAppletInitializerinstance is available the applet is initialized and afterwards activated using the initializer. Additionally every instantiatedAppletbean is initialized using theApplet.initmethod. Furthermore every applet gets a defaultAppletStub. TheApplet's document base is the location of the ".ser" file if it was deserialized or the location of its class file if it was instantiated. AClassNotFoundExceptionis not only thrown when a class name was unknown but even when the class has public no-argument constructor (IllegalAccessExceptionis wrapped) or an exception is thrown while invoking such a constructor (causing exception is wrapped).
- Parameters:
cl- ClassLoader to be used ornullfor the system classloader.beanName- Name of a serialized bean or class name.beanContext- Context to which the newly created Bean should be added.initializer- The AppletInitializer which is used for initializingAppletbeans.
- Returns:
- A newly created bean.
- Throws:
IOException- If access of an IO resource failed.ClassNotFoundException- If the class name is not known or does not lead to a proper bean class.
public static boolean isDesignTime()
Returns whether it is design time. Design time means we are in a RAD tool. Defaults to false.
- Returns:
- whether it is design time.
public static boolean isGuiAvailable()
Returns whether the GUI is available to use. Defaults to true.
- Returns:
- whether the GUI is available to use.
public static boolean isInstanceOf(Object bean, Class> newBeanClass)
Determines whether the Bean can be cast to a different class type. This should be used instead of instanceof to determine a Bean's castability, because in the future there may be new types of Bean, even Beans spanning multiple Objects.
- Parameters:
bean- the Bean to cast.
- Returns:
- whether the Bean can be cast to the class type in question.
public static void setDesignTime(boolean designTime) throws SecurityException
Sets whether it is design time. Design time means we are in a RAD tool.
- Parameters:
designTime- whether it is design time.
public static void setGuiAvailable(boolean guiAvailable) throws SecurityException
Sets whether the GUI is available to use.
- Parameters:
guiAvailable- whether the GUI is available to use.