Search in sources :

Example 21 with StringRefAddr

use of javax.naming.StringRefAddr in project h2database by h2database.

the class JdbcDataSource method getReference.

/**
 * Get a new reference for this object, using the current settings.
 *
 * @return the new reference
 */
@Override
public Reference getReference() {
    debugCodeCall("getReference");
    String factoryClassName = JdbcDataSourceFactory.class.getName();
    Reference ref = new Reference(getClass().getName(), factoryClassName, null);
    ref.add(new StringRefAddr("url", url));
    ref.add(new StringRefAddr("user", userName));
    ref.add(new StringRefAddr("password", convertToString(passwordChars)));
    ref.add(new StringRefAddr("loginTimeout", String.valueOf(loginTimeout)));
    ref.add(new StringRefAddr("description", description));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 22 with StringRefAddr

use of javax.naming.StringRefAddr in project nimbus by nimbus-org.

the class WrappedDataSourceService method startService.

/**
 * 開始処理を行う。<p>
 *
 * @exception Exception 開始処理に失敗した場合
 */
public void startService() throws Exception {
    if (sourceJNDIName == null) {
        throw new IllegalArgumentException("SourceJNDIName is null.");
    }
    if (wrappedJNDIName == null) {
        throw new IllegalArgumentException("WrappedJNDIName is null.");
    }
    if (jndiRepositoryServiceName != null) {
        jndiRepository = (Repository) ServiceManagerFactory.getServiceObject(jndiRepositoryServiceName);
    }
    if (jndiRepository == null) {
        JNDIRepositoryService jndiRepositoryService = new JNDIRepositoryService();
        jndiRepositoryService.create();
        jndiRepositoryService.start();
        jndiRepository = jndiRepositoryService;
    }
    if (getConnectionWrapperClassName() != null) {
        connectionWrapperClass = Class.forName(getConnectionWrapperClassName(), true, NimbusClassLoader.getInstance());
    }
    if (connectionWrapperProperties != null && connectionWrapperProperties.size() != 0) {
        properties = new LinkedHashMap();
        final Iterator props = connectionWrapperProperties.keySet().iterator();
        while (props.hasNext()) {
            final String propName = (String) props.next();
            final Object val = connectionWrapperProperties.get(propName);
            final Property property = PropertyFactory.createProperty(propName);
            properties.put(property, val);
        }
    }
    if (getSourceDataSource() == null) {
        throw new IllegalArgumentException("SourceJNDIName can not get from JNDIRepository.");
    }
    StringRefAddr addr = new StringRefAddr("nimbus/service", getServiceNameObject().toString());
    reference = new Reference(getClass().getName(), addr, WrappedDataSourceObjectFactory.class.getName(), null);
    if (!jndiRepository.register(wrappedJNDIName, reference)) {
        throw new IllegalArgumentException("WrappedJNDIName can not register to JNDIRepository.");
    }
}
Also used : JNDIRepositoryService(jp.ossc.nimbus.service.repository.JNDIRepositoryService) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 23 with StringRefAddr

use of javax.naming.StringRefAddr in project derby by apache.

the class ClientDataSource method addBeanProperties.

/**
 * Add Java Bean properties to the reference using
 * StringRefAddr for each property. List of bean properties
 * is defined from the public getXXX() methods on this object
 * that take no arguments and return short, int, boolean or String.
 * The StringRefAddr has a key of the Java bean property name,
 * converted from the method name. E.g. traceDirectory for
 * traceDirectory.
 *
 * @param ref The referenced object
 */
private void addBeanProperties(Reference ref) {
    Properties p = getProperties(this);
    Enumeration<?> e = p.propertyNames();
    while (e.hasMoreElements()) {
        String propName = (String) e.nextElement();
        Object value = p.getProperty(propName);
        if (value != null) {
            ref.add(new StringRefAddr(propName, value.toString()));
        }
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Properties(java.util.Properties)

Example 24 with StringRefAddr

use of javax.naming.StringRefAddr in project jaybird by FirebirdSQL.

the class FBAbstractCommonDataSource method updateReference.

/**
 * Updates the supplied reference with RefAddr properties relevant to this class.
 *
 * @param ref Reference to update
 * @param instance Instance of this class to obtain values
 */
protected static void updateReference(Reference ref, FBAbstractCommonDataSource instance) {
    synchronized (instance.lock) {
        ref.add(new StringRefAddr(REF_DESCRIPTION, instance.getDescription()));
        ref.add(new StringRefAddr(REF_SERVER_NAME, instance.getServerName()));
        if (instance.getPortNumber() != 0) {
            ref.add(new StringRefAddr(REF_PORT_NUMBER, Integer.toString(instance.getPortNumber())));
        }
        ref.add(new StringRefAddr(REF_DATABASE_NAME, instance.getDatabaseName()));
        byte[] data = DataSourceFactory.serialize(instance.connectionProperties);
        ref.add(new BinaryRefAddr(REF_PROPERTIES, data));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) BinaryRefAddr(javax.naming.BinaryRefAddr)

Example 25 with StringRefAddr

use of javax.naming.StringRefAddr in project activemq-artemis by apache.

the class JNDIReferenceFactory method createReference.

/**
 * Create a Reference instance from a JNDIStorable object
 *
 * @param instanceClassName
 *     The name of the class that is being created.
 * @param po
 *     The properties object to use when configuring the new instance.
 *
 * @return Reference
 *
 * @throws NamingException if an error occurs while creating the new instance.
 */
public static Reference createReference(String instanceClassName, JNDIStorable po) throws NamingException {
    Reference result = new Reference(instanceClassName, JNDIReferenceFactory.class.getName(), null);
    try {
        Properties props = po.getProperties();
        for (Enumeration iter = props.propertyNames(); iter.hasMoreElements(); ) {
            String key = (String) iter.nextElement();
            result.add(new StringRefAddr(key, props.getProperty(key)));
        }
    } catch (Exception e) {
        throw new NamingException(e.getMessage());
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) Properties(java.util.Properties) NamingException(javax.naming.NamingException)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3