當前位置: 首頁>>代碼示例>>Java>>正文


Java Reference類代碼示例

本文整理匯總了Java中javax.naming.Reference的典型用法代碼示例。如果您正苦於以下問題:Java Reference類的具體用法?Java Reference怎麽用?Java Reference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Reference類屬於javax.naming包,在下文中一共展示了Reference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addEjb

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

	// Create a reference to the EJB.
	Reference ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
	// Adding the additional parameters, if any
	Iterator<String> params = ejb.listProperties();
	while (params.hasNext()) {
		String paramName = params.next();
		String paramValue = (String) ejb.getProperty(paramName);
		StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
		ref.add(refAddr);
	}
	try {
		createSubcontexts(envCtx, ejb.getName());
		envCtx.bind(ejb.getName(), ref);
	} catch (NamingException e) {
		logger.error(sm.getString("naming.bindFailed", e));
	}

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:24,代碼來源:NamingContextListener.java

示例2: getObjectInstance

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:DataSourceLinkFactory.java

示例3: getObjectInstance

import javax.naming.Reference; //導入依賴的package包/類
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();

    String type = ref.getClassName();
    Object o = Class.forName(type).newInstance();

    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent()!=null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value,false)) {

        } else {
            log.debug("Property not configured["+param+"]. No setter found on["+o+"].");
        }
    }
    return o;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:27,代碼來源:GenericNamingResourcesFactory.java

示例4: getObjectInstance

import javax.naming.Reference; //導入依賴的package包/類
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
        Hashtable<?,?> environment) throws Exception {

    if (obj instanceof Reference) {
        Reference ref = (Reference)obj;
        String className = ref.getClassName();

        if (className == null) {
            throw new RuntimeException();
        }

        if (className.equals("org.apache.naming.resources.TesterObject")) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Class<?> clazz =
                cl.loadClass("org.apache.naming.resources.TesterObject");
            return clazz.newInstance();
        }
    }
    return null;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:22,代碼來源:TesterFactory.java

示例5: addResourceEnvRef

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator<String> params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:26,代碼來源:NamingContextListener.java

示例6: storeToRef

import javax.naming.Reference; //導入依賴的package包/類
protected void storeToRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToStore = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToStore.storeTo(ref);
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.errorNotExpected"), getExceptionInterceptor());
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:18,代碼來源:ConnectionPropertiesImpl.java

示例7: getReference

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:31,代碼來源:MysqlDataSource.java

示例8: getObjectInstance

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Creates a JDBCDataSource object using the location or reference
 * information specified.<p>
 *
 * The Reference object should support the properties, database, user,
 * password.
 *
 * @param obj The reference information used in creating a
 *      JDBCDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created JDBCDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.JDBCDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        JDBCDataSource ds = new JDBCDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:35,代碼來源:JDBCDataSourceFactory.java

示例9: testBug16791

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
 * due to Reference containing RefAddrs with null content.
 * 
 * @throws Exception
 *             if the test fails
 */
public void testBug16791() throws Exception {
    MysqlDataSource myDs = new MysqlDataSource();
    myDs.setUrl(dbUrl);
    Reference asRef = myDs.getReference();
    System.out.println(asRef);

    removeFromRef(asRef, "port");
    removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
    removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
    removeFromRef(asRef, "serverName");
    removeFromRef(asRef, "databaseName");

    //MysqlDataSource newDs = (MysqlDataSource)
    new MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:23,代碼來源:DataSourceRegressionTest.java

示例10: initializeFromRef

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Initializes driver properties that come from a JNDI reference (in the
 * case of a javax.sql.DataSource bound into some name service that doesn't
 * handle Java objects directly).
 * 
 * @param ref
 *            The JNDI Reference that holds RefAddrs for all properties
 * @throws SQLException
 */
protected void initializeFromRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToSet.initializeFrom(ref, getExceptionInterceptor());
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException("Internal properties failure", SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
        }
    }

    postInitialization();
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:29,代碼來源:ConnectionPropertiesImpl.java

示例11: addEjb

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

    // Create a reference to the EJB.
    Reference ref = new EjbRef
        (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:25,代碼來源:NamingContextListener.java

示例12: addEjb

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

    // Create a reference to the EJB.
    Reference ref = new EjbRef
        (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = (String) params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:NamingContextListener.java

示例13: addResourceEnvRef

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = (String) params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:NamingContextListener.java

示例14: getObjectInstance

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Create a new DataSource instance.
 * 
 * @param obj
 *            The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
		throws NamingException {
	Object result = super.getObjectInstance(obj, name, nameCtx, environment);
	// Can we process this request?
	if (result != null) {
		Reference ref = (Reference) obj;
		RefAddr userAttr = ref.get("username");
		RefAddr passAttr = ref.get("password");
		if (userAttr.getContent() != null && passAttr.getContent() != null) {
			result = wrapDataSource(result, userAttr.getContent().toString(), passAttr.getContent().toString());
		}
	}
	return result;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:22,代碼來源:DataSourceLinkFactory.java

示例15: addEjb

import javax.naming.Reference; //導入依賴的package包/類
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

    // Create a reference to the EJB.
    Reference ref = new EjbRef
        (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    addAdditionalParameters(ejb.getNamingResources(), ref, ejb.getName());
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        log(sm.getString("naming.bindFailed", e));
    }

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:19,代碼來源:NamingContextListener.java


注:本文中的javax.naming.Reference類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。