java.beans.Beans#instantiate ( )源码实例Demo

下面列出了java.beans.Beans#instantiate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ManifestSection.java
/** 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();
        }
    }
}
 
源代码2 项目: commons-bsf   文件: ReflectionUtils.java
/**
   * 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);
    }
  }
 
/**
 * <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);
}
 
源代码4 项目: dragonwell8_jdk   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码5 项目: TencentKona-8   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码6 项目: jdk8u60   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码7 项目: JDKSourceCode1.8   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码8 项目: openjdk-jdk8u   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码10 项目: Bytecoder   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码11 项目: openjdk-jdk9   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码12 项目: jdk8u-jdk   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码13 项目: Java8CN   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码14 项目: hottub   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码15 项目: openjdk-8-source   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码16 项目: openjdk-8   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码17 项目: jdk8u_jdk   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码18 项目: jdk8u-jdk   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码19 项目: jdk-1.7-annotated   文件: BeanContextSupport.java
/**
 * <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);
}
 
源代码20 项目: jdk8u-dev-jdk   文件: BeanContextSupport.java
/**
 * <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);
}