vinayc 2003/08/28 11:39:22
Added: tools/src/java/org/apache/altrmi/tools/generator/ant
ProxyGenerationTask.java
Log:
Refactorize (includes modularize,mavenize & rest of the nice's)
Revision Changes Path
1.1
incubator-altrmi/tools/src/java/org/apache/altrmi/tools/generator/ant/ProxyGenerationTask.java
Index: ProxyGenerationTask.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.tools.generator.ant;
import java.io.File;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.altrmi.server.ProxyGenerationException;
import org.apache.altrmi.server.ProxyGenerator;
import org.apache.altrmi.server.PublicationDescriptionItem;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
/**
* Class ProxyGenerationTask
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class ProxyGenerationTask extends Task
{
protected String[] m_interfacesToExpose;
protected String[] m_additionalFacades;
protected String[] m_callbackFacades;
protected File m_srcGenDir;
protected File m_classGenDir;
protected String m_genName;
protected Path m_classpath;
protected String m_verbose = "false";
private String
m_generatorClass="org.apache.altrmi.tools.generator.ProxyGeneratorImpl";
/**
* Constructor ProxyGenerationTask
*
*
*/
public ProxyGenerationTask()
{
}
/**
* Method setInterfaces
*
*
* @param interfacesToExpose
*
*/
public void setInterfaces( String interfacesToExpose )
{
StringTokenizer st = new StringTokenizer( interfacesToExpose, "," );
Vector strings = new Vector();
while( st.hasMoreTokens() )
{
strings.add( st.nextToken().trim() );
}
m_interfacesToExpose = new String[ strings.size() ];
strings.copyInto( m_interfacesToExpose );
}
/**
* Method setAdditionalfacades
*
*
* @param additionalfacades
*
*/
public void setAdditionalfacades( String additionalfacades )
{
StringTokenizer st = new StringTokenizer( additionalfacades, "," );
Vector strings = new Vector();
while( st.hasMoreTokens() )
{
strings.add( st.nextToken().trim() );
}
m_additionalFacades = new String[ strings.size() ];
strings.copyInto( m_additionalFacades );
}
/**
* Method setAdditionalfacades
*
*
* @param callbackfacades
*
*/
public void setCallbackfacades( String callbackfacades )
{
StringTokenizer st = new StringTokenizer( callbackfacades, "," );
Vector strings = new Vector();
while( st.hasMoreTokens() )
{
strings.add( st.nextToken().trim() );
}
m_callbackFacades = new String[ strings.size() ];
strings.copyInto( m_callbackFacades );
}
/**
* Method setSrcgendir
*
*
* @param srcGenDir
*
*/
public void setSrcgendir( File srcGenDir )
{
m_srcGenDir = srcGenDir;
}
/**
* Method setClassgendir
*
*
* @param classGenDir
*
*/
public void setClassgendir( File classGenDir )
{
m_classGenDir = classGenDir;
}
/**
* Method setGenname
*
*
* @param genName
*
*/
public void setGenname( String genName )
{
this.m_genName = genName;
}
/**
* Method setM_classpath
*
*
* @param classpath
*
*/
public void setClasspath( Path classpath )
{
if( m_classpath == null )
{
m_classpath = classpath;
}
else
{
m_classpath.append( classpath );
}
}
/**
* Method createClasspath
*
*
* @return
*
*/
public Path createClasspath()
{
if( m_classpath == null )
{
m_classpath = new Path( project );
}
return m_classpath.createPath();
}
/**
* Method setClasspathRef
*
*
* @param r
*
*/
public void setClasspathRef( Reference r )
{
createClasspath().setRefid( r );
}
/**
* Method setVerbose
*
*
* @param verbose
*
*/
public void setVerbose( String verbose )
{
m_verbose = verbose;
}
/**
* Sets the GeneratorClass
* @param generatorClass The Generator Class to set.
*/
public void setGeneratorClass(String generatorClass)
{
this.m_generatorClass = generatorClass;
}
/**
* Method execute
*
*
* @throws BuildException
*
*/
public void execute() throws BuildException
{
if( m_interfacesToExpose == null )
{
throw new BuildException( "Specify at least one interface to
expose" );
}
if( m_srcGenDir == null )
{
throw new BuildException( "Specify the directory to generate Java
source in" );
}
if( m_classGenDir == null )
{
throw new BuildException( "Specify the directory to generate Java
classes in" );
}
if( m_genName == null )
{
throw new BuildException( "Specify the name to use for lookup" );
}
ProxyGenerator proxyGenerator;
try
{
proxyGenerator =
(ProxyGenerator)Class
.forName( m_generatorClass )
.newInstance();
}
catch( Exception e )
{
e.printStackTrace();
throw new RuntimeException( "PrimaryGenerator Impl jar not in
m_classpath" );
}
try
{
proxyGenerator.setSrcGenDir( m_srcGenDir.getAbsolutePath() );
proxyGenerator.setClassGenDir( m_classGenDir.getAbsolutePath() );
proxyGenerator.setGenName( m_genName );
proxyGenerator.verbose( Boolean.valueOf( m_verbose
).booleanValue() );
proxyGenerator.setClasspath( m_classpath.concatSystemClasspath(
"ignore" ).toString() );
PublicationDescriptionItem[] interfacesToExpose = new
PublicationDescriptionItem[ m_interfacesToExpose.length ];
ClassLoader classLoader = new AntClassLoader( getProject(),
m_classpath );
for( int i = 0; i < m_interfacesToExpose.length; i++ )
{
String cn = m_interfacesToExpose[ i ];
interfacesToExpose[ i ] = new
PublicationDescriptionItem(classLoader.loadClass( cn ));
}
proxyGenerator.setInterfacesToExpose( interfacesToExpose );
if( m_additionalFacades != null )
{
PublicationDescriptionItem[] additionalFacades = new
PublicationDescriptionItem[ m_additionalFacades.length ];
for( int i = 0; i < m_additionalFacades.length; i++ )
{
String cn = m_additionalFacades[ i ];
additionalFacades[ i ] = new
PublicationDescriptionItem(classLoader.loadClass( cn ));
}
proxyGenerator.setAdditionalFacades( additionalFacades );
}
if( m_callbackFacades != null )
{
PublicationDescriptionItem[] callbackFacades = new
PublicationDescriptionItem[ m_callbackFacades.length ];
for( int i = 0; i < m_callbackFacades.length; i++ )
{
String cn = m_callbackFacades[ i ];
callbackFacades[ i ] = new
PublicationDescriptionItem(classLoader.loadClass( cn ));
}
proxyGenerator.setCallbackFacades( callbackFacades );
}
ClassLoader classLoader2 = null;
if( m_classpath != null )
{
classLoader2 = new AntClassLoader( project, m_classpath );
}
else
{
classLoader2 = this.getClass().getClassLoader();
}
proxyGenerator.generateSrc( classLoader2 );
proxyGenerator.generateClass( classLoader2 );
}
catch( ClassNotFoundException cnfe )
{
cnfe.printStackTrace();
throw new BuildException( "Class not found : " +
cnfe.getMessage() );
}
catch( ProxyGenerationException sge )
{
throw new BuildException( "Proxy Gerneation error : " +
sge.getMessage() );
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]