checkIsDestroyed(); Name parsedName = getParsedName(name); if (parsedName.size() == 0 || parsedName.get(0).length() == 0) { throw new InvalidNameException( "Name can not be empty!"); String nameToRemove = parsedName.get(0); if (boundObject instanceof Context) { ((Context) boundObject).unbind(parsedName.getSuffix(1)); } else { throw new NameNotFoundException( String.format("Can not find %s", name)); throw new NotContextException(String.format("Expected Context but found %s", boundObject));
try { String app_ver = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e(tag, e.getMessage()); }
NameNotFoundException n = new NameNotFoundException(name); n.initCause(e); throw n; } catch (SecurityException ex) {
@Override public final NameNotFoundException nameNotFoundInContext(final String name, final Name contextName) { final NameNotFoundException result = new NameNotFoundException(String.format(getLoggingLocale(), nameNotFoundInContext$str(), name, contextName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String nullVar = "WFLYNAM0041: %s is null";
public Object doInContext(Context ctx) throws NamingException { Object located = ctx.lookup(name); if (located == null) { throw new NameNotFoundException( "JNDI object with [" + name + "] not found: JNDI implementation returned null"); } return located; } });
if (cname.size() == 0) String firstComponent = cname.get(0); Object ctx = null; throw new NameNotFoundException (); if(__log.isDebugEnabled())__log.debug("Dereferencing Reference for "+name.get(0)); try ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env); throw new NamingException (e.getMessage()); throw new NotContextException(); return ((Context)ctx).list (cname.getSuffix(1));
if (pos > 0) { String scheme = name.substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); return ctx.lookup(name); } else { Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException(name); } else if (obj instanceof Context && path.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(path.getSuffix(1)); result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
this.parent.unbind(name); else if (unbindName.isEmpty()) throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES .getString("WinstoneContext.CantUnbindEmptyName")); else if (unbindName.size() > 1) { Object ctx = lookup(unbindName.get(0)); if (!(ctx instanceof Context)) throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.NotContext", new String[] { unbindName.get(0), ctx.getClass().getName() })); else if (ctx == null) throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.NameNotFound", unbindName.get(0))); else try { ((Context) ctx).unbind(unbindName.getSuffix(1)); } finally { ((Context) ctx).close(); } else if (this.bindings.get(name.get(0)) == null) throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.NameNotFound", name.toString())); else {
@Override public Object lookup(Name name) throws NamingException { if (name.isEmpty()) { return this.clone(); String atomicName = normalizedName.get(0); Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (atomicNameBinding == null) { throw new NameNotFoundException("Name ["+atomicName+"] from ["+normalizedName+"] not found in this binding"); return NamingManager.getObjectInstance( atomicNameBinding, new CompositeName().add(atomicName), env); } catch (Exception e) { NamingException _e = new NamingException("NamingManager.getObjectInstance(...) failed"); _e.setRootCause(e); throw _e; return ((Context)atomicNameBinding).lookup(normalizedName.getSuffix(1)); throw new NotContextException(atomicName+" from ["+name+"] is not a context, cannot perform further lookup");
if (cname.size() == 0) String firstComponent = cname.get(0); Object ctx = null; throw new NameNotFoundException (); ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env); throw new NamingException (e.getMessage()); throw new NotContextException(); return ((Context)ctx).listBindings (cname.getSuffix(1));
public void testDefaultUserTransactionAndResources() throws Exception { PoolingDataSource pds = new PoolingDataSource(); pds.setMaxPoolSize(1); pds.setClassName(MockitoXADataSource.class.getName()); pds.setUniqueName("jdbc/pds"); pds.init(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName()); Context ctx = new InitialContext(env); assertTrue(transactionManager == ctx.lookup("java:comp/UserTransaction")); try { ctx.lookup("aaa"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage()); } assertTrue(pds == ctx.lookup("jdbc/pds")); ctx.close(); pds.close(); }
this.parent.bind(name, value, allowOverwrites); else if (bindName.isEmpty()) throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.AlreadyExists", name.toString())); else if (bindName.size() > 1) { Object ctx = lookup(bindName.get(0)); if (!(ctx instanceof Context)) throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.NotContext", new String[] { bindName.get(0), ctx.getClass().getName() })); else if (ctx == null) throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.NameNotFound", bindName.get(0))); else try { if (allowOverwrites) ((Context) ctx).rebind(bindName.getSuffix(1), value); else ((Context) ctx).bind(bindName.getSuffix(1), value); } finally { ((Context) ctx).close();
public void rebind(Name name, Object obj) throws NamingException if (name.size() == 0) throw new NamingException(L.l("can't bind root")); for (; i + 1 < name.size(); i++) { String first = name.get(i); ((Context) value).bind(name.getSuffix(i + 1), obj); return; throw new NotContextException(L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name));
@Test public void testLookupFails() throws Exception { NameNotFoundException ne = new NameNotFoundException(); String name = "foo"; final Context context = mock(Context.class); given(context.lookup(name)).willThrow(ne); JndiTemplate jt = new JndiTemplate() { @Override protected Context createInitialContext() { return context; } }; try { jt.lookup(name); fail("Should have thrown NamingException"); } catch (NameNotFoundException ex) { // Ok } verify(context).close(); }
public Object lookup(Name name) throws NamingException { if (name.isEmpty()) { return this; } String key = name.get(0); Name suffix = name.getSuffix(1); Object ret = lookupInstance(key, suffix); if (ret instanceof Context) { Context ctx = (Context) ret; if (!suffix.isEmpty()) { ret = ctx.lookup(suffix); } } if (ret == null) { throw new NameNotFoundException(name.toString()); } return ret; }
throws NamingException { while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextBindingsEnumeration(bindings.values().iterator(), this); throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name, name.get(0))); throw new NamingException (sm.getString("namingContext.contextExpected")); return ((Context) entry.value).listBindings(name.getSuffix(1));
public void unbind(String name) throws NamingException { checkName(name); Registry registry = getRegistry(); try { registry.unbind(toRMIName(name)); } catch (NotBoundException ex) { throw new NameNotFoundException(name + " not found in RMI registry " + registry); } catch (RemoteException ex) { throw new NamingException("Remote exception: " + ex.getMessage()); } }
public Context createSubcontext(Name name) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't create root subcontext")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { return ((Context) value).createSubcontext(name.getSuffix(i + 1)); } else if (value != null) throw new NotContextException(L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); model = model.createSubcontext(first); return create(getFullPath(name), model, _env); }
public void destroySubcontext(Name name) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't destroy root subcontext")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).destroySubcontext(name.getSuffix(i + 1)); return; } else if (value != null) throw new NotContextException(L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); model.unbind(first); }
/** * @see javax.naming.Context#destroySubcontext(javax.naming.Name) */ public void destroySubcontext(Name name) throws NamingException { if(name.size() > 1) { if(subContexts.containsKey(name.getPrefix(1))) { Context subContext = (Context)subContexts.get(name.getPrefix(1)); subContext.destroySubcontext(name.getSuffix(1)); return; } /* TODO: Better message might be necessary */ throw new NameNotFoundException(); } /* Look at the contextStore to see if the name is bound there */ if(table.containsKey(name)) { throw new NotContextException(); } /* Look for the subcontext */ if(!subContexts.containsKey(name)) { throw new NameNotFoundException(); } Context subContext = (Context)subContexts.get(name); /* Look to see if the context is empty */ NamingEnumeration names = subContext.list(""); if(names.hasMore()) { throw new ContextNotEmptyException(); } ((Context)subContexts.get(name)).close(); subContexts.remove(name); }