Package org.ow2.easybeans.mavenplugin.examples.directory

Source Code of org.ow2.easybeans.mavenplugin.examples.directory.Client

/**
* EasyBeans
* Copyright (C) 2007 Bull S.A.S.
* Contact: easybeans@objectweb.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
* USA
*
* --------------------------------------------------------------------------
* $Id: Client.java 5369 2010-02-24 14:58:19Z benoitf $
* --------------------------------------------------------------------------
*/

package org.ow2.easybeans.mavenplugin.examples.directory;

import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
* Simple client for directory.
* @author julien
*/
public final class Client {

    /**
    * JNDI name of the bean.
    */
    private static final String JNDI_NAME =
         "org.ow2.easybeans.mavenplugin.directory.DirectoryBean" + "_"
         + DirectoryRemote.class.getName() + "@Remote";

    /**
     * Utility class : no public constructor.
     */
    private Client() {
       
    }

    /**
     * Main.
     * @param args the command line arguments
     */
    public static void main(final String[] args) {
        try {
            /* Solve withespaces problem for windows users */
            System.setProperty("java.rmi.server.useCodebaseOnly", "true");
            Context initialContext = getInitialContext();
            DirectoryRemote dir = (DirectoryRemote) initialContext.lookup(JNDI_NAME);

            dir.create("tete", "tata");
            dir.add("blais", "julien", "", "0673863814");
            try {
                System.out.println(dir.getPhoneNumber("blais", "julien"));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
           
        } catch (NamingException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * GetInitialContext.
     * @return smartFactory initialised context
     * @throws NamingException naming exception
     */
    private static Context getInitialContext() throws NamingException {

        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.ow2.easybeans.component.smartclient.spi.SmartContextFactory");
        env.put(Context.PROVIDER_URL, "smart://localhost:22503");
        return new InitialContext(env);
    }
}
TOP

Related Classes of org.ow2.easybeans.mavenplugin.examples.directory.Client

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.