java.beans

Class Beans


public class Beans
extends Object

Beans provides some helper methods that allow the basic operations of Bean-ness.
Since:
1.1

Constructor Summary

Beans()
Once again, we have a java.beans class with only static methods that can be instantiated.

Method Summary

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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Beans

public Beans()
Once again, we have a java.beans class with only static methods that can be instantiated. When will the madness end? :)

Method Details

getInstanceOf

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.

instantiate

public static Object instantiate(ClassLoader cl,
                                 String beanName)
            throws IOException,
                   ClassNotFoundException
Creates a bean.

This is a convenience method that calls instantiate(cl, beanName, null, null).

Parameters:
cl - ClassLoader to be used or null for 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)

instantiate

public static Object instantiate(ClassLoader cl,
                                 String beanName,
                                 BeanContext beanContext)
            throws IOException,
                   ClassNotFoundException
Creates a bean.

This is a convenience method that calls instantiate(cl, beanName, beanContext, null).

Parameters:
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.
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)

instantiate

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 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).

Parameters:
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.
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.

isDesignTime

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.

isGuiAvailable

public static boolean isGuiAvailable()
Returns whether the GUI is available to use.

Defaults to true.

Returns:
whether the GUI is available to use.

isInstanceOf

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.
newBeanClass - the Class to cast it to.
Returns:
whether the Bean can be cast to the class type in question.

setDesignTime

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.

setGuiAvailable

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.

java.beans.Beans Copyright (C) 1998, 1999, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.