javax.naming.Reference.getFactoryClassName()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中javax.naming.Reference.getFactoryClassName方法的一些代码示例,展示了Reference.getFactoryClassName的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.getFactoryClassName方法的具体详情如下:
包路径:javax.naming.Reference
类名称:Reference
方法名:getFactoryClassName

Reference.getFactoryClassName介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
  try {
    final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
    ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
    if (factory instanceof ServiceAwareObjectFactory) {
      ((ServiceAwareObjectFactory) factory).injectServiceRegistry(currentServiceContainer());
    }
    return factory;
  } catch (Throwable t) {
    throw NamingLogger.ROOT_LOGGER.objectFactoryCreationFailure(t);
  }
}

代码示例来源:origin: wildfly/wildfly

private ObjectFactory factoryFromReference(final Reference reference, final Hashtable<?, ?> environment) throws Exception {
  if (reference.getFactoryClassName() == null) {
    return lookForURLs(reference, environment);
  }
  if (reference instanceof ModularReference) {
    return factoryFromModularReference(ModularReference.class.cast(reference), environment);
  }
  return factoryFromReference(reference, WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(), environment);
}

代码示例来源:origin: tomcat/naming-factory

/**
 * Retrieves the class name of the factory of the object to which this 
 * reference refers.
 */
public String getFactoryClassName() {
  String factory = super.getFactoryClassName();
  if (factory != null) {
    return factory;
  } else {
    factory = System.getProperty(Context.OBJECT_FACTORIES);
    if (factory != null) {
      return null;
    } else {
      return DEFAULT_FACTORY;
    }
  }
}

代码示例来源:origin: tomcat/naming-factory

/**
 * Retrieves the class name of the factory of the object to which this 
 * reference refers.
 */
public String getFactoryClassName() {
  String factory = super.getFactoryClassName();
  if (factory != null) {
    return factory;
  } else {
    factory = System.getProperty(Context.OBJECT_FACTORIES);
    if (factory != null) {
      return null;
    } else {
      return DEFAULT_FACTORY;
    }
  }
}

代码示例来源:origin: org.apache.qpid/qpid-jca

private Object dereference(Reference ref) throws Exception
{
  ObjectFactory objFactory = (ObjectFactory) Class.forName(
      ref.getFactoryClassName()).newInstance();
  return objFactory.getObjectInstance(ref, null, null, null);
}

代码示例来源:origin: org.gatein.naming/gatein-naming

private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
    try {
      final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
      ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
      return factory;
    } catch (Throwable t) {
      throw namingException("Failed to create object factory from classloader.", t);
    }
  }
}

代码示例来源:origin: org.apache.qpid/qpid-jca

private Object dereference(Reference ref) throws Exception
{
  ObjectFactory objFactory = (ObjectFactory) Class.forName(
      ref.getFactoryClassName()).newInstance();
  return objFactory.getObjectInstance(ref, null, null, null);
}

代码示例来源:origin: org.jboss/jboss-remote-naming

private Object getObjectInstance(final Reference reference, final Name name, final Hashtable<?, ?> environment) throws NamingException {
  try {
    final Class<?> factoryClass = Thread.currentThread().getContextClassLoader().loadClass(reference.getFactoryClassName());
    ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
    return factory.getObjectInstance(reference, name, this, environment);
  } catch(NamingException e) {
    throw e;
  } catch(Throwable t) {
    throw namingException("failed to get object instance from reference", t);
  }
}

代码示例来源:origin: org.wildfly/wildfly-naming

private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
  try {
    final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
    ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
    if (factory instanceof ServiceAwareObjectFactory) {
      ((ServiceAwareObjectFactory) factory).injectServiceRegistry(currentServiceContainer());
    }
    return factory;
  } catch (Throwable t) {
    throw NamingLogger.ROOT_LOGGER.objectFactoryCreationFailure(t);
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-naming

private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
  try {
    final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
    ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
    if (factory instanceof ServiceAwareObjectFactory) {
      ((ServiceAwareObjectFactory) factory).injectServiceRegistry(currentServiceContainer());
    }
    return factory;
  } catch (Throwable t) {
    throw NamingLogger.ROOT_LOGGER.objectFactoryCreationFailure(t);
  }
}

代码示例来源:origin: org.jboss.as/jboss-as-naming

private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
  try {
    final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
    ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
    if (factory instanceof ServiceAwareObjectFactory) {
      ((ServiceAwareObjectFactory) factory).injectServiceRegistry(currentServiceContainer());
    }
    return factory;
  } catch (Throwable t) {
    throw MESSAGES.objectFactoryCreationFailure(t);
  }
}

代码示例来源:origin: apache/activemq-artemis

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());
 }
}

代码示例来源:origin: org.jboss.eap/wildfly-naming

private ObjectFactory factoryFromReference(final Reference reference, final Hashtable<?, ?> environment) throws Exception {
  if (reference.getFactoryClassName() == null) {
    return lookForURLs(reference, environment);
  }
  if (reference instanceof ModularReference) {
    return factoryFromModularReference(ModularReference.class.cast(reference), environment);
  }
  return factoryFromReference(reference, WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(), environment);
}

代码示例来源:origin: org.wildfly/wildfly-naming

private ObjectFactory factoryFromReference(final Reference reference, final Hashtable<?, ?> environment) throws Exception {
  if (reference.getFactoryClassName() == null) {
    return lookForURLs(reference, environment);
  }
  if (reference instanceof ModularReference) {
    return factoryFromModularReference(ModularReference.class.cast(reference), environment);
  }
  return factoryFromReference(reference, WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(), environment);
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testReferenceCF() throws Exception {
 Reference cfRef = ((Referenceable) cf).getReference();
 String factoryName = cfRef.getFactoryClassName();
 Class<?> factoryClass = Class.forName(factoryName);
 ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
 Object instance = factory.getObjectInstance(cfRef, null, null, null);
 ProxyAssertSupport.assertTrue(instance instanceof ActiveMQConnectionFactory);
 ActiveMQJMSConnectionFactory cf2 = (ActiveMQJMSConnectionFactory) instance;
 simpleSendReceive(cf2, queue1);
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testReferenceTopic() throws Exception {
 Reference topicRef = ((Referenceable) ActiveMQServerTestCase.topic1).getReference();
 String factoryName = topicRef.getFactoryClassName();
 Class factoryClass = Class.forName(factoryName);
 ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
 Object instance = factory.getObjectInstance(topicRef, null, null, null);
 ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
 ActiveMQTopic topic2 = (ActiveMQTopic) instance;
 ProxyAssertSupport.assertEquals(ActiveMQServerTestCase.topic1.getTopicName(), topic2.getTopicName());
 simpleSendReceive(cf, topic2);
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testReferenceQueue() throws Exception {
 Reference queueRef = ((Referenceable) queue1).getReference();
 String factoryName = queueRef.getFactoryClassName();
 Class<?> factoryClass = Class.forName(factoryName);
 ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
 Object instance = factory.getObjectInstance(queueRef, null, null, null);
 ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
 ActiveMQQueue queue2 = (ActiveMQQueue) instance;
 ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
 simpleSendReceive(cf, queue2);
}

代码示例来源:origin: apache/activemq-artemis

@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);
}

代码示例来源:origin: hibernate/hibernate-ogm

@Test
public void testJNDIReference() throws Exception {
  final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ogm", TestHelper.getDefaultTestSettings() );
  SessionFactory factory = (SessionFactory) emf;
  Reference reference = factory.getReference();
  assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() );
  assertThat( reference.getFactoryClassName() ).isEqualTo( ObjectFactoryImpl.class.getName() );
  assertThat( reference.get( 0 ) ).isNotNull();
  assertThat( reference.getFactoryClassLocation() ).isNull();
  ObjectFactory objFactory = new ObjectFactoryImpl();
  SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null );
  assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
  assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() );
  emf.close();
}

代码示例来源:origin: hibernate/hibernate-ogm

@Test
public void testGetReferenceImplementation() throws Exception {
  final Session session = openSession();
  SessionFactory factory = session.getSessionFactory();
  assertThat( factory.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
  Reference reference = factory.getReference();
  assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() );
  assertThat( reference.getFactoryClassName() ).isEqualTo( ObjectFactoryImpl.class.getName() );
  assertThat( reference.get( 0 ) ).isNotNull();
  assertThat( reference.getFactoryClassLocation() ).isNull();
  ObjectFactory objFactory = new ObjectFactoryImpl();
  SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null );
  assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
  assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() );
  session.close();
}

相关文章