Example usage for javax.naming Reference get

List of usage examples for javax.naming Reference get

Introduction

In this page you can find the example usage for javax.naming Reference get.

Prototype

public RefAddr get(int posn) 

Source Link

Document

Retrieves the address at index posn.

Usage

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathBindableRepository.java

@Override
protected JackrabbitRepository createRepository() throws RepositoryException {
    Reference reference = this.getReference();
    String configFilePath = reference.get(CONFIGFILEPATH_ADDRTYPE).getContent().toString();
    if (StringUtils.startsWith(configFilePath, ClasspathPropertiesInitializer.CLASSPATH_PREFIX)) {
        InputStream resource = getClass().getResourceAsStream(
                StringUtils.substringAfter(configFilePath, ClasspathPropertiesInitializer.CLASSPATH_PREFIX));
        if (resource != null) {
            RepositoryConfig config = RepositoryConfig.create(resource,
                    reference.get(REPHOMEDIR_ADDRTYPE).getContent().toString());
            return RepositoryImpl.create(config);
        }//from   w w  w. j  a  v  a  2  s . c  o  m
    }
    return super.createRepository();
}

From source file:Rebind.java

public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable<?, ?> env) throws Exception {

    if (obj instanceof Reference) {
        Reference ref = (Reference) obj;

        if (ref.getClassName().equals(Fruit.class.getName())) {
            RefAddr addr = ref.get("fruit");
            if (addr != null) {
                return new Fruit((String) addr.getContent());
            }/*from w  w  w.  j av  a 2 s  . c  o m*/
        }
    }
    return null;
}

From source file:NonSerializableFactory.java

/** Transform the obj Reference bound into the JNDI namespace into the
actual non-Serializable object./* w  ww . j a v a2s  .  co m*/
        
@param obj the object bound in the JNDI namespace. This must be an implementation
of javax.naming.Reference with a javax.naming.RefAddr of type "nns" whose
content is the String key used to location the non-Serializable object in the 
NonSerializableFactory map.
@param name ignored.
@param nameCtx ignored.
@param env ignored.
        
@return the non-Serializable object associated with the obj Reference if one
exists, null if one does not.
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception { // Get the nns value from the Reference obj and use it as the map key
    Reference ref = (Reference) obj;
    RefAddr addr = ref.get("nns");
    String key = (String) addr.getContent();
    Object target = wrapperMap.get(key);
    return target;
}

From source file:com.frameworkset.commons.dbcp2.BasicDataSourceFactory.java

/**
 * Collects warnings and info messages.  Warnings are generated when an obsolete
 * property is set.  Unknown properties generate info messages.
 *
 * @param ref Reference to check properties of
 * @param name Name provided to getObject
 * @param warnings container for warning messages
 * @param infoMessages container for info messages
 *//*  w  w  w  .j  a v a 2  s  .c  o m*/
private void validatePropertyNames(Reference ref, Name name, List<String> warnings, List<String> infoMessages) {
    final List<String> allPropsAsList = Arrays.asList(ALL_PROPERTIES);
    final String nameString = name != null ? "Name = " + name.toString() + " " : "";
    if (NUPROP_WARNTEXT != null && !NUPROP_WARNTEXT.keySet().isEmpty()) {
        for (String propertyName : NUPROP_WARNTEXT.keySet()) {
            final RefAddr ra = ref.get(propertyName);
            if (ra != null && !allPropsAsList.contains(ra.getType())) {
                final StringBuilder stringBuilder = new StringBuilder(nameString);
                final String propertyValue = ra.getContent().toString();
                stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)).append(" You have set value of \"")
                        .append(propertyValue).append("\" for \"").append(propertyName)
                        .append("\" property, which is being ignored.");
                warnings.add(stringBuilder.toString());
            }
        }
    }

    final Enumeration<RefAddr> allRefAddrs = ref.getAll();
    while (allRefAddrs.hasMoreElements()) {
        final RefAddr ra = allRefAddrs.nextElement();
        final String propertyName = ra.getType();
        // If property name is not in the properties list, we haven't warned on it
        // and it is not in the "silent" list, tell user we are ignoring it.
        if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.keySet().contains(propertyName)
                || SILENT_PROPERTIES.contains(propertyName))) {
            final String propertyValue = ra.getContent().toString();
            final StringBuilder stringBuilder = new StringBuilder(nameString);
            stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue)
                    .append("\" for \"").append(propertyName).append("\" property");
            infoMessages.add(stringBuilder.toString());
        }
    }
}

From source file:com.frameworkset.commons.dbcp2.BasicDataSourceFactory.java

/**
 * <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/* www.  j  ava2 s.c om*/
 *
 * @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;
    if (!"javax.sql.DataSource".equals(ref.getClassName())) {
        return null;
    }

    // Check property names and log warnings about obsolete and / or unknown properties
    final List<String> warnings = new ArrayList<String>();
    final List<String> infoMessages = new ArrayList<String>();
    validatePropertyNames(ref, name, warnings, infoMessages);
    for (String warning : warnings) {
        log.warn(warning);
    }
    for (String infoMessage : infoMessages) {
        log.info(infoMessage);
    }

    Properties properties = new Properties();
    for (String propertyName : ALL_PROPERTIES) {
        RefAddr ra = ref.get(propertyName);
        if (ra != null) {
            String propertyValue = ra.getContent().toString();
            properties.setProperty(propertyName, propertyValue);
        }
    }

    return createDataSource(properties);
}

From source file:org.apache.jackrabbit.core.jndi.BindableRepositoryFactory.java

/**
 * {@inheritDoc}//from   w ww  .j a v a2 s  .  c o m
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment)
        throws Exception {
    if (obj instanceof Reference) {
        Reference ref = (Reference) obj;
        synchronized (cache) {
            if (cache.containsKey(ref)) {
                return cache.get(ref);
            } else {
                String configFilePath = (String) ref.get(BindableRepository.CONFIGFILEPATH_ADDRTYPE)
                        .getContent();
                String repHomeDir = (String) ref.get(BindableRepository.REPHOMEDIR_ADDRTYPE).getContent();
                return createInstance(configFilePath, repHomeDir);
            }
        }
    }
    return null;
}

From source file:org.enhydra.jdbc.pool.StandardPoolDataSource.java

public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {

    super.getObjectInstance(refObj, name, nameCtx, env);
    Reference ref = (Reference) refObj;
    this.setLifeTime(Long.parseLong((String) ref.get("lifeTime").getContent()));
    this.setJdbcTestStmt((String) ref.get("jdbcTestStmt").getContent());
    this.setMaxSize(Integer.parseInt((String) ref.get("maxSize").getContent()));
    this.setMinSize(Integer.parseInt((String) ref.get("minSize").getContent()));
    this.setDataSourceName((String) ref.get("dataSourceName").getContent());
    InitialContext ictx = new InitialContext(env);
    cpds = (ConnectionPoolDataSource) ictx.lookup(this.dataSourceName);
    return this;
}

From source file:org.enhydra.jdbc.pool.StandardXAPoolDataSource.java

public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {

    super.getObjectInstance(refObj, name, nameCtx, env);
    Reference ref = (Reference) refObj;
    InitialContext ictx = new InitialContext(env);
    this.setTransactionManagerName((String) ref.get("transactionManagerName").getContent());
    if (this.transactionManagerName != null) {
        try {/*from   w  ww.j  av  a 2s. c  om*/
            this.setTransactionManager((TransactionManager) ictx.lookup(this.transactionManagerName));
        } catch (NamingException e) {
            // ignore, TransactionManager might be set later enlisting the XAResouce on the Transaction
        }
    }

    this.setDataSource((XADataSource) ictx.lookup(this.dataSourceName));
    log.debug("StandardXAPoolDataSource:getObjectInstance: instance created");
    return this;
}

From source file:org.enhydra.jdbc.standard.StandardDataSource.java

/**
 * Methods inherited from ObjectFactory/*from w w  w .  j a  va  2  s  .  c  o m*/
 */
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {
    Reference ref = (Reference) refObj;
    this.setDriverName((String) ref.get("driverName").getContent());
    this.setUrl((String) ref.get("url").getContent());
    this.setUser((String) ref.get("user").getContent());
    this.setPassword((String) ref.get("password").getContent());
    this.setDescription((String) ref.get("description").getContent());
    this.setLoginTimeout(Integer.parseInt((String) ref.get("loginTimeout").getContent()));
    this.setTransactionIsolation(Integer.parseInt((String) ref.get("transIsolation").getContent()));
    return this;
}

From source file:org.enhydra.jdbc.standard.StandardXADataSource.java

public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {

    super.getObjectInstance(refObj, name, nameCtx, env);
    Reference ref = (Reference) refObj;
    InitialContext ictx = new InitialContext(env);
    this.setTransactionManagerName((String) ref.get("transactionManagerName").getContent());
    if (this.transactionManagerName != null) {
        try {//from w w  w.j a v a2 s  .  co  m
            this.setTransactionManager((TransactionManager) ictx.lookup(this.transactionManagerName));
        } catch (NamingException e) {
            // ignore, TransactionManager might be set later enlisting the XAResouce on the Transaction
        }
    }
    log.debug("StandardXADataSource:getObjectInstance: instance created");
    return this;
}