下面列出了java.beans.Beans#instantiate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** 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();
}
}
}
/**
* 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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}