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

📄 memorycontext.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
字号:
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.avalon.excalibur.naming.memory;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.naming.*;
import javax.naming.Context;
import org.apache.avalon.excalibur.naming.AbstractLocalContext;
import org.apache.avalon.excalibur.naming.Namespace;

/**
 * Start of a generic Context implementation.
 *
 * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
 * @version $Revision: 1.2 $
 */
public class MemoryContext
    extends AbstractLocalContext
{
    protected Hashtable    m_bindings;

    protected MemoryContext( final Namespace namespace,
                             final Hashtable environment,
                             final Context parent,
                             final Hashtable bindings )
    {
        super( namespace, environment, parent );
        m_bindings = bindings;
    }

    public MemoryContext( final Namespace namespace,
                          final Hashtable environment,
                          final Context parent )
    {
        this( namespace, environment, parent, new Hashtable( 11 ) );
    }

    protected Context newContext()
        throws NamingException
    {
        return new MemoryContext( m_namespace, m_environment, m_parent );
    }

    protected Context cloneContext()
        throws NamingException
    {
        return new MemoryContext( m_namespace, m_environment, m_parent, m_bindings );
    }

    protected void doLocalBind( final Name name, final Object object )
        throws NamingException
    {
        m_bindings.put( name.get( 0 ), object );
    }

    protected NamingEnumeration doLocalList()
        throws NamingException
    {
        return new MemoryNamingEnumeration( this, m_namespace, m_bindings, false );
    }

    protected NamingEnumeration doLocalListBindings()
        throws NamingException
    {
        return new MemoryNamingEnumeration( this, m_namespace, m_bindings, true );
    }

    /**
     * Actually lookup raw entry in local context.
     * When overidding this it is not neccesary to resolve references etc.
     *
     * @param name the name in local context (size() == 1)
     * @return the bound object
     * @exception NamingException if an error occurs
     */
    protected Object doLocalLookup( final Name name )
        throws NamingException
    {
        final Object object = m_bindings.get( name.get( 0 ) );
        if( null == object ) throw new NameNotFoundException( name.get( 0 ) );
        return object;
    }

    /**
     * Actually unbind raw entry in local context.
     *
     * @param name the name in local context (size() == 1)
     * @exception NamingException if an error occurs
     */
    protected void doLocalUnbind( final Name name )
        throws NamingException
    {
        m_bindings.remove( name.get( 0 ) );
    }
}

⌨️ 快捷键说明

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