APIdia Launch Partner
Top Description Constructors Methods
java.beans

public Class Beans

Additional top-level class in compilation unit: ObjectInputStreamWithLoader.

extends Object
Class Inheritance
Imports
com.sun.beans.finder.ClassFinder, java.awt.Image, java.beans.beancontext.BeanContext, java.io.IOException, .InputStream, .ObjectInputStream, .ObjectStreamClass, .StreamCorruptedException, java.lang.reflect.Modifier, java.net.MalformedURLException, .URL, java.util.Enumeration, .Hashtable, .Iterator, .Vector

This class provides some general purpose beans control methods.
Since
1.1

Constructor Summary

AccessConstructor and Description
public
Beans()

Constructs a Beans.

Method Summary

Modifier and TypeMethod and Description
public static Object

Returns:

an object representing a specified type view of the source object
getInstanceOf
(Object
Object from which we want to obtain a view.
bean
,
Class<?>
The type of view we'd like to get.
targetType
)

From a given bean, obtain an object representing a specified type view of that source object.

public static Object

Returns:

a JavaBean
instantiate
(ClassLoader
the class-loader from which we should create the bean. If this is null, then the system class-loader is used.
cls
,
String
the name of the bean within the class-loader. For example "sun.beanbox.foobah"
beanName
)

Instantiate a JavaBean.

public static Object

Returns:

a JavaBean
instantiate
(ClassLoader
the class-loader from which we should create the bean. If this is null, then the system class-loader is used.
cls
,
String
the name of the bean within the class-loader. For example "sun.beanbox.foobah"
beanName
,
BeanContext
The BeanContext in which to nest the new bean
beanContext
)
Deprecated for removal since 23. this method will be removed when java.beans.beancontext is removed

Instantiate a JavaBean.

public static boolean

Returns:

True if we are running in an application construction environment.
isDesignTime
()

Test if we are in design-mode.

public static boolean

Returns:

True if we are running in an environment where beans can assume that an interactive GUI is available, so they can pop up dialog boxes, etc. This will normally return true in a windowing environment, and will normally return false in a server environment or if an application is running as part of a batch job.
isGuiAvailable
()

Determines whether beans can assume a GUI is available.

public static boolean

Returns:

"true" if the given bean supports the given targetType.
isInstanceOf
(Object
Bean from which we want to obtain a view.
bean
,
Class<?>
The type of view we'd like to get.
targetType
)

Check if a bean can be viewed as a given target type.

private static URL
newURL(String spec)

public static void
setDesignTime(boolean
True if we're in an application builder tool.
isDesignTime
)

Used to indicate whether of not we are running in an application builder environment.

public static void
setGuiAvailable(boolean
True if GUI interaction is available.
isGuiAvailable
)

Used to indicate whether of not we are running in an environment where GUI interaction is available.

private static void
unsafeBeanContextAdd(BeanContext beanContext, Object res)
Deprecated for removal since 23.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Beansback to summary
public Beans()

Constructs a Beans.

Method Detail

getInstanceOfback to summary
public static Object getInstanceOf(Object bean, Class<?> targetType)

From a given bean, obtain an object representing a specified type view of that source object.

The result may be the same object or a different object. If the requested target view isn't available then the given bean is returned.

This method is provided in Beans 1.0 as a hook to allow the addition of more flexible bean behaviour in the future.

Parameters
bean:Object

Object from which we want to obtain a view.

targetType:Class<?>

The type of view we'd like to get.

Returns:Object

an object representing a specified type view of the source object

instantiateback to summary
public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException

Instantiate a JavaBean.

The bean is created based on a name relative to a class-loader. This name should be a binary name of a class such as "a.b.C".

The given name can indicate either a serialized object or a class. We first try to treat the beanName as a serialized object name then as a class name.

When using the beanName as a serialized object name we convert the given beanName to a resource pathname and add a trailing ".ser" suffix. We then try to load a serialized object from that resource.

For example, given a beanName of "x.y", Beans.instantiate would first try to read a serialized object from the resource "x/y.ser" and if that failed it would try to load the class "x.y" and create an instance of that class.

Parameters
cls:ClassLoader

the class-loader from which we should create the bean. If this is null, then the system class-loader is used.

beanName:String

the name of the bean within the class-loader. For example "sun.beanbox.foobah"

Returns:Object

a JavaBean

Exceptions
IOException:
if an I/O error occurs.
ClassNotFoundException:
if the class of a serialized object could not be found.
instantiateback to summary
public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException

Deprecated

for removal since 23.

this method will be removed when java.beans.beancontext is removed

Instantiate a JavaBean.

The bean is created based on a name relative to a class-loader. This name should be a binary name of a class such as "a.b.C".

The given name can indicate either a serialized object or a class. We first try to treat the beanName as a serialized object name then as a class name.

When using the beanName as a serialized object name we convert the given beanName to a resource pathname and add a trailing ".ser" suffix. We then try to load a serialized object from that resource.

For example, given a beanName of "x.y", Beans.instantiate would first try to read a serialized object from the resource "x/y.ser" and if that failed it would try to load the class "x.y" and create an instance of that class.

Parameters
cls:ClassLoader

the class-loader from which we should create the bean. If this is null, then the system class-loader is used.

beanName:String

the name of the bean within the class-loader. For example "sun.beanbox.foobah"

beanContext:BeanContext

The BeanContext in which to nest the new bean

Returns:Object

a JavaBean

Annotations
@Deprecated
since:23
forRemoval:true
@SuppressWarnings:removal
Exceptions
IOException:
if an I/O error occurs.
ClassNotFoundException:
if the class of a serialized object could not be found.
Since
1.2
isDesignTimeback to summary
public static boolean isDesignTime()

Test if we are in design-mode.

Returns:boolean

True if we are running in an application construction environment.

See Also
DesignMode
isGuiAvailableback to summary
public static boolean isGuiAvailable()

Determines whether beans can assume a GUI is available.

Returns:boolean

True if we are running in an environment where beans can assume that an interactive GUI is available, so they can pop up dialog boxes, etc. This will normally return true in a windowing environment, and will normally return false in a server environment or if an application is running as part of a batch job.

See Also
Visibility
isInstanceOfback to summary
public static boolean isInstanceOf(Object bean, Class<?> targetType)

Check if a bean can be viewed as a given target type. The result will be true if the Beans.getInstanceof method can be used on the given bean to obtain an object that represents the specified targetType type view.

Parameters
bean:Object

Bean from which we want to obtain a view.

targetType:Class<?>

The type of view we'd like to get.

Returns:boolean

"true" if the given bean supports the given targetType.

newURLback to summary
private static URL newURL(String spec) throws MalformedURLException
Annotations
@SuppressWarnings:deprecation
setDesignTimeback to summary
public static void setDesignTime(boolean isDesignTime)

Used to indicate whether of not we are running in an application builder environment.

Parameters
isDesignTime:boolean

True if we're in an application builder tool.

setGuiAvailableback to summary
public static void setGuiAvailable(boolean isGuiAvailable)

Used to indicate whether of not we are running in an environment where GUI interaction is available.

Parameters
isGuiAvailable:boolean

True if GUI interaction is available.

unsafeBeanContextAddback to summary
private static void unsafeBeanContextAdd(BeanContext beanContext, Object res)

Deprecated

for removal since 23.

Annotations
@Deprecated
since:23
forRemoval:true
@SuppressWarnings:unchecked, removal