本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}