vinayc 2003/08/28 11:31:52
Added:
server/impl/src/java/org/apache/altrmi/server/impl/classretrievers
AbstractClassRetriever.java
AbstractDynamicGeneratorClassRetriever.java
BcelDynamicGeneratorClassRetriever.java
JarFileClassRetriever.java
JavacDynamicGeneratorClassRetriever.java
NoClassRetriever.java PlainClassRetriever.java
Log:
Refactorize (includes modularize,mavenize & rest of the nice's)
Revision Changes Path
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/AbstractClassRetriever.java
Index: AbstractClassRetriever.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.server.impl.classretrievers;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.altrmi.server.ClassRetrievalException;
import org.apache.altrmi.server.ClassRetriever;
/**
* Class AbstractClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public abstract class AbstractClassRetriever implements ClassRetriever
{
private ClassLoader m_classLoader;
/**
* Set the classloader to use.
*
* @param classLoader the classloader to use.
*/
protected void setClassLoader( ClassLoader classLoader )
{
m_classLoader = classLoader;
}
/**
* Method getProxyClassBytes
*
*
* @param publishedName the publication name
*
* @return a byte array for the Bean.
*
* @throws ClassRetrievalException if the bytes cannot be retrieved.
*
*/
public final byte[] getProxyClassBytes( String publishedName ) throws
ClassRetrievalException
{
return getThingBytes( "AltrmiGenerated" + publishedName );
}
/**
* Method getThingBytes
*
*
* @param thingName the publication name
*
* @return a byte array for the thing.
*
* @throws ClassRetrievalException if the bytes cannot be retrieved.
*
*/
protected byte[] getThingBytes( String thingName ) throws
ClassRetrievalException
{
InputStream is = null;
thingName = thingName.replace( '.', '\\' ) + ".class";
try
{
is = m_classLoader.getResourceAsStream( thingName );
}
catch( Exception e )
{
throw new ClassRetrievalException(
"Generated class not found in classloader specified : " +
e.getMessage() );
}
if( is == null )
{
throw new ClassRetrievalException(
"Generated class not found in classloader specified." );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = 0;
try
{
while( -1 != ( i = is.read() ) )
{
baos.write( i );
}
is.close();
}
catch( IOException e )
{
throw new ClassRetrievalException( "Error retrieving generated
class bytes : "
+ e.getMessage() );
}
return baos.toByteArray();
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/AbstractDynamicGeneratorClassRetriever.java
Index: AbstractDynamicGeneratorClassRetriever.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.server.impl.classretrievers;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.altrmi.server.DynamicProxyGenerator;
import org.apache.altrmi.server.ClassRetriever;
import org.apache.altrmi.server.PublicationDescription;
import org.apache.altrmi.server.ClassRetrievalException;
import org.apache.altrmi.server.PublicationException;
import org.apache.altrmi.server.PublicationDescriptionItem;
import org.apache.altrmi.server.ProxyGenerationEnvironmentException;
/**
* Class JarFileClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class AbstractDynamicGeneratorClassRetriever
implements DynamicProxyGenerator, ClassRetriever
{
private String m_classpath;
private String m_classGenDir = ".";
private String m_srcGenDir;
private Class m_generatorClass;
/**
*
* @param classLoader the classloader in which the proxy generater will
be found.
* @param generatorClassName the name of teh proxy gen class
*/
public AbstractDynamicGeneratorClassRetriever(ClassLoader classLoader,
String generatorClassName)
{
try
{
m_generatorClass = classLoader.loadClass(generatorClassName);
}
catch (ClassNotFoundException e)
{
throw new NoClassDefFoundError(generatorClassName);
}
}
/**
* Method generate
*
*
* @param asName the name to generate as
* @param interfaceToExpose the interfaces to expose.
* @param classLoader the classloader to use during generation.
* @throws PublicationException if the generation failed.
*
*/
public void generate( String asName, Class interfaceToExpose, ClassLoader
classLoader )
throws PublicationException
{
generateProxy( asName, new PublicationDescription( interfaceToExpose
),
classLoader, false );
}
/**
* Method generate
*
*
* @param asName the name to generate as
* @param publicationDescription the description of the publication
* @param classLoader the class loader to use.
*
* @throws PublicationException if the generation failed.
*
*/
public void generate(
String asName, PublicationDescription publicationDescription,
ClassLoader classLoader )
throws PublicationException
{
generateProxy( asName, publicationDescription, classLoader, false );
}
/**
* Method deferredGenerate
*
*
* @param asName the name of the clas to generate
* @param publicationDescription the description of the publication
* @param classLoader the class loader to use.
*
* @throws PublicationException if the generation failed.
*
*/
public void deferredGenerate(
String asName, PublicationDescription publicationDescription,
ClassLoader classLoader )
throws PublicationException
{
generateProxy( asName, publicationDescription, classLoader, true );
}
/**
* Use this m_classpath during retrieval.
*
*
* @param classpath the m_classpath
*
*/
public void setClasspath( String classpath )
{
m_classpath = classpath;
}
/**
* Method addToClasspath
*
*
* @param classpathElement an element for the m_classpath
*
*/
public void addToClasspath( String classpathElement )
{
m_classpath = m_classpath + File.pathSeparator + classpathElement;
}
/**
* Method setClassGenDir
*
*
* @param classGenDir the class generation directory
*
*/
public void setClassGenDir( String classGenDir )
{
m_classGenDir = classGenDir;
}
/**
* Method getProxyClassBytes
*
*
* @param publishedName the name to publish as
*
* @return the byte array for the proxy class
*
* @throws ClassRetrievalException if the class cannot be retrieved.
*
*/
public final byte[] getProxyClassBytes( String publishedName ) throws
ClassRetrievalException
{
return getThingBytes( "AltrmiGenerated" + publishedName );
}
/**
*
* @param thingName the thing name
* @return the byte array of the thing.
* @throws ClassRetrievalException if getting the bytes was a problem.
*/
protected byte[] getThingBytes( String thingName ) throws
ClassRetrievalException
{
thingName = thingName.replace( '.', '\\' ) + ".class";
FileInputStream fis;
try
{
fis = new FileInputStream( new File( m_classGenDir, thingName ) );
}
catch( Exception e )
{
e.printStackTrace();
throw new ClassRetrievalException(
"Generated class not found in classloader specified : " +
e.getMessage() );
}
if( fis == null )
{
throw new ClassRetrievalException(
"Generated class not found in classloader specified." );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = 0;
try
{
while( -1 != ( i = fis.read() ) )
{
baos.write( i );
}
fis.close();
}
catch( IOException e )
{
e.printStackTrace();
throw new ClassRetrievalException( "Error retrieving generated
class bytes : "
+ e.getMessage() );
}
byte[] bytes = baos.toByteArray();
return bytes;
}
/**
* Method setSrcGenDir
*
*
* @param srcGenDir the source generaton directory.
*
*/
public void setSrcGenDir( String srcGenDir )
{
m_srcGenDir = srcGenDir;
}
private void generateProxy(
String asName, PublicationDescription publicationDescription,
ClassLoader classLoader, boolean deferred )
throws PublicationException
{
if( classLoader == null )
{
classLoader = this.getClass().getClassLoader();
}
PublicationDescriptionItem[] interfacesToExpose = new
PublicationDescriptionItem[ 0 ];
PublicationDescriptionItem[] addInfs = new
PublicationDescriptionItem[ 0 ];
interfacesToExpose = publicationDescription.getInterfacesToExpose();
addInfs = publicationDescription.getAdditionalFacades();
org.apache.altrmi.server.ProxyGenerator proxyGenerator;
try
{
proxyGenerator = (org.apache.altrmi.server.ProxyGenerator)
m_generatorClass.newInstance();
}
catch (InstantiationException e)
{
throw new RuntimeException( "ProxyGenerator cannot be
instantiated." );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( "ProxyGenerator was illegally
accessed" );
}
proxyGenerator.setSrcGenDir( m_srcGenDir );
proxyGenerator.setClassGenDir( m_classGenDir );
proxyGenerator.setGenName( asName );
proxyGenerator.setClasspath( m_classpath );
proxyGenerator.setInterfacesToExpose( interfacesToExpose );
proxyGenerator.setAdditionalFacades( addInfs );
try
{
proxyGenerator.generateSrc( classLoader );
}
catch( Throwable t )
{
System.err.println( "******" );
System.err.println( "** Exception while making source : " );
System.err.flush();
t.printStackTrace();
System.err.println( "** Name=" + asName );
System.err.println( "** Classes/Interfaces to Expose.." );
for( int i = 0; i < interfacesToExpose.length; i++ )
{
String aString = interfacesToExpose[ i
].getFacadeClass().getName();
System.err.println( "** .." + aString );
}
System.err.println( "******" );
System.err.flush();
}
if( !deferred )
{
try
{
proxyGenerator.generateClass( classLoader );
}
catch( Throwable t )
{
if( ( t instanceof NoClassDefFoundError )
&& t.getMessage().equals( "sun/tools/javac/Main" ) )
{
System.err.println(
"***************************************" );
System.err.println( "*
*" );
System.err.println( "* AltRMI problem......
*" );
System.err.println( "* Please copy
JAVA_HOME/lib/tools.jar *" );
System.err.println( "* to your applications m_classpath
so *" );
System.err.println( "* that proxys can be compiled.
*" );
System.err.println( "*
*" );
System.err.println(
"***************************************" );
throw new ProxyGenerationEnvironmentException(
"tools.jar not found in m_classpath." );
}
System.err.println( "******" );
System.err.println( "** Exception while making String : " );
System.err.flush();
t.printStackTrace();
System.err.println( "** SrcDir=" + m_srcGenDir );
System.err.println( "** ClassDir=" + m_classGenDir );
System.err.println( "** Name=" + asName );
System.err.println( "** CLasspath=" + m_classpath );
System.err.println( "** Classes/Interfaces to Expose.." );
for( int i = 0; i < interfacesToExpose.length; i++ )
{
String aString = interfacesToExpose[ i
].getFacadeClass().getName();
System.err.println( "** .." + aString );
}
System.err.println( "******" );
System.err.flush();
}
}
}
/**
* Method generateDeferred
*
*
* @param classLoader the classloader to use.
*
*/
public void generateDeferred( ClassLoader classLoader )
{
org.apache.altrmi.server.ProxyGenerator proxyGenerator;
try
{
proxyGenerator = (org.apache.altrmi.server.ProxyGenerator)
m_generatorClass.newInstance();
}
catch (InstantiationException e)
{
throw new RuntimeException( "ProxyGenerator cannot be
instantiated." );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( "ProxyGenerator was illegally
accessed" );
}
proxyGenerator.generateDeferredClasses();
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/BcelDynamicGeneratorClassRetriever.java
Index: BcelDynamicGeneratorClassRetriever.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.server.impl.classretrievers;
/**
* Class BcelDynamicGeneratorClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class BcelDynamicGeneratorClassRetriever extends
AbstractDynamicGeneratorClassRetriever
{
/**
* Contruct a Dynamic Class Generator with a classloader pointing to the
generator classes.
*
* @param classLoader the classloader in which the proxy generater will
be found.
*/
public BcelDynamicGeneratorClassRetriever(ClassLoader classLoader)
{
super(classLoader,
"org.apache.altrmi.tools.generator.BCELProxyGeneratorImpl");
}
/**
* Contruct a Dynamic Class Generator using the classes own classloader.
*
*/
public BcelDynamicGeneratorClassRetriever()
{
super(BcelDynamicGeneratorClassRetriever.class.getClassLoader(),
"org.apache.altrmi.tools.generator.BCELProxyGeneratorImpl");
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/JarFileClassRetriever.java
Index: JarFileClassRetriever.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.server.impl.classretrievers;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
/**
* Class JarFileClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class JarFileClassRetriever extends AbstractClassRetriever
{
/**
* Contruct a ClassRetriever from url of a JAR file.
*
*
* @param urlOfJarFile the jar file URL.
*
*/
public JarFileClassRetriever( URL urlOfJarFile )
{
setClassLoader( new URLClassLoader( new URL[]{urlOfJarFile} ) );
}
/**
* Contruct a ClassRetriever from urls of JAR files.
*
*
* @param urlsOfJarFiles the jar file URLs.
*
*/
public JarFileClassRetriever( URL[] urlsOfJarFiles )
{
setClassLoader( new URLClassLoader( urlsOfJarFiles ) );
}
/**
* Contruct a ClassRetriever from file paths.
*
*
* @param pathsOfJarFiles the paths that map to URLs
*
* @throws MalformedURLException if the paths are not mappable to URLS.
*
*/
public JarFileClassRetriever( String[] pathsOfJarFiles ) throws
MalformedURLException
{
URL[] urls = new URL[ pathsOfJarFiles.length ];
for( int i = 0; i < pathsOfJarFiles.length; i++ )
{
urls[ i ] = new File( pathsOfJarFiles[ i ] ).toURL();
}
setClassLoader( new URLClassLoader( urls ) );
}
/**
* Construct from a path to a jar file
*
*
* @param pathOfJarFile the path
*
* @throws MalformedURLException if the path is not mappable to a URL.
*
*/
public JarFileClassRetriever( String pathOfJarFile ) throws
MalformedURLException
{
setClassLoader( new URLClassLoader( new URL[]{new File( pathOfJarFile
).toURL()} ) );
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/JavacDynamicGeneratorClassRetriever.java
Index: JavacDynamicGeneratorClassRetriever.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.server.impl.classretrievers;
/**
* Class JavacDynamicGeneratorClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class JavacDynamicGeneratorClassRetriever extends
AbstractDynamicGeneratorClassRetriever
{
/**
* Contruct a Dynamic Class Generator with a classloader pointing to the
generator classes.
*
* @param classLoader the classloader in which the proxy generater will
be found.
*/
public JavacDynamicGeneratorClassRetriever(ClassLoader classLoader)
{
super(classLoader,
"org.apache.altrmi.tools.generator.ProxyGeneratorImpl");
}
/**
* Contruct a Dynamic Class Generator using the classes own classloader.
*
*/
public JavacDynamicGeneratorClassRetriever()
{
super(JavacDynamicGeneratorClassRetriever.class.getClassLoader(),
"org.apache.altrmi.tools.generator.ProxyGeneratorImpl");
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/NoClassRetriever.java
Index: NoClassRetriever.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.server.impl.classretrievers;
import org.apache.altrmi.server.ClassRetrievalException;
/**
* Class NoClassRetriever
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class NoClassRetriever extends AbstractClassRetriever
{
/**
*
* @param thingName get a byte array for a thing.
* @return the byte array
* @throws ClassRetrievalException if the retrieval failed.
*/
protected byte[] getThingBytes( String thingName ) throws
ClassRetrievalException
{
throw new ClassRetrievalException( "This AltRMI server does not
support class forwarding" );
}
}
1.1
incubator-altrmi/server/impl/src/java/org/apache/altrmi/server/impl/classretrievers/PlainClassRetriever.java
Index: PlainClassRetriever.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.server.impl.classretrievers;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.altrmi.server.ClassRetrievalException;
/**
* Class PlainClassRetriever
*
*
* @author Paul Hammant
* @author Vinay Chandrasekharan <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class PlainClassRetriever extends AbstractClassRetriever
{
private ClassLoader m_classLoader;
/**
* Constructor PlainClassRetriever
*
*
*/
public PlainClassRetriever()
{
m_classLoader = this.getClass().getClassLoader();
}
/**
* Create a plain clasretriever from a classloader.
*
*
* @param classLoader the classloader.
*
*/
public PlainClassRetriever( ClassLoader classLoader )
{
m_classLoader = classLoader;
}
/**
*
* Get the classfile byte array for the thing name
*
* @param thingName the things name
* @return the byte array of the thing.
* @throws ClassRetrievalException if the bytes are not available.
*/
protected byte[] getThingBytes( String thingName ) throws
ClassRetrievalException
{
InputStream is = null;
is = m_classLoader.getResourceAsStream( thingName + ".class" );
if( is == null )
{
throw new ClassRetrievalException( "Generated class for " +
thingName
+ " not found in specified
classloader " );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = 0;
try
{
while( -1 != ( i = is.read() ) )
{
baos.write( i );
}
is.close();
}
catch( IOException e )
{
throw new ClassRetrievalException( "Error retrieving generated
class bytes : "
+ e.getMessage() );
}
return baos.toByteArray();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]