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