📄 hanamingcontextfactory.java
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2001 - ScalAgent Distributed Technologies * Copyright (C) 1996 - Dyade * * 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Initial developer(s): David Feliot */package fr.dyade.aaa.jndi2.haclient;import javax.naming.spi.*;import javax.naming.*;import java.util.*;import fr.dyade.aaa.jndi2.client.*;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.util.monolog.api.Logger;public class HANamingContextFactory implements InitialContextFactory { /** * @param env This contains the hostname and the port. * @return A JNDI initial context. * @exception NamingException Thrown if the host and port properties * aren't strings, if the port string does not represent a valid number, * or if an exception is thrown from the NamingContext constructor. */ public Context getInitialContext(Hashtable env) throws NamingException { if (Trace.logger.isLoggable(BasicLevel.DEBUG)) Trace.logger.log( BasicLevel.DEBUG, "NamingContextFactory.getInitialContext(" + env + ')'); return new fr.dyade.aaa.jndi2.client.NamingContextImpl( getNamingConnection(env), new CompositeName()); } private static String getEnvProperty(Hashtable env, String propName) { String value = null; if (env != null) { value = (String) env.get(propName); } if (value == null) { value = System.getProperty(propName, null); } return value; } public static NamingConnection getNamingConnection( Hashtable env) throws NamingException { try { NamingConnection namingConnection; // URL should be as: hascn://host:port String url = getEnvProperty(env, "scn.naming.provider.url"); if (url == null) { url = getEnvProperty(env, Context.PROVIDER_URL); } if (url != null) { StringTokenizer tokenizer = new StringTokenizer(url, "/:,"); if (! tokenizer.hasMoreElements()) throw new NamingException("URL not valid:" + url); String protocol = tokenizer.nextToken(); if (protocol.equals("hascn")) { HANamingConnection haNamingConnection = new HANamingConnection(); while (tokenizer.hasMoreElements()) { haNamingConnection.addServerAddress( tokenizer.nextToken(), Integer.parseInt(tokenizer.nextToken())); } namingConnection = haNamingConnection; } else { throw new NamingException("Unknown protocol:" + protocol); } } else { throw new NamingException( "URL " + Context.PROVIDER_URL + " not defined"); } return namingConnection; } catch (Exception e) { NamingException nx = new NamingException( "exception creating NamingContext: " + e.toString()); nx.setRootCause(e); throw nx; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -