Class Beans
- Since:
- 1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectgetInstanceOf(Object bean, Class<?> targetType) From a given bean, obtain an object representing a specified type view of that source object.static Objectinstantiate(ClassLoader cls, String beanName) Instantiate a JavaBean.static Objectinstantiate(ClassLoader cls, String beanName, BeanContext beanContext) Deprecated, for removal: This API element is subject to removal in a future version.this method will be removed when java.beans.beancontext is removedstatic booleanTest if we are in design-mode.static booleanDetermines whether beans can assume a GUI is available.static booleanisInstanceOf(Object bean, Class<?> targetType) Check if a bean can be viewed as a given target type.static voidsetDesignTime(boolean isDesignTime) Used to indicate whether of not we are running in an application builder environment.static voidsetGuiAvailable(boolean isGuiAvailable) Used to indicate whether of not we are running in an environment where GUI interaction is available.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
Beans
public Beans()Constructs aBeans.
-
-
Method Details
-
instantiate
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
beanNameas a serialized object name then as a class name.When using the
beanNameas a serialized object name we convert the givenbeanNameto a resource pathname and add a trailing ".ser" suffix. We then try to load a serialized object from that resource.For example, given a
beanNameof "x.y",Beans.instantiatewould 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- the class-loader from which we should create the bean. If this is null, then the system class-loader is used.beanName- the name of the bean within the class-loader. For example "sun.beanbox.foobah"- Returns:
- a JavaBean
- Throws:
ClassNotFoundException- if the class of a serialized object could not be found.IOException- if an I/O error occurs.
-
instantiate
@Deprecated(since="23", forRemoval=true) public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException Deprecated, for removal: This API element is subject to removal in a future version.this method will be removed when java.beans.beancontext is removedInstantiate 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
beanNameas a serialized object name then as a class name.When using the
beanNameas a serialized object name we convert the givenbeanNameto a resource pathname and add a trailing ".ser" suffix. We then try to load a serialized object from that resource.For example, given a
beanNameof "x.y",Beans.instantiatewould 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- the class-loader from which we should create the bean. If this is null, then the system class-loader is used.beanName- the name of the bean within the class-loader. For example "sun.beanbox.foobah"beanContext- The BeanContext in which to nest the new bean- Returns:
- a JavaBean
- Throws:
ClassNotFoundException- if the class of a serialized object could not be found.IOException- if an I/O error occurs.- Since:
- 1.2
-
getInstanceOf
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 from which we want to obtain a view.targetType- The type of view we'd like to get.- Returns:
- an object representing a specified type view of the source object
-
isInstanceOf
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- Bean from which we want to obtain a view.targetType- The type of view we'd like to get.- Returns:
- "true" if the given bean supports the given targetType.
-
isDesignTime
public static boolean isDesignTime()Test if we are in design-mode.- Returns:
- True if we are running in an application construction environment.
- See Also:
-
isGuiAvailable
public static boolean isGuiAvailable()Determines whether beans can assume a GUI is available.- 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.
- See Also:
-
setDesignTime
public static void setDesignTime(boolean isDesignTime) Used to indicate whether of not we are running in an application builder environment.- Parameters:
isDesignTime- True if we're in an application builder tool.
-
setGuiAvailable
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- True if GUI interaction is available.
-