当前位置: 首页>>代码示例>>Java>>正文


Java ObjectFactory.getObjectInstance方法代码示例

本文整理汇总了Java中javax.naming.spi.ObjectFactory.getObjectInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectFactory.getObjectInstance方法的具体用法?Java ObjectFactory.getObjectInstance怎么用?Java ObjectFactory.getObjectInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.spi.ObjectFactory的用法示例。


在下文中一共展示了ObjectFactory.getObjectInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDataSource

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
/**
 * Tests that we can get a connection from the DataSource bound in JNDI
 * during test setup
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testDataSource() throws Exception {
    NameParser nameParser = this.ctx.getNameParser("");
    Name datasourceName = nameParser.parse("_test");
    Object obj = this.ctx.lookup(datasourceName);
    DataSource boundDs = null;

    if (obj instanceof DataSource) {
        boundDs = (DataSource) obj;
    } else if (obj instanceof Reference) {
        //
        // For some reason, this comes back as a Reference instance under CruiseControl !?
        //
        Reference objAsRef = (Reference) obj;
        ObjectFactory factory = (ObjectFactory) Class.forName(objAsRef.getFactoryClassName()).newInstance();
        boundDs = (DataSource) factory.getObjectInstance(objAsRef, datasourceName, this.ctx, new Hashtable<Object, Object>());
    }

    assertTrue("Datasource not bound", boundDs != null);

    Connection con = boundDs.getConnection();
    con.close();
    assertTrue("Connection can not be obtained from data source", con != null);
}
 
开发者ID:KillianMeersman,项目名称:Geometry-wars,代码行数:31,代码来源:DataSourceTest.java

示例2: lookupDatasourceInJNDI

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
    NameParser nameParser = this.ctx.getNameParser("");
    Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath() + jndiName);
    Object obj = this.ctx.lookup(datasourceName);
    DataSource boundDs = null;

    if (obj instanceof DataSource) {
        boundDs = (DataSource) obj;
    } else if (obj instanceof Reference) {
        //
        // For some reason, this comes back as a Reference instance under CruiseControl !?
        //
        Reference objAsRef = (Reference) obj;
        ObjectFactory factory = (ObjectFactory) Class.forName(objAsRef.getFactoryClassName()).newInstance();
        boundDs = (DataSource) factory.getObjectInstance(objAsRef, datasourceName, this.ctx, new Hashtable<Object, Object>());
    }

    return boundDs;
}
 
开发者ID:KillianMeersman,项目名称:Geometry-wars,代码行数:20,代码来源:DataSourceRegressionTest.java

示例3: lookupDatasourceInJNDI

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
	NameParser nameParser = this.ctx.getNameParser("");
	Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath()
			+ jndiName);
	Object obj = this.ctx.lookup(datasourceName);
	DataSource boundDs = null;

	if (obj instanceof DataSource) {
		boundDs = (DataSource) obj;
	} else if (obj instanceof Reference) {
		//
		// For some reason, this comes back as a Reference
		// instance under CruiseControl !?
		//
		Reference objAsRef = (Reference) obj;
		ObjectFactory factory = (ObjectFactory) Class.forName(
				objAsRef.getFactoryClassName()).newInstance();
		boundDs = (DataSource) factory.getObjectInstance(objAsRef,
				datasourceName, this.ctx, new Hashtable<Object, Object>());
	}

	return boundDs;
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:24,代码来源:DataSourceRegressionTest.java

示例4: resolveObject

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
/**
 * Resolve a Remote Object: If this object is a reference return the
 * reference
 * @param o the object to resolve
 * @param n the name of this object
 * @return a <code>Referenceable</code> if o is a Reference and the
 *         inititial object o if else
 */
private Object resolveObject(Object o, Name name) {
    try {
        if (o instanceof Reference) {
            // build of the Referenceable object with is Reference
            Reference objRef = (Reference) o;
            ObjectFactory objFact = (ObjectFactory) (Thread.currentThread().getContextClassLoader()
                    .loadClass(objRef.getFactoryClassName())).newInstance();
            return objFact.getObjectInstance(objRef, name, this, this.getEnvironment());
        } else {
            return o;
        }
    } catch (Exception e) {
        TraceCarol.error("LmiInitialContext.resolveObject()", e);
        return o;
    }
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:25,代码来源:left_LmiInitialContext_1.5.java

示例5: testJNDI2Pools

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
public void testJNDI2Pools() throws Exception {
    Reference refObj = new Reference(SharedPoolDataSource.class.getName());
    refObj.add(new StringRefAddr("dataSourceName","java:comp/env/jdbc/bookstoreCPDS"));
    Context context = new InitialContext();
    Hashtable env = new Hashtable();
    
    ObjectFactory factory = new SharedPoolDataSourceFactory();
    
    Name name = new CompositeName("myDB");
    Object obj = factory.getObjectInstance(refObj, name, context, env);
    assertNotNull(obj);
    
    Name name2 = new CompositeName("myDB2");
    Object obj2 = factory.getObjectInstance(refObj, name2, context, env);
    assertNotNull(obj2);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:17,代码来源:TestFactory.java

示例6: federate

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
protected Object federate(final String compositName) throws NamingException {
    final ObjectFactory[] factories = getFederatedFactories();
    for (final ObjectFactory factory : factories) {
        try {
            final CompositeName name = new CompositeName(compositName);
            final Object obj = factory.getObjectInstance(null, name, null, null);

            if (obj instanceof Context) {
                return ((Context) obj).lookup(compositName);
            } else if (obj != null) {
                return obj;
            }
        } catch (final Exception doNothing) {
            // no-op
        }
    }

    throw new NameNotFoundException("Name \"" + compositName + "\" not found.");
}
 
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:IvmContext.java

示例7: testJNDI2Pools

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
@Test
public void testJNDI2Pools() throws Exception {
    final Reference refObj = new Reference(SharedPoolDataSource.class.getName());
    refObj.add(new StringRefAddr("dataSourceName","java:comp/env/jdbc/bookstoreCPDS"));
    final Context context = new InitialContext();
    final Hashtable<?, ?> env = new Hashtable<>();
    
    final ObjectFactory factory = new SharedPoolDataSourceFactory();
    
    final Name name = new CompositeName("myDB");
    final Object obj = factory.getObjectInstance(refObj, name, context, env);
    assertNotNull(obj);
    
    final Name name2 = new CompositeName("myDB2");
    final Object obj2 = factory.getObjectInstance(refObj, name2, context, env);
    assertNotNull(obj2);
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:18,代码来源:TestFactory.java

示例8: getObjectInstance

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
public Object getObjectInstance(Object ref, Name name, Context nameCtx,
    Hashtable<?,?> env) throws Exception {

    if (!isLdapRef(ref)) {
        return null;
    }
    ObjectFactory factory = new ldapURLContextFactory();
    String[] urls = getURLs((Reference)ref);
    return factory.getObjectInstance(urls, name, nameCtx, env);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:LdapCtxFactory.java

示例9: testDataSourceFactory

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
private void testDataSourceFactory() throws Exception {
    ObjectFactory factory = new JdbcDataSourceFactory();
    assertTrue(null == factory.getObjectInstance("test", null, null, null));
    Reference ref = new Reference("java.lang.String");
    assertTrue(null == factory.getObjectInstance(ref, null, null, null));
    ref = new Reference(JdbcDataSource.class.getName());
    ref.add(new StringRefAddr("url", "jdbc:h2:mem:"));
    ref.add(new StringRefAddr("user", "u"));
    ref.add(new StringRefAddr("password", "p"));
    ref.add(new StringRefAddr("loginTimeout", "1"));
    ref.add(new StringRefAddr("description", "test"));
    JdbcDataSource ds = (JdbcDataSource) factory.getObjectInstance(
            ref, null, null, null);
    assertEquals(1, ds.getLoginTimeout());
    assertEquals("test", ds.getDescription());
    assertEquals("jdbc:h2:mem:", ds.getURL());
    assertEquals("u", ds.getUser());
    assertEquals("p", ds.getPassword());
    Reference ref2 = ds.getReference();
    assertEquals(ref.size(), ref2.size());
    assertEquals(ref.get("url").getContent().toString(),
            ref2.get("url").getContent().toString());
    assertEquals(ref.get("user").getContent().toString(),
            ref2.get("user").getContent().toString());
    assertEquals(ref.get("password").getContent().toString(),
            ref2.get("password").getContent().toString());
    assertEquals(ref.get("loginTimeout").getContent().toString(),
            ref2.get("loginTimeout").getContent().toString());
    assertEquals(ref.get("description").getContent().toString(),
            ref2.get("description").getContent().toString());
    ds.setPasswordChars("abc".toCharArray());
    assertEquals("abc", ds.getPassword());
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:34,代码来源:TestDataSource.java

示例10: assertDataSourceReferenceEmpty

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
/**
 * Make sure it is possible to create a new data source using
 * <code>Referencable</code>, that the new instance has the correct
 * default values set for the bean properties and finally that the
 * data source can be serialized/deserialized.
 *
 * @param dsDesc data source descriptor
 * @param className data source class name
 * @throws Exception on a wide variety of error conditions...
 */
private void assertDataSourceReferenceEmpty(DataSourceDescriptor dsDesc,
                                            String className)
        throws Exception {
    println("Testing recreated empty data source.");
    // Create an empty data source.
    Object ds = Class.forName(className).newInstance();
    Referenceable refDs = (Referenceable)ds;
    Reference dsAsReference = refDs.getReference();
    String factoryClassName = dsAsReference.getFactoryClassName();
    ObjectFactory factory =
        (ObjectFactory)Class.forName(factoryClassName).newInstance();
    Object recreatedDs =
        factory.getObjectInstance(dsAsReference, null, null, null);
    // Empty, recreated data source should not be the same as the one we
    // created earlier on.
    assertNotNull("Recreated datasource is <null>", recreatedDs);
    assertNotSame(recreatedDs, ds);
    compareDataSources(dsDesc, ds, recreatedDs, true);

    // Serialize and recreate data source with default values.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(ds);
    oos.flush();
    oos.close();
    ByteArrayInputStream bais =
            new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    recreatedDs = ois.readObject();
    compareDataSources(dsDesc, ds, recreatedDs, true);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:42,代码来源:DataSourceReferenceTest.java

示例11: testDataSource

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
/**
 * Tests that we can get a connection from the DataSource bound in JNDI
 * during test setup
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testDataSource() throws Exception {
	NameParser nameParser = this.ctx.getNameParser("");
	Name datasourceName = nameParser.parse("_test");
	Object obj = this.ctx.lookup(datasourceName);
	DataSource boundDs = null;

	if (obj instanceof DataSource) {
		boundDs = (DataSource) obj;
	} else if (obj instanceof Reference) {
		//
		// For some reason, this comes back as a Reference
		// instance under CruiseControl !?
		//
		Reference objAsRef = (Reference) obj;
		ObjectFactory factory = (ObjectFactory) Class.forName(
				objAsRef.getFactoryClassName()).newInstance();
		boundDs = (DataSource) factory.getObjectInstance(objAsRef,
				datasourceName, this.ctx, new Hashtable<Object, Object>());
	}

	assertTrue("Datasource not bound", boundDs != null);

	Connection con = boundDs.getConnection();
	con.close();
	assertTrue("Connection can not be obtained from data source",
			con != null);
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:35,代码来源:DataSourceTest.java

示例12: testReference

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
@Test
public void testReference() throws Exception {
   ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
   Reference reference = queue.getReference();
   String factoryName = reference.getFactoryClassName();
   Class<?> factoryClass = Class.forName(factoryName);
   ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
   Object object = factory.getObjectInstance(reference, null, null, null);
   Assert.assertNotNull(object);
   Assert.assertTrue(object instanceof ActiveMQDestination);
   Assert.assertEquals(queue, object);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:DestinationObjectFactoryTest.java

示例13: getObject

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
private <T> T getObject(Reference reference, Class<T> tClass) throws Exception {
   String factoryName = reference.getFactoryClassName();
   Class<?> factoryClass = Class.forName(factoryName);
   ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
   Object o = factory.getObjectInstance(reference, null, null, null);
   if (tClass.isAssignableFrom(tClass)) {
      return tClass.cast(o);
   } else {
      throw new IllegalStateException("Expected class, " + tClass.getName());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:12,代码来源:StringRefAddrReferenceTest.java

示例14: invokeObjectFactory

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
/**
 * Invoke the ObjectFactory.
 * 
 * @param context
 * @param objectFactory
 * @return The product of invoking the ObjectFactory's getObjectInstance()
 *         method.
 * @throws JexlEvaluationException
 * @throws IOException
 * @throws NamingException
 * @throws Exception
 */
private Object invokeObjectFactory(ExecutionContext context,
		ObjectFactory objectFactory) throws JexlEvaluationException,
		IOException, NamingException, Exception {

	if (log.isDebugEnabled()) {
		log.debug(String.format(
				"invokeObjectFactory: context, objectFactory".replaceAll(
						", ", "=%s, ") + "=%s", context, objectFactory));
	}

	// Expand text properties, and store in the Reference.
	Properties props = new Properties();
	String text = context.substitute(getNode().getTextContent());
	if (text != null) {
		props.load(new StringReader(text));
	}

	if (log.isDebugEnabled()) {
		log.debug("ObjectFactory Properties: " + props);
	}

	Reference ref = new Reference(context.substitute(getNode()
			.getAttribute("objectClassName")));
	for (String key : props.stringPropertyNames()) {
		ref.add(new StringRefAddr(key, props.getProperty(key)));
	}

	// Define other variables we don't actually care about.
	Name name = null;
	Hashtable<?, ?> env = new Hashtable<>();

	// Invoke the ObjectFactory to create the desired object.
	Object theObject = objectFactory.getObjectInstance(ref, name,
			getInitialContext(), env);
	return theObject;
}
 
开发者ID:twitmer,项目名称:sqlrodeo,代码行数:49,代码来源:ObjectFactoryAction.java

示例15: testHsqlObjectFactory

import javax.naming.spi.ObjectFactory; //导入方法依赖的package包/类
@Test
public void testHsqlObjectFactory() {

	try {
		String dsFactoryClassname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
		String dsClassname = "org.hsqldb.jdbc.JDBCDataSource";

		ObjectFactory of = (ObjectFactory) Class
				.forName(dsFactoryClassname).newInstance();

		System.out.println("Building initial context");
		InitialContext context = new InitialContext();

		Reference ref = new Reference(dsClassname);
		ref.add(new StringRefAddr("database",
				"jdbc:hsqldb:file:throwaway/myDb"));
		ref.add(new StringRefAddr("user", "scott"));
		ref.add(new StringRefAddr("password", "tiger"));

		Name name = null;
		Hashtable<?, ?> env = new Hashtable<>();
		Object product = of.getObjectInstance(ref, name, context, env);
		System.out.println("Product: " + product);

	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
开发者ID:twitmer,项目名称:sqlrodeo,代码行数:30,代码来源:TestObjectFactory2.java


注:本文中的javax.naming.spi.ObjectFactory.getObjectInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。