Search in sources :

Example 21 with Reference

use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.

the class SharedPoolDataSource method getReference.

/**
 * Returns a <code>SharedPoolDataSource</code> {@link Reference}.
 */
@Override
public Reference getReference() throws NamingException {
    Reference ref = new Reference(getClass().getName(), SharedPoolDataSourceFactory.class.getName(), null);
    ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 22 with Reference

use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.

the class DriverAdapterCPDS method getReference.

// ----------------------------------------------------------------------
// Referenceable implementation
/**
 * <CODE>Referenceable</CODE> implementation.
 */
@Override
public Reference getReference() throws NamingException {
    // this class implements its own factory
    String factory = getClass().getName();
    Reference ref = new Reference(getClass().getName(), factory, null);
    ref.add(new StringRefAddr("description", getDescription()));
    ref.add(new StringRefAddr("driver", getDriver()));
    ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
    ref.add(new StringRefAddr("password", getPassword()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
    ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
    ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
    ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
    ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
    ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 23 with Reference

use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.

the class BasicDataSourceFactory method getObjectInstance.

// -------------------------------------------------- ObjectFactory Methods
/**
 * <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 {
    // 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<>();
    final List<String> infoMessages = new ArrayList<>();
    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);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 24 with Reference

use of javax.naming.Reference in project kernel by exoplatform.

the class HikariDataSourceFactory method getObjectInstance.

/**
 * {@inheritDoc}
 */
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;
    if (!"javax.sql.DataSource".equals(ref.getClassName())) {
        return null;
    }
    Properties properties = new Properties();
    for (int i = 0; i < ref.size(); i++) {
        String propertyName = ref.get(i).getType();
        RefAddr ra = ref.get(propertyName);
        if (ra != null) {
            String propertyValue = ra.getContent().toString();
            properties.setProperty(propertyName, propertyValue);
        }
    }
    return createDataSource(properties);
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) Properties(java.util.Properties)

Example 25 with Reference

use of javax.naming.Reference in project kernel by exoplatform.

the class InitialContextBinder method bind.

/**
 * Constructs references from params, binds in initial contexts and persists list of all binded
 * references into file.
 *
 * @param bindName
 *          bind name
 * @param className
 *          class name
 * @param factory
 *          factory name
 * @param factoryLocation
 *          factory location
 * @param refAddr
 *          map of references's properties
 *
 * @throws NamingException
 *          if error occurs due to binding
 * @throws XMLStreamException
 * @throws FileNotFoundException
 */
public void bind(String bindName, String className, String factory, String factoryLocation, Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException {
    Reference reference = new Reference(className, factory, factoryLocation);
    for (Map.Entry<String, String> entry : refAddr.entrySet()) {
        reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
    }
    bindInternally(bindName, reference);
    saveBindings();
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12