当前位置: 首页>>代码示例>>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;未经允许,请勿转载。