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));
if (cname.size() == 0) String firstComponent = cname.get(0); Object ctx = null; throw new NameNotFoundException (); ctx = binding.getObject(); ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env); throw new NamingException (e.getMessage()); throw new NotContextException(); return ((Context)ctx).listBindings (cname.getSuffix(1));
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(name.size() == 0) { } else if(name.size() > 1) { if(bindings.containsKey(name.getPrefix(1))) { Object subcontext = bindings.get(name.getPrefix(1)); if(subcontext instanceof Context) return ((Context) subcontext).lookup(name.getSuffix(1)); else throw new NotContextException("the name "+name.getPrefix(1)+" does not identify a context"); } else throw new NameNotFoundException("the name "+name.getPrefix(1)+" is not bound"); return value; } catch(Exception ex) { throw new NamingException("could not create object: "+ex.getMessage()); throw new NameNotFoundException("name "+name+" could not be found");
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();
value = NamingManager.getObjectInstance( value, name, this, env ); throw new NamingException( ex.getMessage() ); if( lookup && name.size() > 1 ) return MemoryContext.class.cast( value ).lookupImpl( name.getSuffix( 1 ), resolveLink ); return Context.class.cast( value ).lookup( name.getSuffix( 1 ) ); throw new NotContextException( simple + " is not a subcontext" );
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));
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); }
/** * Enumerates the names bound in the named context, along with the * class names of objects bound to them. * The contents of any subcontexts are not included. * <p/> * <p> If a binding is added to or removed from this context, * its effect on an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the * bindings in this context. Each element of the * enumeration is of type <tt>NameClassPair</tt>. * @throws javax.naming.NamingException if a naming exception is encountered * @see #list(String) * @see #listBindings(javax.naming.Name) * @see javax.naming.NameClassPair */ @Override public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { if(name == null || name.size() == 0) return new NameClassEnumerationImpl(this.bindings); else { Object subcontext = bindings.get(name.getPrefix(1)); if(subcontext == null) throw new NameNotFoundException("subcontext with name "+name.getPrefix(1)+" does not exist"); else if(subcontext instanceof Context) return ((Context) subcontext).list(name.getSuffix(1)); else throw new NotContextException("object with name "+name.getPrefix(1)+" is not a context"); } }
/** * Lists the bindings of a context or subcontext. The operation is * delegated to the serial context. * * @return an enumeration of the bindings of the context. * @throws NamingException if there is a naming exception. */ public NamingEnumeration listBindings(String name) throws NamingException { if (name.equals("")) { // listing this context if (namingManager == null) throw new NamingException(); return namingManager.listBindings(myName); } // Perhaps 'name' names a context Object target = lookup(name); if (target instanceof Context) { return ((Context) target).listBindings(""); } throw new NotContextException(name + " cannot be listed"); }
/** * Lists the contents of a context or subcontext. The operation is * delegated to the serial context. * * @return an enumeration of the contents of the context. * @throws NamingException if there is a naming exception. */ @Override public NamingEnumeration<NameClassPair> list(String name) throws NamingException { if (name.equals("")) { // listing this context if (namingManager == null) throw new NamingException(); return namingManager.list(myName); } // Check if 'name' names a context Object target = lookup(name); if (target instanceof Context) { return ((Context) target).list(""); } throw new NotContextException(name + " cannot be listed"); }
throw new NamingException(L.l("can't unbind root")); throw new NamingException(L.l("can't unbind subcontext; use destroySubcontext")); ((Context) value).unbind(rest); return; throw new NotContextException(L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name));
throw new NamingException(L.l("can't create root subcontext")); return ((Context) value).createSubcontext(rest); else if (value != null) throw new NotContextException(L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name));
if(name == null || name.isEmpty()) { Name subName = name.getPrefix(1); if(table.containsKey(subName)) { throw new NotContextException(name + " cannot be listed"); return ((Context)subContexts.get(subName)).listBindings(name.getSuffix(1)); throw new NamingException();
checkIsDestroyed(); Name parsedName = getParsedName(name); if (parsedName.size() == 0 || parsedName.get(0).length() == 0) { throw new InvalidNameException( "Name can not be empty!"); String nameToBind = parsedName.get(0); if (parsedName.size() == 1) { ctxMaps.put(nameToBind, obj); ((Context) boundObject).bind(parsedName.getSuffix(1), obj); } else { if (boundObject == null) { sub.bind(parsedName.getSuffix(1), obj); } else { throw new NotContextException(String.format("Expected Context but found %s", boundObject));
@Override public void rebind(Name name, Object obj) throws NamingException { if (name.isEmpty()) { throw new InvalidNameException("Name ["+name+"] is empty "); } Name normalizedName = normalizeName(name); String atomicName = normalizedName.get(0); // first component Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (obj instanceof AbstractHierarchicalContext) { ((AbstractHierarchicalContext)obj).parent = this; } bindings.put(atomicName, NamingManager.getStateToBind(obj, new CompositeName().add(atomicName), this, env)); } else { if (atomicNameBinding instanceof Context) { ((Context)atomicNameBinding).rebind(normalizedName.getSuffix(1), obj); } else { throw new NotContextException(format("%s from [%s] is not a context, cannot perform further binding", atomicName, name)); } } }
@Override public void bind(Name name, Object obj) throws NamingException { if (name.isEmpty()) { throw new InvalidNameException(format("Name [%s] is empty ", name)); } Name normalizedName = normalizeName(name); String atomicName = normalizedName.get(0); // first component Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (atomicNameBinding != null) { throw new NameAlreadyBoundException(format("Name [%s] in [%s] is already binded to [%s]", atomicName, normalizedName, atomicNameBinding)); } bindings.put(atomicName, NamingManager.getStateToBind(obj, new CompositeName().add(atomicName), this, env)); } else { if (atomicNameBinding instanceof Context) { ((Context)atomicNameBinding).bind(normalizedName.getSuffix(1), obj); } else { throw new NotContextException(format("%s from [%s] is not a context, cannot perform further binding", atomicName, name)); } } }