List of usage examples for javax.naming CompositeName CompositeName
public CompositeName(String n) throws InvalidNameException
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoContainer.java
/** * Bind object in root context. Create needed sub contexts. * * since 5.6/*from w w w . j av a 2 s . c o m*/ */ public static void addDeepBinding(String name, Object obj) throws InvalidNameException, NamingException { addDeepBinding(rootContext, new CompositeName(name), obj); }
From source file:org.exoplatform.services.naming.InitialContextTest.java
public void testCompositeNameUsing() throws Exception { Name name = new CompositeName("java:comp/env/jdbc/jcr"); Enumeration en = name.getAll(); while (en.hasMoreElements()) { en.nextElement();//from w w w. j a va 2 s . c o m } InitialContext ctx = new InitialContext(); ctx.bind(name, "foo"); assertEquals("foo", ctx.lookup(name)); try { ctx.bind(name, "foo2"); fail("A NameAlreadyBoundException is expected here"); } catch (NameAlreadyBoundException e) { // expected exception } assertEquals("foo", ctx.lookup(name)); assertEquals("foo", ctx.lookup("java:comp/env/jdbc/jcr")); ctx.unbind(name); try { ctx.lookup(name); fail("A NameNotFoundException is expected here"); } catch (NameNotFoundException e) { // expected exception } }
From source file:org.nuxeo.runtime.datasource.DataSourceComponent.java
@Override public void applicationStarted(ComponentContext context) { if (namingContext != null) { return;/*from www .j a v a 2 s . com*/ } namingContext = NuxeoContainer.getRootContext(); // allocate datasource sub-contexts Name comp; try { comp = new CompositeName(DataSourceHelper.getDataSourceJNDIPrefix()); } catch (NamingException e) { throw new RuntimeException(e); } Context ctx = namingContext; for (int i = 0; i < comp.size(); i++) { try { ctx = (Context) ctx.lookup(comp.get(i)); } catch (NamingException e) { try { ctx = ctx.createSubcontext(comp.get(i)); } catch (NamingException e1) { throw new RuntimeException(e1); } } } // bind datasources for (DataSourceDescriptor datasourceDesc : datasources.values()) { bindDataSource(datasourceDesc); } // bind links for (DataSourceLinkDescriptor linkDesc : links.values()) { bindDataSourceLink(linkDesc); } }
From source file:org.nuxeo.runtime.datasource.DataSourceHelper.java
public static <T> T getDataSource(String partialName, Class<T> clazz) throws NamingException { String jndiName = getDataSourceJNDIName(partialName); InitialContext context = new InitialContext(); Object resolved = context.lookup(jndiName); if (resolved instanceof Reference) { try {//from w ww . ja va 2 s . com resolved = NamingManager.getObjectInstance(resolved, new CompositeName(jndiName), context, null); } catch (Exception e) { throw new RuntimeException("Cannot get access to " + jndiName, e); } } return clazz.cast(resolved); }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
protected static void installTransactionManager(TransactionManagerConfiguration config) throws NamingException { initTransactionManager(config);//from w w w. j a va 2s .c o m addDeepBinding(rootContext, new CompositeName(nameOf("TransactionManager")), getTransactionManagerReference()); addDeepBinding(rootContext, new CompositeName(nameOf("UserTransaction")), getUserTransactionReference()); }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
/** * Creates and installs in the container a new ConnectionManager. * * @param name the repository name/*from w w w . j av a 2 s .c o m*/ * @param config the pool configuration * @return the created connection manager */ public static synchronized ConnectionManagerWrapper installConnectionManager( NuxeoConnectionManagerConfiguration config) { String name = config.getName(); ConnectionManagerWrapper cm = connectionManagers.get(name); if (cm != null) { return cm; } cm = initConnectionManager(config); // also bind it in JNDI if (rootContext != null) { String jndiName = nameOf("ConnectionManager/".concat(name)); try { addDeepBinding(rootContext, new CompositeName(jndiName), getConnectionManagerReference(name)); } catch (NamingException e) { log.error("Cannot bind in JNDI connection manager " + config.getName() + " to name " + jndiName); } } return cm; }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
/** * Bind object in root context. Create needed sub contexts. since 5.6 *//* ww w .j av a2 s . c o m*/ public static void addDeepBinding(String name, Object obj) throws NamingException { addDeepBinding(rootContext, new CompositeName(name), obj); }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
public static <T> T lookup(Context context, String name, Class<T> type) throws NamingException { Object resolved;/*from ww w. j a v a 2 s . com*/ try { resolved = context.lookup(detectJNDIPrefix(context).concat(name)); } catch (NamingException cause) { if (parentContext == null) { throw cause; } return type.cast(parentContext.lookup(detectJNDIPrefix(parentContext).concat(name))); } if (resolved instanceof Reference) { try { resolved = NamingManager.getObjectInstance(resolved, new CompositeName(name), rootContext, null); } catch (NamingException e) { throw e; } catch (Exception e) { // stupid JNDI API throws Exception throw ExceptionUtils.runtimeException(e); } } return type.cast(resolved); }
From source file:org.sonar.server.database.JndiDatabaseConnector.java
private void createJNDISubContexts(Context ctx, String jndiBinding) throws NamingException { Name name = new CompositeName(jndiBinding); for (int i = 0; i < name.size() - 1; i++) { String namingContext = name.get(i); try {//from www .ja va 2 s . com Object obj = ctx.lookup(namingContext); if (!(obj instanceof Context)) { throw new NamingException(namingContext + " is not a JNDI Context"); } } catch (NameNotFoundException ex) { ctx = ctx.createSubcontext(namingContext); } } }
From source file:org.springframework.ldap.support.LdapUtilsTest.java
@Test public void testNewLdapNameFromCompositeName() throws InvalidNameException { LdapName result = LdapUtils.newLdapName(new CompositeName(EXPECTED_DN_STRING)); assertThat(result).isEqualTo(new LdapName(EXPECTED_DN_STRING)); }