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

📄 nameserviceprovider.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
字号:
/**
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "Exolab" must not be used to endorse or promote
 *    products derived from this Software without prior written
 *    permission of Exoffice Technologies.  For written permission,
 *    please contact info@exolab.org.
 *
 * 4. Products derived from this Software may not be called "Exolab"
 *    nor may "Exolab" appear in their names without prior written
 *    permission of Exoffice Technologies. Exolab is a registered
 *    trademark of Exoffice Technologies.
 *
 * 5. Due credit should be given to the Exolab Project
 *    (http://www.exolab.org/).
 *
 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 */

package org.exolab.jms.server.mipc;

import java.io.Serializable;
import java.util.Vector;

import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingException;

import org.apache.avalon.excalibur.naming.NamingProvider;
import org.apache.avalon.excalibur.naming.rmi.server.RMINamingProviderImpl;

import org.exolab.core.ipc.NotifierIfc;


/**
 * This class is responsible for interpreting JNDI requests and
 * delegating them to the server, and passing back any necessary replies.
 *
 * @version     $Revision: 1.3 $ $Date: 2003/08/17 01:32:26 $
 * @author      <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
 * @see         org.exolab.jms.jndi.mipc.NameServiceProxy
 * @see         org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory
 */
public class NameServiceProvider implements NotifierIfc {

    /**
     * The root context
     */
    private Context _context;

    /**
     * The naming provider to delegate requests to
     */
    private NamingProvider _provider;


    /**
     * Construct a new <code>NameServiceProvider</code>
     *
     * @param context the root context
     */
    public NameServiceProvider(Context context) {
        _context = context;
        // use the RMI provider implementation, for convenience...
        _provider = new RMINamingProviderImpl(context);
    }

    /**
     * A new request has been received.
     * Carry out the request, and pass back any relevent data.
     *
     * @param object The data received,
     * @param id The id of the calling connection, not used by the client.
     * @return Object Return any requested result. This must never be null.
     */
    public Serializable notify(Object object, String id) {
        Vector v = (Vector) object;
        String func = (String) v.get(1);
        Serializable result = null;

        try {
            if (func.equals("getNameParser")) {
                result = getNameParser();
            } else if (func.equals("bind")) {
                result = bind((Name) v.get(3), (String) v.get(4), v.get(5));
            } else if (func.equals("rebind")) {
                result = rebind((Name) v.get(3), (String) v.get(4), v.get(5));
            } else if (func.equals("createSubcontext")) {
                result = createSubcontext((Name) v.get(3));
            } else if (func.equals("destroySubcontext")) {
                result = destroySubcontext((Name) v.get(3));
            } else if (func.equals("list")) {
                result = list((Name) v.get(3));
            } else if (func.equals("listBindings")) {
                result = listBindings((Name) v.get(3));
            } else if (func.equals("lookup")) {
                result = lookup((Name) v.get(3));
            } else if (func.equals("unbind")) {
                result = unbind((Name) v.get(3));
            } else {
                NamingException error = new NamingException(
                    "Unknown request received: " + func);
                result = pack(Boolean.FALSE, error);
            }
        } catch (NamingException exception) {
            result = pack(Boolean.FALSE, exception);
        } catch (Exception exception) {
            result = pack(Boolean.FALSE, new NamingException(
                exception.getMessage()));
        }
        return result;
    }

    /**
     * The connection has been broken.
     *
     * @param The unique identifier of this connection.
     */
    public void disconnection(String id) {
    }

    protected Vector getNameParser() throws NamingException, Exception {
        NameParser parser = _provider.getNameParser();
        return pack(Boolean.TRUE, parser);
    }

    protected Vector bind(Name name, String className, Object object)
        throws NamingException, Exception {
        _provider.bind(name, className, object);
        return pack(Boolean.TRUE, null);
    }

    protected Vector rebind(Name name, String className, Object object)
        throws NamingException, Exception {
        _provider.rebind(name, className, object);
        return pack(Boolean.TRUE, null);
    }

    protected Vector createSubcontext(Name name)
        throws NamingException, Exception {
        Context context = _provider.createSubcontext(name);
        return pack(Boolean.TRUE, context);
    }

    protected Vector destroySubcontext(Name name)
        throws NamingException, Exception {
        _provider.destroySubcontext(name);
        return pack(Boolean.TRUE, null);
    }

    protected Vector list(Name name) throws NamingException, Exception {
        NameClassPair[] pairs = _provider.list(name);
        return pack(Boolean.TRUE, pairs);
    }

    protected Vector listBindings(Name name)
        throws NamingException, Exception {
        Binding[] bindings = _provider.listBindings(name);
        return pack(Boolean.TRUE, bindings);
    }

    protected Vector lookup(Name name)
        throws NamingException, Exception {
        Object object = _provider.lookup(name);
        return pack(Boolean.TRUE, object);
    }

    protected Vector unbind(Name name)
        throws NamingException, Exception {
        _provider.unbind(name);
        return pack(Boolean.TRUE, null);
    }

    /**
     * Pack all the data that is required by the server in a vector.
     * Set the size of the vector to be exactly the right size for efficiency.
     *
     * @param success Boolean indicating success or failure of request.
     * @param ob The Object being returned.
     * @return Vector The vector containing all the data.
     *
     */
    protected Vector pack(Boolean success, Object ob) {
        Vector v = new Vector(2);
        v.add(success);
        v.add(ob);
        return v;
    }

} //-- NameServiceProvider

⌨️ 快捷键说明

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