本文整理匯總了Java中javax.naming.Reference.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Reference.get方法的具體用法?Java Reference.get怎麽用?Java Reference.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.Reference
的用法示例。
在下文中一共展示了Reference.get方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例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;
}
示例3: getObjectInstance
import javax.naming.Reference; //導入方法依賴的package包/類
/**
* <p>Create and return a new <code>MemoryUserDatabase</code> instance
* that has been configured according to the properties of the
* specified <code>Reference</code>. If you instance can be created,
* return <code>null</code> instead.</p>
*
* @param obj The possibly null object containing location or
* reference information that can be used in creating an object
* @param name The name of this object relative to <code>nameCtx</code>
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or <code>null</code> if <code>name</code>
* is relative to the default initial context
* @param environment The possibly null environment that is used in
* creating this object
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws Exception {
// We only know how to deal with <code>javax.naming.Reference</code>s
// that specify a class name of "org.apache.catalina.UserDatabase"
if ((obj == null) || !(obj instanceof Reference)) {
return (null);
}
Reference ref = (Reference) obj;
if (!"org.apache.catalina.UserDatabase".equals(ref.getClassName())) {
return (null);
}
// Create and configure a MemoryUserDatabase instance based on the
// RefAddr values associated with this Reference
MemoryUserDatabase database = new MemoryUserDatabase(name.toString());
RefAddr ra = null;
ra = ref.get("pathname");
if (ra != null) {
database.setPathname(ra.getContent().toString());
}
ra = ref.get("readonly");
if (ra != null) {
database.setReadonly(Boolean.parseBoolean(ra.getContent().toString()));
}
// Return the configured database instance
database.open();
// Don't try something we know won't work
if (!database.getReadonly())
database.save();
return (database);
}
示例4: initializeFrom
import javax.naming.Reference; //導入方法依賴的package包/類
void initializeFrom(Reference ref, ExceptionInterceptor exceptionInterceptor) throws SQLException {
RefAddr refAddr = ref.get(getPropertyName());
if (refAddr != null) {
String refContentAsString = (String) refAddr.getContent();
initializeFrom(refContentAsString, exceptionInterceptor);
}
}
示例5: removeFromRef
import javax.naming.Reference; //導入方法依賴的package包/類
private void removeFromRef(Reference ref, String key) {
int size = ref.size();
for (int i = 0; i < size; i++) {
RefAddr refAddr = ref.get(i);
if (refAddr.getType().equals(key)) {
ref.remove(i);
break;
}
}
}
示例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;
}
示例7: getObjectInstance
import javax.naming.Reference; //導入方法依賴的package包/類
/**
* <p>Create and return a new <code>BasicDataSource</code> instance. If no
* instance can be created, return <code>null</code> instead.</p>
*
* @param obj The possibly null object containing location or
* reference information that can be used in creating an object
* @param name The name of this object relative to <code>nameCtx</code>
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or <code>null</code> if <code>name</code>
* is relative to the default initial context
* @param environment The possibly null environment that is used in
* creating this object
*
* @exception Exception if an exception occurs creating the instance
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment) throws Exception {
// We only know how to deal with <code>javax.naming.Reference</code>s
// that specify a class name of "javax.sql.DataSource"
if ((obj == null) || !(obj instanceof Reference)) {
return null;
}
Reference ref = (Reference) obj;
boolean XA = false;
boolean ok = false;
if ("javax.sql.DataSource".equals(ref.getClassName())) {
ok = true;
}
if ("javax.sql.XADataSource".equals(ref.getClassName())) {
ok = true;
XA = true;
}
if (org.apache.tomcat.jdbc.pool.DataSource.class.getName().equals(ref.getClassName())) {
ok = true;
}
if (!ok) {
log.warn(ref.getClassName()+" is not a valid class name/type for this JNDI factory.");
return null;
}
Properties properties = new Properties();
for (int i = 0; i < ALL_PROPERTIES.length; i++) {
String propertyName = ALL_PROPERTIES[i];
RefAddr ra = ref.get(propertyName);
if (ra != null) {
String propertyValue = ra.getContent().toString();
properties.setProperty(propertyName, propertyValue);
}
}
return createDataSource(properties,nameCtx,XA);
}
示例8: 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;
}
示例9: nullSafeRefAddrStringGet
import javax.naming.Reference; //導入方法依賴的package包/類
private String nullSafeRefAddrStringGet(String referenceName, Reference ref) {
RefAddr refAddr = ref.get(referenceName);
String asString = refAddr != null ? (String) refAddr.getContent() : null;
return asString;
}