Class Beans

java.lang.Object
java.beans.Beans

public class Beans extends Object
This class provides some general purpose beans control methods.
Since:
1.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Beans.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    getInstanceOf(Object bean, Class<?> targetType)
    From a given bean, obtain an object representing a specified type view of that source object.
    static Object
    instantiate(ClassLoader cls, String beanName)
    Instantiate a JavaBean.
    static Object
    instantiate(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 removed
    static boolean
    Test if we are in design-mode.
    static boolean
    Determines whether beans can assume a GUI is available.
    static boolean
    isInstanceOf(Object bean, Class<?> targetType)
    Check if a bean can be viewed as a given target type.
    static void
    setDesignTime(boolean isDesignTime)
    Used to indicate whether of not we are running in an application builder environment.
    static void
    setGuiAvailable(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, wait
    Modifier and Type
    Method
    Description
    protected Object
    Creates and returns a copy of this object.
    boolean
    Indicates whether some other object is "equal to" this one.
    protected void
    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<?>
    Returns the runtime class of this Object.
    int
    Returns a hash code value for this object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
    final void
    wait(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 void
    wait(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 a Beans.
  • 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 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 - 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 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 - 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

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

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