/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
@Test public void testRebind_1() throws Exception { try { ic.lookup("/nosuchsubcontext"); ProxyAssertSupport.fail("the name is not supposed to be there"); } catch (NameNotFoundException e) { // OK } JNDIUtil.rebind(ic, "/nosuchsubcontext/sub1/sub2/sub3/name", new Integer(7)); ProxyAssertSupport.assertEquals(7, ((Integer) ic.lookup("/nosuchsubcontext/sub1/sub2/sub3/name")).intValue()); }
@Test public void testRebind_2() throws Exception { try { ic.lookup("/doesnotexistyet"); ProxyAssertSupport.fail("the name is not supposed to be there"); } catch (NameNotFoundException e) { // OK } JNDIUtil.rebind(ic, "/doesnotexistyet", new Integer(8)); ProxyAssertSupport.assertEquals(8, ((Integer) ic.lookup("/doesnotexistyet")).intValue()); ic.unbind("doesnotexistyet"); }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
@Test public void testRebind_3() throws Exception { try { ic.lookup("doesnotexistyet"); ProxyAssertSupport.fail("the name is not supposed to be there"); } catch (NameNotFoundException e) { // OK } JNDIUtil.rebind(ic, "doesnotexistyet", new Integer(9)); ProxyAssertSupport.assertEquals(9, ((Integer) ic.lookup("/doesnotexistyet")).intValue()); ic.unbind("doesnotexistyet"); }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
private boolean bindToJndi(final String jndiName, final Object objectToBind) throws NamingException { if (context != null) { String parentContext; String jndiNameInContext; int sepIndex = jndiName.lastIndexOf('/'); if (sepIndex == -1) { parentContext = ""; } else { parentContext = jndiName.substring(0, sepIndex); } jndiNameInContext = jndiName.substring(sepIndex + 1); try { context.lookup(jndiName); //JMSServerManagerImpl.log.warn("Binding for " + jndiName + " already exists"); return false; } catch (Throwable e) { // OK } Context c = JNDIUtil.createContext(context, parentContext); c.rebind(jndiNameInContext, objectToBind); } return true; } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }
public static void tearDownRecursively(final Context c) throws Exception { for (NamingEnumeration<Binding> ne = c.listBindings(""); ne.hasMore(); ) { Binding b = ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { JNDIUtil.tearDownRecursively((Context) object); } c.unbind(name); } }
/** * Context.rebind() requires that all intermediate contexts and the target context (that named by * all but terminal atomic component of the name) must already exist, otherwise * NameNotFoundException is thrown. This method behaves similar to Context.rebind(), but creates * intermediate contexts, if necessary. */ public static void rebind(final Context c, final String jndiName, final Object o) throws NamingException { Context context = c; String name = jndiName; int idx = jndiName.lastIndexOf('/'); if (idx != -1) { context = JNDIUtil.createContext(c, jndiName.substring(0, idx)); name = jndiName.substring(idx + 1); } boolean failed = false; try { context.rebind(name, o); } catch (Exception ignored) { failed = true; } if (failed) { context.bind(name, o); } }