本文整理匯總了Java中java.beans.Beans.instantiate方法的典型用法代碼示例。如果您正苦於以下問題:Java Beans.instantiate方法的具體用法?Java Beans.instantiate怎麽用?Java Beans.instantiate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.beans.Beans
的用法示例。
在下文中一共展示了Beans.instantiate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCommandObject
import java.beans.Beans; //導入方法依賴的package包/類
/**
* Returns the instantiated bean.
* If the bean implements <code>CommandObject</code>, its
* <code>setCommandContext</code> method will be called.
* @param dh the data handler describing the command data
* @param loader the class loader used to instantiate the bean
*/
public Object getCommandObject(DataHandler dh, ClassLoader loader)
throws IOException, ClassNotFoundException
{
Object object = Beans.instantiate(loader, className);
if (object != null)
{
if (object instanceof CommandObject)
{
CommandObject command = (CommandObject)object;
command.setCommandContext(verb, dh);
}
else if (dh != null && (object instanceof Externalizable))
{
InputStream in = dh.getInputStream();
if (in != null)
{
Externalizable externalizable = (Externalizable)object;
externalizable.readExternal(new ObjectInputStream(in));
}
}
}
return object;
}
示例2: BeanInstance
import java.beans.Beans; //導入方法依賴的package包/類
/**
* Creates a new <code>BeanInstance</code> instance given the fully qualified
* name of the bean
*
* @param container a <code>JComponent</code> to add the bean to
* @param beanName the fully qualified name of the bean
* @param x the x coordinate of the bean
* @param y th y coordinate of the bean
*/
public BeanInstance(JComponent container, String beanName, int x, int y,
Integer... tab) {
m_x = x;
m_y = y;
// try and instantiate the named component
try {
m_bean = Beans.instantiate(null, beanName);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
addBean(container, tab);
}
示例3: getInstance
import java.beans.Beans; //導入方法依賴的package包/類
/**
* Get a new Bean instance given its name
*/
public Object getInstance(String name) {
try {
return Beans.instantiate(null, name);
} catch (Throwable th) {
if (com.bbn.openmap.util.Debug.debugging("beanbox")) {
System.err.println(th);
th.printStackTrace();
if (name.indexOf('\\') >= 0) {
System.err.println(" Note that file names in manifests must use forward "
+ "slashes \"/\" \n rather than back-slashes \"\\\"");
}
}
return null;
}
}
示例4: createInstance
import java.beans.Beans; //導入方法依賴的package包/類
/** 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();
}
}
}
示例5: instantiateBean
import java.beans.Beans; //導入方法依賴的package包/類
/**
* "Instantiates" the bean represented by this leaf.
*/
protected void instantiateBean() {
try {
if (isMetaBean()) {
// MetaBean copy = copyMetaBean(m_metaBean, false);
// copy.addPropertyChangeListenersSubFlow(KnowledgeFlowApp.this);
m_toolBarBean = m_metaBean.get(1);
} else {
m_toolBarBean = Beans.instantiate(KnowledgeFlowApp.this.getClass()
.getClassLoader(), m_fullyQualifiedCompName);
if (isWrappedAlgorithm()) {
Object algo = Beans.instantiate(KnowledgeFlowApp.this.getClass()
.getClassLoader(), m_wekaAlgoName);
((WekaWrapper) m_toolBarBean).setWrappedAlgorithm(algo);
}
}
KnowledgeFlowApp.this.setCursor(Cursor
.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
m_mode = ADDING;
m_pasteB.setEnabled(false);
} catch (Exception ex) {
System.err
.println("Problem instantiating bean \"" + m_fullyQualifiedCompName
+ "\" (JTreeLeafDetails.instantiateBean()");
ex.printStackTrace();
}
}
示例6: BeanInstance
import java.beans.Beans; //導入方法依賴的package包/類
/**
* Creates a new <code>BeanInstance</code> instance given the fully
* qualified name of the bean
*
* @param container a <code>JComponent</code> to add the bean to
* @param beanName the fully qualified name of the bean
* @param x the x coordinate of the bean
* @param y th y coordinate of the bean
*/
public BeanInstance(JComponent container, String beanName, int x, int y, Integer... tab) {
m_x = x;
m_y = y;
// try and instantiate the named component
try {
m_bean = Beans.instantiate(null, beanName);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
addBean(container, tab);
}
示例7: instantiateBean
import java.beans.Beans; //導入方法依賴的package包/類
/**
* "Instantiates" the bean represented by this leaf.
*/
protected void instantiateBean() {
try {
if (isMetaBean()) {
// MetaBean copy = copyMetaBean(m_metaBean, false);
//copy.addPropertyChangeListenersSubFlow(KnowledgeFlowApp.this);
m_toolBarBean = m_metaBean.get(1);
} else {
m_toolBarBean = Beans.instantiate(KnowledgeFlowApp.this.getClass().getClassLoader(),
m_fullyQualifiedCompName);
if (isWrappedAlgorithm()) {
Object algo = Beans.instantiate(KnowledgeFlowApp.this.getClass().getClassLoader(),
m_wekaAlgoName);
((WekaWrapper)m_toolBarBean).setWrappedAlgorithm(algo);
}
}
KnowledgeFlowApp.this.setCursor(Cursor.
getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
m_mode = ADDING;
m_pasteB.setEnabled(false);
} catch (Exception ex) {
System.err.println("Problem instantiating bean \""
+ m_fullyQualifiedCompName + "\" (JTreeLeafDetails.instantiateBean()");
ex.printStackTrace();
}
}
示例8: testInstantiateClassLoaderString_Class
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderString_Class() throws Exception {
ClassLoader loader = new BinClassLoader();
Object bean = Beans.instantiate(loader, MOCK_JAVA_BEAN2);
assertEquals("as_class", (String) bean.getClass().getMethod(
"getPropertyOne", (Class[]) null).invoke(bean, (Object[]) null));
assertSame(loader, bean.getClass().getClassLoader());
}
示例9: test_instantiate_ClassNotFoundExceptionThrowing
import java.beans.Beans; //導入方法依賴的package包/類
public void test_instantiate_ClassNotFoundExceptionThrowing()
throws IOException {
ClassLoader loader = new WrongSerClassLoader();
try {
Beans
.instantiate(loader,
"org.apache.harmony.beans.tests.support.mock.WrongSerBean2");
fail("Should throw a ClassNotFoundException");
} catch (ClassNotFoundException ex) {
// expected
}
}
示例10: testInstantiateClassLoaderString_BeanNameNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderString_BeanNameNull()
throws Exception {
try {
Beans.instantiate(null, null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
}
}
示例11: testInstantiateClassLoaderStringBeanContext_ClassLoaderNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderStringBeanContext_ClassLoaderNull()
throws Exception {
BeanContext context = new BeanContextSupport();
Object bean = Beans.instantiate(null, MockJavaBean.class.getName(),
context);
assertEquals(bean.getClass(), MockJavaBean.class);
assertSame(ClassLoader.getSystemClassLoader(), bean.getClass()
.getClassLoader());
assertTrue(context.contains(bean));
}
示例12: testInstantiateClassLoaderStringBeanContext_ContextNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderStringBeanContext_ContextNull()
throws Exception {
ClassLoader loader = createSpecificClassLoader();
Object bean = Beans.instantiate(loader, MockJavaBean.class.getName(),
null);
assertEquals(bean.getClass(), MockJavaBean.class);
}
示例13: testInstantiateClassLoaderStringBeanContextAppletInitializer_Class
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderStringBeanContextAppletInitializer_Class()
throws Exception {
ClassLoader loader = new BinClassLoader();
BeanContext context = new BeanContextSupport();
AppletInitializer appInit = new MockAppletInitializer();
Object bean = Beans.instantiate(loader, MOCK_JAVA_BEAN2, context,
appInit);
assertEquals("as_class", (String) bean.getClass().getMethod(
"getPropertyOne", (Class[]) null).invoke(bean, (Object[]) null));
assertSame(loader, bean.getClass().getClassLoader());
assertTrue(context.contains(bean));
}
示例14: testInstantiateClassLoaderStringBeanContextAppletInitializer_Ser
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderStringBeanContextAppletInitializer_Ser()
throws Exception {
ClassLoader loader = new SerClassLoader();
BeanContext context = new BeanContextSupport();
AppletInitializer appInit = new MockAppletInitializer();
Object bean = Beans.instantiate(loader, MOCK_JAVA_BEAN2, context,
appInit);
assertEquals("as_object", (String) bean.getClass().getMethod(
"getPropertyOne", (Class[]) null).invoke(bean, (Object[]) null));
assertSame(loader, bean.getClass().getClassLoader());
assertTrue(context.contains(bean));
}
示例15: testInstantiateClassLoaderStringBeanContextAppletInitializer_BeanNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testInstantiateClassLoaderStringBeanContextAppletInitializer_BeanNull()
throws Exception {
ClassLoader loader = createSpecificClassLoader();
BeanContext context = new BeanContextSupport();
AppletInitializer appInit = new MockAppletInitializer();
try {
Beans.instantiate(loader, null, context, appInit);
fail("Should throw NullPointerException.");
} catch (NullPointerException e) {
}
}