vinayc 2003/08/28 11:03:35
Added: client/impl/src/java/org/apache/altrmi/client/impl/naming
DefaultContext.java
DefaultInitialContextFactory.java
Log:
Refactorize (includes modularize,mavenize & rest of the nice's)
Revision Changes Path
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/naming/DefaultContext.java
Index: DefaultContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.naming;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.apache.altrmi.client.InterfaceLookup;
import org.apache.altrmi.client.InterfaceLookupFactory;
import org.apache.altrmi.client.impl.DefaultInterfaceLookupFactory;
import org.apache.altrmi.common.ConnectionException;
/**
* Class DefaultContext
*
*
* @author Vinay Chandrasekharan <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class DefaultContext implements Context
{
InterfaceLookupFactory m_interfaceLookupFactory =
new DefaultInterfaceLookupFactory();
InterfaceLookup m_altrmiInterfaceLookup;
/**
* Constructor DefaultContext
*
*
* @param host
* @param port
* @param transportStream
* @param env
*
* @throws NamingException
*
*/
DefaultContext( String host, String port, String transportStream,
Hashtable env )
throws NamingException
{
String proxyDetails = null;
ClassLoader interfacesClassLoader = null;
boolean optimize;
proxyDetails = (String)env.get( "proxy.type" );
{
if( proxyDetails == null )
{
proxyDetails = "S";
}
else if( proxyDetails.equals( "ClientSideClasses" ) )
{
proxyDetails = "C";
}
else if( proxyDetails.equals( "ServerSideClasses" ) )
{
proxyDetails = "S";
}
else
{
throw new NamingException(
"proxy.type should be 'ClientSideClasses' or
'ServerSideClasses', you specified "
+ proxyDetails );
}
}
String optimizeStr = (String)env.get( "optimize" );
{
if( optimizeStr == null )
{
optimize = true;
}
else if( optimizeStr.equals( "true" ) )
{
optimize = true;
}
else if( optimizeStr.equals( "false" ) )
{
optimize = false;
}
else
{
throw new NamingException(
"optimize should be 'true' or 'false', you specified " +
optimizeStr );
}
}
{
interfacesClassLoader = (ClassLoader)env.get(
"interfaces.classloader" );
if( interfacesClassLoader == null )
{
interfacesClassLoader = this.getClass().getClassLoader();
}
try
{
m_altrmiInterfaceLookup =
m_interfaceLookupFactory
.getInterfaceLookup( transportStream + ":" + host + ":" +
port + ":"
+ proxyDetails,
interfacesClassLoader, optimize );
if (m_altrmiInterfaceLookup == null) {
throw new
IllegalArgumentException("InterfaceLookupFactory not found for '" +
transportStream + " " + host + " " + port);
}
}
catch( ConnectionException ace )
{
ace.printStackTrace();
throw new NamingException( ace.getMessage() );
}
}
}
/**
* Method lookup
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Object lookup( Name name ) throws NamingException
{
return lookup(name.toString()); // this right?
}
/**
* Method lookup
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Object lookup( String name ) throws NamingException
{
try
{
return m_altrmiInterfaceLookup.lookup( name );
}
catch( ConnectionException ace )
{
throw new NamingException( ace.getMessage() );
}
}
/**
* Method bind
*
*
* @param name
* @param obj
*
* @throws NamingException
*
*/
public void bind( Name name, Object obj ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method bind
*
*
* @param name
* @param obj
*
* @throws NamingException
*
*/
public void bind( String name, Object obj ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method rebind
*
*
* @param name
* @param obj
*
* @throws NamingException
*
*/
public void rebind( Name name, Object obj ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method rebind
*
*
* @param name
* @param obj
*
* @throws NamingException
*
*/
public void rebind( String name, Object obj ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method unbind
*
*
* @param name
*
* @throws NamingException
*
*/
public void unbind( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method unbind
*
*
* @param name
*
* @throws NamingException
*
*/
public void unbind( String name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method rename
*
*
* @param oldName
* @param newName
*
* @throws NamingException
*
*/
public void rename( Name oldName, Name newName ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method rename
*
*
* @param oldName
* @param newName
*
* @throws NamingException
*
*/
public void rename( String oldName, String newName ) throws
NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method list
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NamingEnumeration list( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method list
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NamingEnumeration list( String name ) throws NamingException
{
final String[] names = m_altrmiInterfaceLookup.list();
return new NamingEnumeration()
{
int size = names.length;
int index = 0;
public void close()
{
}
public boolean hasMore()
{
return index < names.length;
}
public Object next()
{
return names[ index++ ];
}
public boolean hasMoreElements()
{
return hasMore();
}
public Object nextElement()
{
return next();
}
};
}
/**
* Method listBindings
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NamingEnumeration listBindings( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method listBindings
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NamingEnumeration listBindings( String name ) throws
NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method destroySubcontext
*
*
* @param name
*
* @throws NamingException
*
*/
public void destroySubcontext( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method destroySubcontext
*
*
* @param name
*
* @throws NamingException
*
*/
public void destroySubcontext( String name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method createSubcontext
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Context createSubcontext( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method createSubcontext
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Context createSubcontext( String name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method lookupLink
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Object lookupLink( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method lookupLink
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public Object lookupLink( String name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method getNameParser
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NameParser getNameParser( Name name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method getNameParser
*
*
* @param name
*
* @return
*
* @throws NamingException
*
*/
public NameParser getNameParser( String name ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method composeName
*
*
* @param name
* @param prefix
*
* @return
*
* @throws NamingException
*
*/
public Name composeName( Name name, Name prefix ) throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method composeName
*
*
* @param name
* @param prefix
*
* @return
*
* @throws NamingException
*
*/
public String composeName( String name, String prefix ) throws
NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method addToEnvironment
*
*
* @param propName
* @param propVal
*
* @return
*
* @throws NamingException
*
*/
public Object addToEnvironment( String propName, Object propVal ) throws
NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method removeFromEnvironment
*
*
* @param propName
*
* @return
*
* @throws NamingException
*
*/
public Object removeFromEnvironment( String propName ) throws
NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method getEnvironment
*
*
* @return
*
* @throws NamingException
*
*/
public Hashtable getEnvironment() throws NamingException
{
throw new UnsupportedOperationException();
}
/**
* Method close
*
*
* @throws NamingException
*
*/
public void close() throws NamingException
{
m_altrmiInterfaceLookup.close();
}
/**
* Method getNameInNamespace
*
*
* @return
*
* @throws NamingException
*
*/
public String getNameInNamespace() throws NamingException
{
throw new UnsupportedOperationException();
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/naming/DefaultInitialContextFactory.java
Index: DefaultInitialContextFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.naming;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import org.apache.altrmi.client.impl.DefaultInterfaceLookupFactory;
/**
* Class DefaultInitialContextFactory
*
*
* @author Vinay Chandrasekharan <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class DefaultInitialContextFactory implements InitialContextFactory
{
/**
* Method getInitialContext
*
*
* @param env
*
* @return
*
* @throws NamingException
*
* @see InitialContextFactory#getInitialContext(Hashtable)
*
*/
public Context getInitialContext( Hashtable env ) throws NamingException
{
String transportStream = "";
String s_url = (String)env.get( Context.PROVIDER_URL );
int index = -1;
index = ( s_url.lastIndexOf( "\\" ) > s_url.lastIndexOf( "/" ) )
? s_url.lastIndexOf( "\\" ) : s_url.lastIndexOf( "/" );
transportStream = s_url.substring( index + 1 );
for( int i = 0; i <
DefaultInterfaceLookupFactory.SUPPORTEDSTREAMS.length; i++ )
{
if( transportStream
.equalsIgnoreCase(
DefaultInterfaceLookupFactory.SUPPORTEDSTREAMS[ i ] ) )
{
String host = s_url.substring( s_url.indexOf( ":" ) + 3,
s_url.lastIndexOf( ":" ) );
String port = s_url.substring( s_url.lastIndexOf( ":" ) + 1,
index );
return new DefaultContext( host, port, transportStream, env );
}
}
throw new NamingException( "TransportStream[" + transportStream + "]
not supported" );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]