⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memorynamingcontext.java

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }        /**     * Enumerates the names bound in the named context, along with the      * objects bound to them. The contents of any subcontexts are not      * included.     * <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 bindings in this context.      * Each element of the enumeration is of type Binding.     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration listBindings(Name name)        throws NamingException {        // Removing empty parts        while ((!name.isEmpty()) && (name.get(0).length() == 0))            name = name.getSuffix(1);                if (name.isEmpty()) {            return new NamingContextEnumeration(bindings.elements(), this, true);        }                NamingEntry entry = (NamingEntry) bindings.get(name.get(0));                if (entry == null) {            throw new NameNotFoundException                (sm.getString("namingContext.nameNotBound", name.get(0)));        }                if (entry.type != NamingEntry.CONTEXT) {            throw new NamingException                (sm.getString("namingContext.contextExpected"));        }        return ((Context) entry.value).listBindings(name.getSuffix(1));    }    /**     * Creates and binds a new context. Creates a new context with the given      * name and binds it in the target context (that named by all but      * terminal atomic component of the name). All intermediate contexts and      * the target context must already exist.     *      * @param name the name of the context to create; may not be empty     * @return the newly created context     * @exception NameAlreadyBoundException if name is already bound     * @exception InvalidAttributesException if creation of the subcontext      * requires specification of mandatory attributes     * @exception NamingException if a naming exception is encountered     */    public DirContext createSubcontext(Name name, Attributes attrs)        throws NamingException    {        checkWritable(name);                DirContext newContext = new MemoryNamingContext(env);        bind(name, newContext);        return newContext;    }    // XXX Make it iterative, less objects    private NamingEntry findNamingEntry(Name name, boolean resolveLinks)        throws NamingException    {         if (name.isEmpty()) {//             // If name is empty, a newly allocated naming context is returned//             MemoryNamingContext mmc= new MemoryNamingContext(env);//             mmc.setBindings( bindings );//             return mmc;             return null;         }                NamingEntry entry = (NamingEntry) bindings.get(name.get(0));                if (entry == null) {            throw new NameNotFoundException                (sm.getString("namingContext.nameNotBound", name.get(0)));        }                if (name.size() > 1) {            // If the size of the name is greater that 1, then we go through a            // number of subcontexts.            if (entry.type != NamingEntry.CONTEXT) {                throw new NamingException                    (sm.getString("namingContext.contextExpected"));            }            return entry;        } else {            return entry;        }    }    public Object lookup(Name name, boolean resolveLinks)        throws NamingException    {        // Removing empty parts        while ((!name.isEmpty()) && (name.get(0).length() == 0))            name = name.getSuffix(1);                NamingEntry entry=findNamingEntry( name, resolveLinks );        if( entry.type == NamingEntry.CONTEXT ) {            return ((BaseDirContext) entry.value).lookup(name.getSuffix(1), resolveLinks);        }                if ((resolveLinks) && (entry.type == NamingEntry.LINK_REF)) {            String link = ((LinkRef) entry.value).getLinkName();            if (link.startsWith(".")) {                // Link relative to this context                return lookup(link.substring(1));            } else {                return (new InitialContext(env)).lookup(link);            }        } else if (entry.type == NamingEntry.REFERENCE) {            try {                Object obj = NamingManager.getObjectInstance                    (entry.value, name, this, env);                if (obj != null) {                    entry.value = obj;                    entry.type = NamingEntry.ENTRY;                }                return obj;            } catch (NamingException e) {                throw e;            } catch (Exception e) {                throw new NamingException(e.getMessage());            }        } else {            return entry.value;        }    }    /**     * Binds a name to an object. All intermediate contexts and the target      * context (that named by all but terminal atomic component of the name)      * must already exist.     *      * @param name the name to bind; may not be empty     * @param object the object to bind; possibly null     * @param rebind if true, then perform a rebind (ie, overwrite)     * @exception NameAlreadyBoundException if name is already bound     * @exception InvalidAttributesException if object did not supply all      * mandatory attributes     * @exception NamingException if a naming exception is encountered     */    public void bind(Name name, Object obj, Attributes attrs,                     boolean rebind)        throws NamingException    {        checkWritable(name);        	while ((!name.isEmpty()) && (name.get(0).length() == 0))	    name = name.getSuffix(1);        if (name.isEmpty())            throw new NamingException                (sm.getString("namingContext.invalidName"));                NamingEntry entry = (NamingEntry) bindings.get(name.get(0));                if (name.size() > 1) {            if (entry == null) {                throw new NameNotFoundException                    (sm.getString("namingContext.nameNotBound", name.get(0)));            }            if (entry.type == NamingEntry.CONTEXT) {                if (rebind) {                    ((Context) entry.value).rebind(name.getSuffix(1), obj);                } else {                    ((Context) entry.value).bind(name.getSuffix(1), obj);                }            } else {                throw new NamingException                    (sm.getString("namingContext.contextExpected"));            }        } else {            if ((!rebind) && (entry != null)) {                throw new NamingException                    (sm.getString("namingContext.alreadyBound", name.get(0)));            } else {                // Getting the type of the object and wrapping it within a new                // NamingEntry                Object toBind =                     NamingManager.getStateToBind(obj, name, this, env);                if (toBind instanceof Context) {                    entry = new NamingEntry(name.get(0), toBind, attrs,                                              NamingEntry.CONTEXT);                } else if (toBind instanceof LinkRef) {                    entry = new NamingEntry(name.get(0), toBind, attrs,                                             NamingEntry.LINK_REF);                } else if (toBind instanceof Reference) {                    entry = new NamingEntry(name.get(0), toBind, attrs,                                             NamingEntry.REFERENCE);                } else if (toBind instanceof Referenceable) {                    toBind = ((Referenceable) toBind).getReference();                    entry = new NamingEntry(name.get(0), toBind, attrs,                                             NamingEntry.REFERENCE);                } else {                    entry = new NamingEntry(name.get(0), toBind, attrs,                                             NamingEntry.ENTRY);                }                bindings.put(name.get(0), entry);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -