Example usage for javax.naming CompositeName CompositeName

List of usage examples for javax.naming CompositeName CompositeName

Introduction

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

Prototype

public CompositeName(String n) throws InvalidNameException 

Source Link

Document

Constructs a new composite name instance by parsing the string n using the composite name syntax (left-to-right, slash separated).

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    CompositeName composite = new CompositeName("cn=John,o=hits/summary.txt");
    String first = composite.get(0);
    String last = composite.get(composite.size() - 1);

    composite.add(0, "yourname.com");
    composite.remove(2);//from   w w  w  . j  av  a  2s.c om
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*from  w  w  w .  j a v  a2 s . c  o m*/
public void testGetObjectInstance_WrongClass() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnblds");

    //
    // not javax.sql.DataSource --> exception
    //
    Reference ref = new Reference("javax.sql.DataSourceeeee");
    Object result = null;
    boolean exception = false;

    try {
        result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    } catch (NamingException e) {
        exception = true;
    }
    assertTrue(exception);
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *///w  w w. ja  v a2  s  . co m
public void testGetObjectInstance_WitWrongJNDIName() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnbl");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr url = new StringRefAddr("url", "jdbc:hsqldb:hsql://localhost/funambol");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource);

    BasicDataSource bds = (BasicDataSource) result;
    assertNull(bds.getPassword());
    assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl());
    //
    // These are read from the db.xml since there is not the fnbl.xml file
    //
    assertEquals("db", bds.getUsername());
    assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName());

}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*from  w  w w . j  av a 2 s  .c o m*/
public void testGetObjectInstance_fnblds() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnblds");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr minIdle = new StringRefAddr("minIdle", "3");
    ref.add(minIdle);

    //
    // At the end this should be overwritten by the value in the fnblds.xml file
    //
    RefAddr url = new StringRefAddr("url", "this-is-the-url");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource);

    BasicDataSource bds = (BasicDataSource) result;
    assertEquals(3, bds.getMinIdle());
    //
    // These are read from the db.xml
    //
    assertEquals("db", bds.getUsername());
    assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName());

    //
    // These are read from the fnblds.xml
    //
    assertEquals("", bds.getPassword());
    assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl());
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*w w  w  .ja va 2 s .c o  m*/
public void testGetObjectInstance_fnblcore() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnblcore");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr minIdle = new StringRefAddr("minIdle", "3");
    ref.add(minIdle);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource);

    BasicDataSource bds = (BasicDataSource) result;
    assertEquals(3, bds.getMinIdle());
    //
    // These are read from the db.xml
    //
    assertEquals("db", bds.getUsername());
    assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName());

    //
    // These are read from the fnblds.xml
    //
    assertEquals("ss", bds.getPassword());
    assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl());
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*  w w w .j  a v a2 s  . c  o m*/
public void testGetObjectInstance_fnbluser() throws Exception {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnbluser");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr userName = new StringRefAddr("minIdle", "7");
    ref.add(userName);

    //
    // At the end this should be overwritten by the value in the fnblds.xml file
    //
    RefAddr url = new StringRefAddr("url", "this-is-the-url");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource);

    BasicDataSource bds = (BasicDataSource) result;
    assertEquals(7, bds.getMinIdle());

    //
    // These are read from the fnbluser.xml
    //
    assertEquals("fnbluserpwd", bds.getUsername());
    assertEquals("fnblpwd", bds.getPassword());
    assertEquals("org.fnbluser", bds.getDriverClassName());
    assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl());

}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*from   ww  w . j  a  v  a  2s .  co  m*/
public void testGetObjectInstance_fnblcore_with_wrappedFactory() throws Exception {

    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnblcore");

    Reference ref = new Reference("javax.sql.DataSource");

    RefAddr wrFactory = new StringRefAddr("wrappedFactory", "org.apache.commons.dbcp.BasicDataSourceFactory");
    ref.add(wrFactory);

    RefAddr minIdle = new StringRefAddr("minIdle", "3");
    ref.add(minIdle);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof org.apache.commons.dbcp.BasicDataSource);

    org.apache.commons.dbcp.BasicDataSource bds = (org.apache.commons.dbcp.BasicDataSource) result;
    assertEquals(3, bds.getMinIdle());
    //
    // These are read from the db.xml
    //
    assertEquals("db", bds.getUsername());
    assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName());

    //
    // These are read from the fnblds.xml
    //
    assertEquals("ss", bds.getPassword());
    assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl());
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *///from  w  w  w. ja va  2 s . c o m
public void testGetObjectInstance_fnbluser_routing_no_partition() throws Exception {

    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnbluser-routing-nopartition");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr userName = new StringRefAddr("minIdle", "7");
    ref.add(userName);

    //
    // At the end this should be overwritten by the value in the fnblds.xml file
    //
    RefAddr url = new StringRefAddr("url", "this-is-the-url");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof RoutingDataSource);

    BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource");

    assertEquals(7, bds.getMinIdle());

    //
    // These are read from the fnbluser.xml
    //
    assertEquals("fnbluserpwd", bds.getUsername());
    assertEquals("fnblpwd", bds.getPassword());
    assertEquals("org.fnbluser", bds.getDriverClassName());
    assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl());

    assertEquals(15, bds.getNumTestsPerEvictionRun()); // coming from db.xml
}

From source file:com.enioka.jqm.tools.JndiContext.java

@Override
public Name parse(String name) throws NamingException {
    return new CompositeName(name);
}

From source file:com.funambol.server.db.DataSourceFactoryTest.java

/**
 * Test of getObjectInstance method, of class DataSourceFactory.
 *//*from   w ww  .j ava2 s.c om*/
public void testGetObjectInstance_fnbluser_routing_with_partition() throws Exception {

    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    InitialContext context = new InitialContext();
    Hashtable environment = new Hashtable();

    Name name = new CompositeName("fnbluser-routing-with-partition");

    Reference ref = new Reference("javax.sql.DataSource");
    RefAddr userName = new StringRefAddr("minIdle", "7");
    ref.add(userName);

    //
    // At the end this should be overwritten by the value in the fnblds.xml file
    //
    RefAddr url = new StringRefAddr("url", "this-is-the-url");
    ref.add(url);

    Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment);
    assertTrue(result instanceof RoutingDataSource);

    RoutingDataSource rds = (RoutingDataSource) result;
    rds.init();
    rds.configure();
    Map<String, DataSource> datasources = rds.getDataSources();
    assertEquals("Wrong number of datasources", 3, datasources.size());

    BasicDataSource ds1 = (BasicDataSource) datasources.get("user_part1");
    assertNotNull("user_part1 must be not null", ds1);
    assertEquals("sa", ds1.getUsername());
    assertEquals("", ds1.getPassword());
    assertEquals("jdbc:hsqldb:mem:user_part1", ds1.getUrl());
    assertEquals(15, ds1.getNumTestsPerEvictionRun()); // from db.xml
    assertEquals(7, ds1.getMinIdle()); // set with StringRefAddr

    BasicDataSource ds2 = (BasicDataSource) datasources.get("user_part2");
    assertNotNull("user_part2 must be not null", ds2);
    assertEquals("sa", ds2.getUsername());
    assertEquals("", ds2.getPassword());
    assertEquals("jdbc:hsqldb:mem:user_part2", ds2.getUrl());
    assertEquals(15, ds2.getNumTestsPerEvictionRun()); // from db.xml
    assertEquals(7, ds2.getMinIdle()); // set with StringRefAddr

    BasicDataSource ds3 = (BasicDataSource) datasources.get("user_part3");
    assertNotNull("user_part3 must be not null", ds3);
    assertEquals("sa", ds3.getUsername());
    assertEquals("", ds3.getPassword());
    assertEquals("jdbc:hsqldb:mem:user_part3", ds3.getUrl());
    assertEquals(15, ds3.getNumTestsPerEvictionRun()); // from db.xml
    assertEquals(7, ds3.getMinIdle()); // set with StringRefAddr

    BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource");

    assertEquals(7, bds.getMinIdle());

    //
    // These are read from the fnbluser.xml
    //
    assertEquals("fnbluserpartition", bds.getUsername());
    assertEquals("fnblpwd", bds.getPassword());
    assertEquals("org.fnbluser", bds.getDriverClassName());
    assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl());

    assertTrue(rds.getPartitioningCriteria() instanceof MockPartitioningCriteria);
}