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


Java Reference.getClassName方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: getObjectInstance

import javax.naming.Reference; //導入方法依賴的package包/類
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment)
    throws NamingException {
    
    if (!(obj instanceof ResourceLinkRef))
        return null;

    // Can we process this request?
    Reference ref = (Reference) obj;

    String type = ref.getClassName();

    // Read the global ref addr
    String globalName = null;
    RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME);
    if (refAddr != null) {
        globalName = refAddr.getContent().toString();
        Object result = null;
        result = globalContext.lookup(globalName);
        // FIXME: Check type
        return result;
    }

    return (null);

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

示例4: 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 {

    if (!(obj instanceof ResourceLinkRef)) {
        return null;
    }

    // Can we process this request?
    Reference ref = (Reference) obj;

    // Read the global ref addr
    String globalName = null;
    RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME);
    if (refAddr != null) {
        globalName = refAddr.getContent().toString();
        // Confirm that the current web application is currently configured
        // to access the specified global resource
        if (!validateGlobalResourceAccess(globalName)) {
            return null;
        }
        Object result = null;
        result = globalContext.lookup(globalName);
        // Check the expected type
        String expectedClassName = ref.getClassName();
        if (expectedClassName == null) {
            throw new IllegalArgumentException(
                    sm.getString("resourceLinkFactory.nullType", name, globalName));
        }
        try {
            Class<?> expectedClazz = Class.forName(
                    expectedClassName, true, Thread.currentThread().getContextClassLoader());
            if (!expectedClazz.isAssignableFrom(result.getClass())) {
                throw new IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType",
                        name, globalName, expectedClassName, result.getClass().getName()));
            }
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(sm.getString("resourceLinkFactory.unknownType",
                    name, globalName, expectedClassName), e);
        }
        return result;
    }

    return null;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:51,代碼來源:ResourceLinkFactory.java

示例5: getObjectInstance

import javax.naming.Reference; //導入方法依賴的package包/類
/**
 * @param refObj
 * @param nm
 * @param ctx
 * @param env
 * @throws Exception
 */
public Object getObjectInstance(Object refObj, Name nm, Context ctx, Hashtable<?, ?> env) throws Exception {
    Reference ref = (Reference) refObj;
    String className = ref.getClassName();

    if ((className != null)
            && (className.equals(DATA_SOURCE_CLASS_NAME) || className.equals(POOL_DATA_SOURCE_CLASS_NAME) || className.equals(XA_DATA_SOURCE_CLASS_NAME))) {
        MysqlDataSource dataSource = null;

        try {
            dataSource = (MysqlDataSource) Class.forName(className).newInstance();
        } catch (Exception ex) {
            throw new RuntimeException("Unable to create DataSource of class '" + className + "', reason: " + ex.toString());
        }

        int portNumber = 3306;

        String portNumberAsString = nullSafeRefAddrStringGet("port", ref);

        if (portNumberAsString != null) {
            portNumber = Integer.parseInt(portNumberAsString);
        }

        dataSource.setPort(portNumber);

        String user = nullSafeRefAddrStringGet(NonRegisteringDriver.USER_PROPERTY_KEY, ref);

        if (user != null) {
            dataSource.setUser(user);
        }

        String password = nullSafeRefAddrStringGet(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, ref);

        if (password != null) {
            dataSource.setPassword(password);
        }

        String serverName = nullSafeRefAddrStringGet("serverName", ref);

        if (serverName != null) {
            dataSource.setServerName(serverName);
        }

        String databaseName = nullSafeRefAddrStringGet("databaseName", ref);

        if (databaseName != null) {
            dataSource.setDatabaseName(databaseName);
        }

        String explicitUrlAsString = nullSafeRefAddrStringGet("explicitUrl", ref);

        if (explicitUrlAsString != null) {
            if (Boolean.valueOf(explicitUrlAsString).booleanValue()) {
                dataSource.setUrl(nullSafeRefAddrStringGet("url", ref));
            }
        }

        dataSource.setPropertiesViaRef(ref);

        return dataSource;
    }

    // We can't create an instance of the reference
    return null;
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:72,代碼來源:MysqlDataSourceFactory.java

示例6: 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 {

	if (!(obj instanceof ResourceLinkRef)) {
		return null;
	}

	// Can we process this request?
	Reference ref = (Reference) obj;

	// Read the global ref addr
	String globalName = null;
	RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME);
	if (refAddr != null) {
		globalName = refAddr.getContent().toString();
		// Confirm that the current web application is currently configured
		// to access the specified global resource
		if (!validateGlobalResourceAccess(globalName)) {
			return null;
		}
		Object result = null;
		result = globalContext.lookup(globalName);
		// Check the expected type
		String expectedClassName = ref.getClassName();
		if (expectedClassName == null) {
			throw new IllegalArgumentException(sm.getString("resourceLinkFactory.nullType", name, globalName));
		}
		try {
			Class<?> expectedClazz = Class.forName(expectedClassName, true,
					Thread.currentThread().getContextClassLoader());
			if (!expectedClazz.isAssignableFrom(result.getClass())) {
				throw new IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType", name, globalName,
						expectedClassName, result.getClass().getName()));
			}
		} catch (ClassNotFoundException e) {
			throw new IllegalArgumentException(
					sm.getString("resourceLinkFactory.unknownType", name, globalName, expectedClassName), e);
		}
		return result;
	}

	return null;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:51,代碼來源:ResourceLinkFactory.java


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