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()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
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.
-