Java Code Examples for java.beans.Beans#instantiate()

The following examples show how to use java.beans.Beans#instantiate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManifestSection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Create a fresh instance.
 * @return the instance
 * @exception Exception if there is an error
 */
protected final Object createInstance() throws Exception {
    if (! isDefaultInstance()) {
        try {
            Object o = Beans.instantiate(getClassLoader(), className);
            clazz = o.getClass();
            if (! getSectionClass().isAssignableFrom(clazz)) {
                throw new ClassCastException("Class " + clazz.getName() + " is not a subclass of " + getSuperclass().getName()); // NOI18N
            }
            return o;
        } catch (ClassNotFoundException cnfe) {
            Exceptions.attachMessage(cnfe,
                                     "Loader for ClassNotFoundException: " +
                                     getClassLoader());
            throw cnfe;
        } catch (LinkageError le) {
            throw new ClassNotFoundException(le.toString(), le);
        }
    } else {
        getSectionClass(); // might throw some exceptions
        if (SharedClassObject.class.isAssignableFrom(clazz)) {
            return SharedClassObject.findObject(clazz.asSubclass(SharedClassObject.class), true);
        } else {
            return clazz.newInstance();
        }
    }
}
 
Example 2
Source File: ReflectionUtils.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
   * Create a bean using given class loader and using the appropriate
   * constructor for the given args of the given arg types.

   * @param cld       the class loader to use. If null, Class.forName is used.
   * @param className name of class to instantiate
   * @param argTypes  array of argument types
   * @param args      array of arguments
   *
   * @return the newly created bean
   *
   * @exception ClassNotFoundException    if class is not loaded
   * @exception NoSuchMethodException     if constructor can't be found
   * @exception InstantiationException    if class can't be instantiated
   * @exception IllegalAccessException    if class is not accessible
   * @exception IllegalArgumentException  if argument problem
   * @exception InvocationTargetException if constructor excepted
   * @exception IOException               if I/O error in beans.instantiate
   */
  public static Bean createBean (ClassLoader cld, String className,
                 Class[] argTypes, Object[] args)
       throws ClassNotFoundException, NoSuchMethodException,
              InstantiationException, IllegalAccessException,
              IllegalArgumentException, InvocationTargetException,
              IOException {
    if (argTypes != null) {

            // if class loader given, use that one, else try
            // the Thread's context class loader (if set) and then
            // the BSFMananger defining class loader
          Class cl=null;
          ClassNotFoundException exCTX=null;

// -----------------------------
          if (cld != null) {    // class loader supplied as argument
              try {     // CL passed as argument
                  cl=cld.loadClass(className);
              }
              catch (ClassNotFoundException e02) {
                  exCTX=e02;
              }
          }

          if (cl==null) {
              // load context class loader, only use it, if not null
              ClassLoader tccl=Thread.currentThread().getContextClassLoader();
              if (tccl!=null) {
                  try {         // CTXCL
                          cl=tccl.loadClass(className);
                      }
                  catch (ClassNotFoundException e01) {}
              }
          }

          if (cl==null) {   // class not loaded yet
                    // defined CL
              if (cld != bsfManagerDefinedCL) {   // if not used already, attempt to load
                  cl=bsfManagerDefinedCL.loadClass(className);
              }
              else {    // classloader was already used, hence re-throw exception
                  throw exCTX;      // re-throw very first exception
              }
          }
// -----------------------------

      Constructor c = MethodUtils.getConstructor (cl, argTypes);
      return new Bean (cl, c.newInstance (args));
    } else {
      // create the bean with no args constructor
      Object obj = Beans.instantiate (cld, className);
      return new Bean (obj.getClass (), obj);
    }
  }
 
Example 3
Source File: BeanContextSupport.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 4
Source File: BeanContextSupport.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 5
Source File: BeanContextSupport.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 6
Source File: BeanContextSupport.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 7
Source File: BeanContextSupport.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 8
Source File: BeanContextSupport.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 9
Source File: BeanContextSupport.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 10
Source File: BeanContextSupport.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 11
Source File: BeanContextSupport.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 12
Source File: BeanContextSupport.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 13
Source File: BeanContextSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a {@code BeanContext}.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 14
Source File: BeanContextSupport.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a {@code BeanContext}.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 15
Source File: BeanContextSupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 16
Source File: BeanContextSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 17
Source File: BeanContextSupport.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 18
Source File: BeanContextSupport.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 19
Source File: BeanContextSupport.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}
 
Example 20
Source File: BeanContextSupport.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * The instantiateChild method is a convenience hook
 * in BeanContext to simplify
 * the task of instantiating a Bean, nested,
 * into a <tt>BeanContext</tt>.
 * </p>
 * <p>
 * The semantics of the beanName parameter are defined by java.beans.Beans.instantiate.
 * </p>
 *
 * @param beanName the name of the Bean to instantiate within this BeanContext
 * @throws IOException if there is an I/O error when the bean is being deserialized
 * @throws ClassNotFoundException if the class
 * identified by the beanName parameter is not found
 * @return the new object
 */
public Object instantiateChild(String beanName)
       throws IOException, ClassNotFoundException {
    BeanContext bc = getBeanContextPeer();

    return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
}