當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。