Java Code Examples for javax.naming.Reference#getFactoryClassName()

The following examples show how to use javax.naming.Reference#getFactoryClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceReferenceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: DataSourceReferenceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: DestinationObjectFactoryTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: StringRefAddrReferenceTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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());
   }
}
 
Example 5
Source File: DataSourceReferenceTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: DataSourceReferenceTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure it is possible to recreate and serialize/deserialize a
 * populated data source.
 * <p>
 * Populated means the various bean properties have non-default
 * values set.
 *
 * @param dsDesc data source descriptor
 * @param className data source class name
 * @throws Exception on a wide variety of error conditions...
 */
private void assertDataSourceReferencePopulated(
                                            DataSourceDescriptor dsDesc,
                                            String className)
        throws Exception {
    println("Testing recreated populated data source.");
    Object ds = Class.forName(className).newInstance();
    // Populate the data source.
    Iterator propIter = dsDesc.getPropertyIterator();
    while (propIter.hasNext()) {
        String property = (String)propIter.next();
        String value = dsDesc.getPropertyValue(property);
        Method getMethod = getGet(property, ds);
        Method setMethod = getSet(getMethod, ds);
        Class paramType = getMethod.getReturnType();

        if (paramType.equals(Integer.TYPE)) {
            setMethod.invoke(ds, new Object[] {Integer.valueOf(value)});
        } else if (paramType.equals(String.class)) {
            setMethod.invoke(ds, new Object[] {value});
        } else if (paramType.equals(Boolean.TYPE)) {
            setMethod.invoke(ds, new Object[] {Boolean.valueOf(value)});
        } else if (paramType.equals(Short.TYPE)) {
            setMethod.invoke(ds, new Object[] {Short.valueOf(value)});
        } else if (paramType.equals(Long.TYPE)) {
            setMethod.invoke(ds, new Object[] {Long.valueOf(value)});
        } else {
            fail("'" + property + "' not settable - update test!!");
        }
    }

    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);
    // Recreated should not be same instance as original.
    assertNotSame(recreatedDs, ds);
    compareDataSources(dsDesc, ds, recreatedDs, false);

    // Serialize and recreate.
    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, false);
}
 
Example 7
Source File: DataSourceReferenceTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure it is possible to recreate and serialize/deserialize a
 * populated data source.
 * <p>
 * Populated means the various bean properties have non-default
 * values set.
 *
 * @param dsDesc data source descriptor
 * @param className data source class name
 * @throws Exception on a wide variety of error conditions...
 */
private void assertDataSourceReferencePopulated(
                                            DataSourceDescriptor dsDesc,
                                            String className)
        throws Exception {
    println("Testing recreated populated data source.");
    Object ds = Class.forName(className).newInstance();
    // Populate the data source.
    Iterator propIter = dsDesc.getPropertyIterator();
    while (propIter.hasNext()) {
        String property = (String)propIter.next();
        String value = dsDesc.getPropertyValue(property);
        Method getMethod = getGet(property, ds);
        Method setMethod = getSet(getMethod, ds);
        Class paramType = getMethod.getReturnType();

        if (paramType.equals(Integer.TYPE)) {
            setMethod.invoke(ds, new Object[] {Integer.valueOf(value)});
        } else if (paramType.equals(String.class)) {
            setMethod.invoke(ds, new Object[] {value});
        } else if (paramType.equals(Boolean.TYPE)) {
            setMethod.invoke(ds, new Object[] {Boolean.valueOf(value)});
        } else if (paramType.equals(Short.TYPE)) {
            setMethod.invoke(ds, new Object[] {Short.valueOf(value)});
        } else if (paramType.equals(Long.TYPE)) {
            setMethod.invoke(ds, new Object[] {Long.valueOf(value)});
        } else {
            fail("'" + property + "' not settable - update test!!");
        }
    }

    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);
    // Recreated should not be same instance as original.
    assertNotSame(recreatedDs, ds);
    compareDataSources(dsDesc, ds, recreatedDs, false);

    // Serialize and recreate.
    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, false);
}
 
Example 8
Source File: ReferenceableTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 9
Source File: ReferenceableTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 10
Source File: ReferenceableTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 11
Source File: DataSourceReferenceTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Make sure it is possible to recreate and serialize/deserialize a
 * populated data source.
 * <p>
 * Populated means the various bean properties have non-default
 * values set.
 *
 * @param dsDesc data source descriptor
 * @param className data source class name
 * @throws Exception on a wide variety of error conditions...
 */
private void assertDataSourceReferencePopulated(
                                            DataSourceDescriptor dsDesc,
                                            String className)
        throws Exception {
    println("Testing recreated populated data source.");
    Object ds = Class.forName(className).newInstance();
    // Populate the data source.
    Iterator propIter = dsDesc.getPropertyIterator();
    while (propIter.hasNext()) {
        String property = (String)propIter.next();
        String value = dsDesc.getPropertyValue(property);
        Method getMethod = getGet(property, ds);
        Method setMethod = getSet(getMethod, ds);
        Class paramType = getMethod.getReturnType();

        if (paramType.equals(Integer.TYPE)) {
            setMethod.invoke(ds, new Object[] {Integer.valueOf(value)});
        } else if (paramType.equals(String.class)) {
            setMethod.invoke(ds, new Object[] {value});
        } else if (paramType.equals(Boolean.TYPE)) {
            setMethod.invoke(ds, new Object[] {Boolean.valueOf(value)});
        } else if (paramType.equals(Short.TYPE)) {
            setMethod.invoke(ds, new Object[] {Short.valueOf(value)});
        } else if (paramType.equals(Long.TYPE)) {
            setMethod.invoke(ds, new Object[] {Long.valueOf(value)});
        } else {
            fail("'" + property + "' not settable - update test!!");
        }
    }

    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);
    // Recreated should not be same instance as original.
    assertNotSame(recreatedDs, ds);
    compareDataSources(dsDesc, ds, recreatedDs, false);

    // Serialize and recreate.
    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, false);
}