java.beans
Constructor and Description |
---|
Beans()
Once again, we have a java.beans class with only
static methods that can be instantiated.
|
Modifier and Type | Method and Description |
---|---|
static Object |
getInstanceOf(Object bean,
Class<?> newClass)
Returns the Bean as a different class type.
|
static Object |
instantiate(ClassLoader cl,
String beanName)
Creates a bean.
|
static Object |
instantiate(ClassLoader cl,
String beanName,
BeanContext beanContext)
Creates a bean.
|
static Object |
instantiate(ClassLoader cl,
String beanName,
BeanContext beanContext,
AppletInitializer initializer)
Instantiates a bean according to Beans 1.0.
|
static boolean |
isDesignTime()
Returns whether it is design time.
|
static boolean |
isGuiAvailable()
Returns whether the GUI is available to use.
|
static boolean |
isInstanceOf(Object bean,
Class<?> newBeanClass)
Determines whether the Bean can be cast to a different
class type.
|
static void |
setDesignTime(boolean designTime)
Sets whether it is design time.
|
static void |
setGuiAvailable(boolean guiAvailable)
Sets whether the GUI is available to use.
|
public Beans()
public static Object instantiate(ClassLoader cl, String beanName) throws IOException, ClassNotFoundException
This is a convenience method that calls instantiate(cl, beanName, null, null)
.
cl
- ClassLoader to be used or null
for the system classloader.beanName
- Name of a serialized bean or class name.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.instantiate(ClassLoader, String, BeanContext, AppletInitializer)
public static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException
This is a convenience method that calls instantiate(cl, beanName, beanContext, null)
.
cl
- ClassLoader to be used or null
for the system classloader.beanName
- Name of a serialized bean or class name.beanContext
- Context to which the newly created Bean should be added.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.instantiate(ClassLoader, String, BeanContext, AppletInitializer)
public static Object instantiate(ClassLoader cl, String beanName, BeanContext beanContext, AppletInitializer initializer) throws IOException, ClassNotFoundException
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 a
ClassLoader
was 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 a BeanContext
instance is available the created bean is added to it.
If the created Bean is an Applet
or subclass and an AppletInitializer
instance is available the applet is initialized and afterwards activated using the initializer. Additionally
every instantiated Applet
bean is initialized using the Applet.init
method.
Furthermore every applet gets a default AppletStub
. The Applet
'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.
A ClassNotFoundException
is not only thrown when a class name was unknown
but even when the class has public no-argument constructor
(IllegalAccessException
is wrapped) or an exception is thrown while
invoking such a constructor (causing exception is wrapped).
cl
- ClassLoader to be used or null
for 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 initializing Applet
beans.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 Object getInstanceOf(Object bean, Class<?> newClass)
bean
- the Bean to cast.newClass
- the Class to cast it to.public static boolean isInstanceOf(Object bean, Class<?> newBeanClass)
bean
- the Bean to cast.newBeanClass
- the Class to cast it to.public static boolean isGuiAvailable()
Defaults to true.
public static boolean isDesignTime()
Defaults to false.
public static void setGuiAvailable(boolean guiAvailable) throws SecurityException
guiAvailable
- whether the GUI is available to use.SecurityException
public static void setDesignTime(boolean designTime) throws SecurityException
designTime
- whether it is design time.SecurityException