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


Java Referenceable.getReference方法代码示例

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


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

示例1: assertDataSourceReferenceEmpty

import javax.naming.Referenceable; //导入方法依赖的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

示例2: assertDataSourceReferencePopulated

import javax.naming.Referenceable; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:65,代码来源:DataSourceReferenceTest.java


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