Author: scamp Date: Wed Jan 5 14:10:36 2005 New Revision: 124282 URL: http://svn.apache.org/viewcvs?view=rev&rev=124282 Log: updated the flags for wsdl2java and included the commons io jar into the project.
These changes also allow us to now generate a jar file for the xmlbeans generated code. Modified: incubator/apollo/trunk/project.xml incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java incubator/apollo/trunk/src/site/content/tutorial/build.xml Modified: incubator/apollo/trunk/project.xml Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/project.xml?view=diff&rev=124282&p1=incubator/apollo/trunk/project.xml&r1=124281&p2=incubator/apollo/trunk/project.xml&r2=124282 ============================================================================== --- incubator/apollo/trunk/project.xml (original) +++ incubator/apollo/trunk/project.xml Wed Jan 5 14:10:36 2005 @@ -239,6 +239,18 @@ <war.bundle>true</war.bundle> </properties> </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.0</version> + <url>http://jakarta.apache.org/commons/io/</url> + <properties> + <license>ApacheLicense-2.0.txt</license> + <usage>Needed for general IO operations.</usage> + <war.bundle>true</war.bundle> + </properties> + </dependency> <dependency> <groupId>concurrent</groupId> Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java?view=diff&rev=124282&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java&r1=124281&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java&r2=124282 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java Wed Jan 5 14:10:36 2005 @@ -45,9 +45,9 @@ String OPT_OUTPUT_DIR_FOR_GEN_SRC = "OPT_OUTPUT_DIR_FOR_GEN_SRC"; /** - * @msg output directory for generated class files. + * @msg output directory for generated jar files. */ - String OPT_OUTPUT_DIR_FOR_GEN_CLASSES = "OPT_OUTPUT_DIR_FOR_GEN_CLASSES"; + String OPT_OUTPUT_DIR_FOR_GEN_JAR = "OPT_OUTPUT_DIR_FOR_GEN_JAR"; /** * @msg enable verbose output. Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java?view=diff&rev=124282&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java&r1=124281&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java&r2=124282 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java Wed Jan 5 14:10:36 2005 @@ -19,6 +19,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; @@ -40,7 +41,6 @@ import org.apache.ws.util.i18n.Messages; import org.apache.xmlbeans.impl.common.XmlErrorPrinter; import org.apache.xmlbeans.impl.tool.SchemaCompiler; - import javax.wsdl.Definition; import javax.wsdl.Service; import javax.wsdl.factory.WSDLFactory; @@ -49,6 +49,7 @@ import java.io.File; import java.io.FileWriter; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -62,590 +63,627 @@ */ public class Wsdl2Java { + private static final Messages MSG = MessagesImpl.getInstance( ); - private static final Messages MSG = MessagesImpl.getInstance(); - - /** - * DOCUMENT_ME - */ - protected static final Options CMD_LINE_OPTIONS = new Options(); - - static - { - initCmdLineOptions(); - } - - private File[] m_wsdlFiles; - private File m_srcOutputDir; - private File m_classesOutputDir; - private Wsdl2JavaOptions m_options; - private Map m_portTypeInfoMap = new HashMap(); - - /** - * Creates a new [EMAIL PROTECTED] Wsdl2Java} object. - * - * @param wsdlFiles DOCUMENT_ME - * @param srcOutputDir DOCUMENT_ME - * @param classesOutputDir DOCUMENT_ME - * @param options DOCUMENT_ME - */ - public Wsdl2Java( File[] wsdlFiles, - File srcOutputDir, - File classesOutputDir, - Wsdl2JavaOptions options ) - { - m_wsdlFiles = wsdlFiles; - if ( m_wsdlFiles.length == 0 ) - { - System.out.println( MSG.getMessage( Keys.WARN_EMPTY_WSDLS ) ); - } - - m_srcOutputDir = srcOutputDir; - m_classesOutputDir = classesOutputDir; - m_options = ( options != null ) ? options : new Wsdl2JavaOptions(); - initPortTypeInfoMap(); - } - - protected void addPortType2JavaInfo( PortType2JavaInfo ptInfo ) - { - m_portTypeInfoMap.put( ptInfo.getName(), ptInfo ); - } - - protected PortType2JavaInfo getPortType2JavaInfo( QName ptName ) - { - return (PortType2JavaInfo) m_portTypeInfoMap.get( ptName ); - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public File getClassesOutputDir() - { - return m_classesOutputDir; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public Wsdl2JavaOptions getOptions() - { - return m_options; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public File getSrcOutputDir() - { - return m_srcOutputDir; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public File[] getWsdlFiles() - { - return m_wsdlFiles; - } - - /** - * DOCUMENT_ME - * - * @throws Exception DOCUMENT_ME - */ - public void generate() - throws Exception - { - generateXmlBeans(); - initVelocity(); - for ( int i = 0; i < m_wsdlFiles.length; i++ ) - { - WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); - File wsdlFile = m_wsdlFiles[i]; - Definition def = wsdlReader.readWSDL( wsdlFile.getPath() ); - Iterator serviceIter = def.getServices().values().iterator(); - while ( serviceIter.hasNext() ) - { - Service service = (Service) serviceIter.next(); - ResourceDefinition resourceDef = new ResourceDefinitionImpl( def, service ); - processTemplates( resourceDef, wsdlFile.getName() ); - } - } - } - - private static void checkForRequiredOption( CommandLine cmdLine, - String opt ) - { - if ( !cmdLine.hasOption( opt ) ) - { - System.err.println( MSG.getMessage( Keys.OPT_REQUIRED, opt ) ); - System.exit( 1 ); - } - } - - private static void initCmdLineOptions() - { - CMD_LINE_OPTIONS.addOption( Opts.SRC_OUTPUT_DIR, - LongOpts.SRC_OUTPUT_DIR, - true, - MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_SRC ) ); - CMD_LINE_OPTIONS.addOption( Opts.CLASSES_OUTPUT_DIR, - LongOpts.CLASSES_OUTPUT_DIR, - true, - MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_CLASSES ) ); - CMD_LINE_OPTIONS.addOption( Opts.VERBOSE, - LongOpts.VERBOSE, - false, - MSG.getMessage( Keys.OPT_ENABLE_VERBOSE ) ); - CMD_LINE_OPTIONS.addOption( Opts.DEBUG, - LongOpts.DEBUG, - false, - MSG.getMessage( Keys.OPT_ENABLE_DEBUG ) ); - CMD_LINE_OPTIONS.addOption( Opts.CLASSPATH, - LongOpts.CLASSPATH, - false, - MSG.getMessage( Keys.OPT_CLASSPATH_SENT_TO_XMLBEANS ) ); - } - - private void processTemplates( ResourceDefinition resourceDef, String wsdlFileName ) - throws Exception - { - String serviceName = StringUtils.capitalize( resourceDef.getName() ); - try - { - VelocityContext context = new VelocityContext(); - ServiceProperties props = buildServiceProperties( serviceName, resourceDef, wsdlFileName ); - - //add to context - context.put( "generated", props ); - context.put( "qnames", new ConstQNames() ); - - //generate files - File packageDir = getPackageDir( resourceDef.getDefinition().getTargetNamespace() ); - packageDir.mkdirs(); - File outputFile = new File( packageDir, "Abstract" + serviceName + "Service.java" ); - processTemplate( context, - "templates/AbstractService.vm", - outputFile ); - - outputFile = new File( packageDir, serviceName + "Service.java" ); - //only generate if it doesn't exist - if ( !outputFile.exists() ) + /** + * DOCUMENT_ME + */ + protected static final Options CMD_LINE_OPTIONS = new Options( ); + + static + { + initCmdLineOptions( ); + } + + private File[] m_wsdlFiles; + private File m_srcOutputDir; + private File m_jarOutputDir; + private Wsdl2JavaOptions m_options; + private Map m_portTypeInfoMap = new HashMap( ); + + /** + * Creates a new [EMAIL PROTECTED] Wsdl2Java} object. + * + * @param wsdlFiles DOCUMENT_ME + * @param srcOutputDir DOCUMENT_ME + * @param classesOutputDir DOCUMENT_ME + * @param options DOCUMENT_ME + */ + public Wsdl2Java( File[] wsdlFiles, + File srcOutputDir, + File classesOutputDir, + Wsdl2JavaOptions options ) + { + m_wsdlFiles = wsdlFiles; + if ( m_wsdlFiles.length == 0 ) + { + System.out.println( MSG.getMessage( Keys.WARN_EMPTY_WSDLS ) ); + } + + m_srcOutputDir = srcOutputDir; + m_jarOutputDir = classesOutputDir; + m_options = ( options != null ) ? options : new Wsdl2JavaOptions( ); + initPortTypeInfoMap( ); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File getJarOutputDir( ) + { + return m_jarOutputDir; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public Wsdl2JavaOptions getOptions( ) + { + return m_options; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File getSrcOutputDir( ) + { + return m_srcOutputDir; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File[] getWsdlFiles( ) + { + return m_wsdlFiles; + } + + /** + * DOCUMENT_ME + * + * @throws Exception DOCUMENT_ME + */ + public void generate( ) + throws Exception + { + initVelocity( ); + for ( int i = 0; i < m_wsdlFiles.length; i++ ) + { + WSDLReader wsdlReader = WSDLFactory.newInstance( ).newWSDLReader( ); + File wsdlFile = m_wsdlFiles[i]; + generateXmlBeans( wsdlFile ); + Definition def = wsdlReader.readWSDL( wsdlFile.getPath( ) ); + Iterator serviceIter = def.getServices( ).values( ).iterator( ); + while ( serviceIter.hasNext( ) ) + { + Service service = (Service) serviceIter.next( ); + ResourceDefinition resourceDef = new ResourceDefinitionImpl( def, service ); + processTemplates( resourceDef, + wsdlFile.getName( ) ); + } + } + } + + /** + * DOCUMENT_ME + * + * @param args DOCUMENT_ME + * + * @throws ParseException DOCUMENT_ME + */ + public static void main( String[] args ) + throws ParseException + { + args = + new String[] + { + "-s", + "C:/gen/src", + "-j", + "C:/gen/jar", + "C:\\incubating-apollo-1.0-beta1\\webapps\\wsrf\\wsdl\\FileSystem.wsdl" + }; + CommandLine cmdLine = new PosixParser( ).parse( CMD_LINE_OPTIONS, args, true ); + checkForRequiredOption( cmdLine, Opts.SRC_OUTPUT_DIR ); + checkForRequiredOption( cmdLine, Opts.JAR_OUTPUT_DIR ); + File srcOutputDir = new File( cmdLine.getOptionValue( Opts.SRC_OUTPUT_DIR ) ); + File classesOutputDir = new File( cmdLine.getOptionValue( Opts.JAR_OUTPUT_DIR ) ); + + Wsdl2JavaOptions options = new Wsdl2Java.Wsdl2JavaOptions( ); + + if ( cmdLine.hasOption( Opts.CLASSPATH ) ) + { + options.setClasspath( cmdLine.getOptionValue( Opts.CLASSPATH ) ); + } + + if ( cmdLine.hasOption( Opts.VERBOSE ) ) + { + options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( Opts.VERBOSE ) ).booleanValue( ) ); + } + + if ( cmdLine.hasOption( Opts.DEBUG ) ) + { + options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( Opts.DEBUG ) ).booleanValue( ) ); + } + + File[] wsdlFiles = new File[cmdLine.getArgs( ).length]; + for ( int i = 0; i < cmdLine.getArgs( ).length; i++ ) + { + wsdlFiles[i] = new File( cmdLine.getArgs( )[i] ); + } + + try + { + System.out.println( MSG.getMessage( Keys.WSDL4J_PASSED_ARGUMENTS, + Integer.toString( wsdlFiles.length ), + srcOutputDir.toString( ), + classesOutputDir.toString( ) ) ); + new Wsdl2Java( wsdlFiles, srcOutputDir, classesOutputDir, options ).generate( ); + } + catch ( Exception e ) + { + e.printStackTrace( ); + System.exit( 1 ); + } + } + + /** + * DOCUMENT_ME + * + * @param ptName DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + protected PortType2JavaInfo getPortType2JavaInfo( QName ptName ) + { + return (PortType2JavaInfo) m_portTypeInfoMap.get( ptName ); + } + + /** + * DOCUMENT_ME + * + * @param ptInfo DOCUMENT_ME + */ + protected void addPortType2JavaInfo( PortType2JavaInfo ptInfo ) + { + m_portTypeInfoMap.put( ptInfo.getName( ), + ptInfo ); + } + + private static void checkForRequiredOption( CommandLine cmdLine, + String opt ) + { + if ( !cmdLine.hasOption( opt ) ) + { + System.err.println( MSG.getMessage( Keys.OPT_REQUIRED, opt ) ); + System.exit( 1 ); + } + } + + private static void initCmdLineOptions( ) + { + CMD_LINE_OPTIONS.addOption( Opts.SRC_OUTPUT_DIR, + LongOpts.SRC_OUTPUT_DIR, + true, + MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_SRC ) ); + CMD_LINE_OPTIONS.addOption( Opts.JAR_OUTPUT_DIR, + LongOpts.JAR_OUTPUT_DIR, + true, + MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_JAR ) ); + CMD_LINE_OPTIONS.addOption( Opts.VERBOSE, + LongOpts.VERBOSE, + false, + MSG.getMessage( Keys.OPT_ENABLE_VERBOSE ) ); + CMD_LINE_OPTIONS.addOption( Opts.DEBUG, + LongOpts.DEBUG, + false, + MSG.getMessage( Keys.OPT_ENABLE_DEBUG ) ); + CMD_LINE_OPTIONS.addOption( Opts.CLASSPATH, + LongOpts.CLASSPATH, + false, + MSG.getMessage( Keys.OPT_CLASSPATH_SENT_TO_XMLBEANS ) ); + } + + private String getJarFileName( File wsdlFile ) + { + String wsdlFileName = wsdlFile.getName( ); + wsdlFileName = wsdlFileName.substring( 0, + wsdlFileName.lastIndexOf( "." ) ); + wsdlFileName = wsdlFileName + ".jar"; + return wsdlFileName; + } + + private File getPackageDir( String targetNamespace ) + { + String javaPackageName = GenerationUtils.getJavaPackageName( targetNamespace ); + return new File( m_srcOutputDir, + javaPackageName.replace( '.', '/' ) ); + } + + private File getTempDir( ) + { + String userTempDir = System.getProperty( "java.io.tmpdir" ); + File userDir = new File( userTempDir ); + userDir.mkdirs( ); + File tempClassesDir = new File( userDir, "tmp" + new Date( ).getTime( ) ); + tempClassesDir.mkdir( ); + return tempClassesDir; + } + + private ServiceProperties buildServiceProperties( String serviceName, + ResourceDefinition resourceDef, + String wsdlFileName ) + { + ServiceProperties props = new ServiceProperties( ); + String targetNamespace = resourceDef.getDefinition( ).getTargetNamespace( ); + props.setPackageName( GenerationUtils.getJavaPackageName( targetNamespace ) ); + props.setServiceName( serviceName ); + props.setServiceImplements( ImplementsListBuilder.getServiceImplementsList( resourceDef, m_portTypeInfoMap ) ); + props.setNamespace( targetNamespace ); + props.setPrefix( GenerationUtils.getPrefix( targetNamespace ) ); + props.setCustomMappings( GenerationUtils.getOperationInfoMap( resourceDef ) ); + + QName[] customPropertyNames = resourceDef.getCustomPropertyNames( ); + Map customPropMap = new HashMap( ); + for ( int i = 0; i < customPropertyNames.length; i++ ) + { + QName customPropertyName = customPropertyNames[i]; + String propName = customPropertyName.getLocalPart( ).toUpperCase( ); + int count = 2; + while ( customPropMap.containsKey( propName ) ) + { + propName = propName + count; + count++; + } + + customPropMap.put( propName, customPropertyName ); + } + + props.setPropertyMap( customPropMap ); + props.setResourceImplements( ImplementsListBuilder.getResourceImplementsList( resourceDef, m_portTypeInfoMap ) ); + props.setPropertyDocumentName( XmlBeanNameUtils.getDocumentElementXmlBeanClassName( resourceDef + .getPropertiesDocumentName( ) ) ); + props.setWsdlName( wsdlFileName ); + + props.setResourcekey( new QName( targetNamespace, "ResourceID" ) ); + Iterator ptNameIter = resourceDef.getImplementedResourceCapabilities( ).keySet( ).iterator( ); + while ( ptNameIter.hasNext( ) ) + { + QName ptName = (QName) ptNameIter.next( ); + PortType2JavaInfo ptInfo = (PortType2JavaInfo) m_portTypeInfoMap.get( ptName ); + if ( ptInfo != null ) + { + if ( ptInfo.getResourceTemplateFileName( ) != null ) { - processTemplate( context, - "templates/Service.vm", - outputFile ); - } - outputFile = new File( packageDir, "Abstract" + serviceName + "Resource.java" ); - processTemplate( context, - "templates/AbstractResource.vm", - outputFile ); - - outputFile = new File( packageDir, serviceName + "Resource.java" ); - //only generate if it doesn't exist - if ( !outputFile.exists() ) - { - processTemplate( context, - "templates/Resource.vm", - outputFile ); + props.addResourceIncludeFile( ptInfo.getResourceTemplateFileName( ) ); } - outputFile = new File( packageDir, serviceName + "Home.java" ); - //only generate if it doesn't exist - if ( !outputFile.exists() ) + if ( ptInfo.getServiceTemplateFileName( ) != null ) { - processTemplate( context, - "templates/Home.vm", - outputFile ); + props.addServiceIncludeFile( ptInfo.getServiceTemplateFileName( ) ); } - //only if they implemented properties does this make sense. - if ( resourceDef.hasProperties() ) - { - outputFile = new File( packageDir, serviceName + "PropertyQNames.java" ); - processTemplate( context, - "templates/PropertyQNames.vm", - outputFile ); - } - - outputFile = new File( packageDir, serviceName + "_deploy.wsdd" ); - processTemplate( context, - "templates/deploy.vm", - outputFile ); - - outputFile = new File( packageDir, serviceName + "_jndi-config.wsdd" ); - processTemplate( context, - "templates/jndi.vm", - outputFile ); - - outputFile = new File( packageDir, serviceName + "CustomOperationsPortType.java" ); - processTemplate( context, - "templates/CustomOperationsPortType.vm", - outputFile ); - - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } - - private void initPortTypeInfoMap() - { - addPortType2JavaInfo( new GetResourcePropertyPortType2JavaInfo() ); - addPortType2JavaInfo( new GetMultipleResourcePropertiesPortType2JavaInfo() ); - addPortType2JavaInfo( new SetResourcePropertiesPortType2JavaInfo() ); - addPortType2JavaInfo( new QueryResourcePropertiesPortType2JavaInfo() ); - addPortType2JavaInfo( new ImmediateResourceTerminationPortType2JavaInfo() ); - addPortType2JavaInfo( new ScheduledResourceTerminationPortType2JavaInfo() ); - } - - private File getPackageDir( String targetNamespace ) - { - String javaPackageName = GenerationUtils.getJavaPackageName( targetNamespace ); - return new File( m_srcOutputDir, javaPackageName.replace( '.', '/' ) ); - } - - private ServiceProperties buildServiceProperties( String serviceName, ResourceDefinition resourceDef, - String wsdlFileName ) - { - ServiceProperties props = new ServiceProperties(); - String targetNamespace = resourceDef.getDefinition().getTargetNamespace(); - props.setPackageName( GenerationUtils.getJavaPackageName( targetNamespace ) ); - props.setServiceName( serviceName ); - props.setServiceImplements( ImplementsListBuilder.getServiceImplementsList( resourceDef, m_portTypeInfoMap ) ); - props.setNamespace( targetNamespace ); - props.setPrefix( GenerationUtils.getPrefix( targetNamespace ) ); - props.setCustomMappings( GenerationUtils.getOperationInfoMap( resourceDef ) ); - - QName[] customPropertyNames = resourceDef.getCustomPropertyNames(); - Map customPropMap = new HashMap(); - for ( int i = 0; i < customPropertyNames.length; i++ ) - { - QName customPropertyName = customPropertyNames[i]; - String propName = customPropertyName.getLocalPart().toUpperCase(); - int count = 2; - while ( customPropMap.containsKey( propName ) ) - { - propName = propName + count; - count++; - } - customPropMap.put( propName, customPropertyName ); - } - props.setPropertyMap( customPropMap ); - props.setResourceImplements( ImplementsListBuilder.getResourceImplementsList( resourceDef, m_portTypeInfoMap ) ); - props.setPropertyDocumentName( - XmlBeanNameUtils.getDocumentElementXmlBeanClassName( resourceDef.getPropertiesDocumentName() ) ); - props.setWsdlName( wsdlFileName ); - if ( m_options.getResourceKey() == null && !m_options.isSingleton() ) - { - m_options.setResourceKey( new QName( targetNamespace, "ResourceID" ) ); - } - props.setResourcekey( m_options.getResourceKey() ); - Iterator ptNameIter = resourceDef.getImplementedResourceCapabilities().keySet().iterator(); - while ( ptNameIter.hasNext() ) - { - QName ptName = (QName) ptNameIter.next(); - PortType2JavaInfo ptInfo = (PortType2JavaInfo) m_portTypeInfoMap.get( ptName ); - if ( ptInfo != null ) - { - if ( ptInfo.getResourceTemplateFileName() != null ) - { - props.addResourceIncludeFile( ptInfo.getResourceTemplateFileName() ); - } - if ( ptInfo.getServiceTemplateFileName() != null ) - { - props.addServiceIncludeFile( ptInfo.getServiceTemplateFileName() ); - } - } - } - return props; - } - - private void generateXmlBeans() - throws Exception - { - SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters(); - scompParams.setSrcDir( m_srcOutputDir ); - scompParams.setClassesDir( m_classesOutputDir ); - scompParams.setWsdlFiles( m_wsdlFiles ); - scompParams.setDownload( true ); - scompParams.setClasspath( m_options.getClasspath() ); - scompParams.setVerbose( m_options.isVerbose() ); - scompParams.setDebug( m_options.isDebug() ); - final boolean beNoisy = true; - XmlErrorPrinter xErrorListener = new XmlErrorPrinter( beNoisy, null ); - scompParams.setErrorListener( xErrorListener ); - m_srcOutputDir.mkdirs(); // necessary? - m_classesOutputDir.mkdirs(); // necessary? - if ( !SchemaCompiler.compile( scompParams ) ) - { - throw new Exception( xErrorListener.toString() ); - } - } - - private void initVelocity() - throws Exception - { - Velocity.addProperty( Velocity.RESOURCE_LOADER, "classpath" ); - Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".class", - "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" ); - Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".cache", "false" ); - Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".modificationCheckInterval", "2" ); - Velocity.init(); - } - - private void processTemplate( VelocityContext context, - String templateLocation, - File outputFile ) - throws Exception - { - /* - * get the Template object. This is the parsed version of your - * template input file. Note that getTemplate() can throw - * ResourceNotFoundException : if it doesn't find the template - * ParseErrorException : if there is something wrong with the VTL - * Exception : if something else goes wrong (this is generally - * indicative of as serious problem...) - */ - try - { - Template template = Velocity.getTemplate( templateLocation ); - - /* - * Now have the template engine process your template using the - * data placed into the context. Think of it as a 'merge' - * of the template and the data to produce the output stream. - */ - FileWriter writer = new FileWriter( outputFile ); - if ( template != null ) - { - template.merge( context, writer ); - } - writer.flush(); - writer.close(); - } - catch ( Exception e ) - { - System.err.println( "Error processing template " + templateLocation ); - e.printStackTrace(); - } - } - - /** - * DOCUMENT_ME - * - * @author $author$ - * @version $Revision: 1.8 $ - */ - public static class Wsdl2JavaOptions - { - private boolean m_verbose; - private boolean m_debug; - private File[] m_classpath; - private boolean m_singleton; - private QName m_resourceKey; - - public QName getResourceKey() - { - return m_resourceKey; - } - - public void setResourceKey( QName resourceKey ) - { - m_resourceKey = resourceKey; - } - - /** - * DOCUMENT_ME - * - * @param classpath DOCUMENT_ME - */ - public void setClasspath( File[] classpath ) - { - m_classpath = classpath; - } - - /** - * DOCUMENT_ME - * - * @param classpath DOCUMENT_ME - */ - public void setClasspath( String classpath ) - { - List classpathItems = new ArrayList(); - for ( StringTokenizer tokenizer = new StringTokenizer( classpath, File.pathSeparator ); - tokenizer.hasMoreTokens(); ) - { - classpathItems.add( new File( tokenizer.nextToken() ) ); - } - - m_classpath = (File[]) classpathItems.toArray( new File[0] ); - } + } + } - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public File[] getClasspath() - { - return m_classpath; - } - - /** - * DOCUMENT_ME - * - * @param debug DOCUMENT_ME - */ - public void setDebug( boolean debug ) - { - m_debug = debug; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public boolean isDebug() - { - return m_debug; - } - - /** - * DOCUMENT_ME - * - * @param verbose DOCUMENT_ME - */ - public void setVerbose( boolean verbose ) - { - m_verbose = verbose; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public boolean isSingleton() - { - return m_singleton; - } - - /** - * DOCUMENT_ME - * - * @param singleton DOCUMENT_ME - */ - public void setSingleton( boolean singleton ) - { - m_singleton = singleton; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public boolean isVerbose() - { - return m_verbose; - } - } - - static interface LongOpts - { - String SRC_OUTPUT_DIR = "srcOutputDir"; - String CLASSES_OUTPUT_DIR = "classesOutputDir"; - String VERBOSE = "verbose"; - String DEBUG = "debug"; - String CLASSPATH = "classpath"; - String SINGLETON = "singleton"; - String RESOURCE_KEY = "resourceKey"; - } - - static interface Opts - { - String SRC_OUTPUT_DIR = "s"; - String CLASSES_OUTPUT_DIR = "c"; - String VERBOSE = "v"; - String DEBUG = "d"; - String CLASSPATH = "C"; - String SINGLETON = "S"; - String RESOURCE_KEY = "k"; - } - - /** - * DOCUMENT_ME - * - * @param args DOCUMENT_ME - * - * @throws ParseException DOCUMENT_ME - */ - public static void main( String[] args ) - throws ParseException - { - args = new String[] - { - "-s", "C:/gen/src", - "-c", "C:/gen/classes", - "C:/opt/tomcat5.0.28/webapps/wsrf/wsdl/FileSystem.wsdl" - }; - CommandLine cmdLine = new PosixParser().parse( CMD_LINE_OPTIONS, args, true ); - checkForRequiredOption( cmdLine, Opts.SRC_OUTPUT_DIR ); - checkForRequiredOption( cmdLine, Opts.CLASSES_OUTPUT_DIR ); - File srcOutputDir = new File( cmdLine.getOptionValue( Opts.SRC_OUTPUT_DIR ) ); - File classesOutputDir = new File( cmdLine.getOptionValue( Opts.CLASSES_OUTPUT_DIR ) ); - - Wsdl2JavaOptions options = new Wsdl2Java.Wsdl2JavaOptions(); - if ( cmdLine.hasOption( Opts.SINGLETON ) ) - { - options.setSingleton( true ); - } - if ( cmdLine.hasOption( Opts.RESOURCE_KEY ) ) - { - options.setResourceKey( QName.valueOf( cmdLine.getOptionValue( Opts.RESOURCE_KEY ) ) ); - } - if ( cmdLine.hasOption( Opts.CLASSPATH ) ) - { - options.setClasspath( cmdLine.getOptionValue( Opts.CLASSPATH ) ); - } - if ( cmdLine.hasOption( Opts.VERBOSE ) ) - { - options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( Opts.VERBOSE ) ).booleanValue() ); - } - if ( cmdLine.hasOption( Opts.DEBUG ) ) - { - options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( Opts.DEBUG ) ).booleanValue() ); - } - - File[] wsdlFiles = new File[cmdLine.getArgs().length]; - for ( int i = 0; i < cmdLine.getArgs().length; i++ ) - { - wsdlFiles[i] = new File( cmdLine.getArgs()[i] ); - } - - try - { - System.out.println( MSG.getMessage( Keys.WSDL4J_PASSED_ARGUMENTS, - Integer.toString( wsdlFiles.length ), - srcOutputDir.toString(), - classesOutputDir.toString() ) ); - new Wsdl2Java( wsdlFiles, srcOutputDir, classesOutputDir, options ).generate(); - } - catch ( Exception e ) - { - e.printStackTrace(); - System.exit( 1 ); - } - } + return props; + } + private void generateXmlBeans( File wsdlFile ) + throws Exception + { + SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters( ); + scompParams.setSrcDir( m_srcOutputDir ); + + File tempClassesDir = getTempDir( ); + + scompParams.setClassesDir( tempClassesDir ); + scompParams.setWsdlFiles( new File[] + { + wsdlFile + } ); + scompParams.setDownload( true ); + scompParams.setClasspath( m_options.getClasspath( ) ); + scompParams.setVerbose( m_options.isVerbose( ) ); + scompParams.setDebug( m_options.isDebug( ) ); + final boolean beNoisy = true; + XmlErrorPrinter xErrorListener = new XmlErrorPrinter( beNoisy, null ); + scompParams.setErrorListener( xErrorListener ); + m_srcOutputDir.mkdirs( ); // necessary? + m_jarOutputDir.mkdirs( ); // necessary? + String wsdlJarFileName = getJarFileName( wsdlFile ); + scompParams.setOutputJar( new File( m_jarOutputDir, wsdlJarFileName ) ); + try + { + if ( !SchemaCompiler.compile( scompParams ) ) + { + throw new Exception( xErrorListener.toString( ) ); + } + } + finally + { + //delete the temp directory + FileUtils.deleteDirectory( tempClassesDir ); + } + } + + private void initPortTypeInfoMap( ) + { + addPortType2JavaInfo( new GetResourcePropertyPortType2JavaInfo( ) ); + addPortType2JavaInfo( new GetMultipleResourcePropertiesPortType2JavaInfo( ) ); + addPortType2JavaInfo( new SetResourcePropertiesPortType2JavaInfo( ) ); + addPortType2JavaInfo( new QueryResourcePropertiesPortType2JavaInfo( ) ); + addPortType2JavaInfo( new ImmediateResourceTerminationPortType2JavaInfo( ) ); + addPortType2JavaInfo( new ScheduledResourceTerminationPortType2JavaInfo( ) ); + } + + private void initVelocity( ) + throws Exception + { + Velocity.addProperty( Velocity.RESOURCE_LOADER, "classpath" ); + Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".class", + "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" ); + Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".cache", "false" ); + Velocity.setProperty( "classpath." + Velocity.RESOURCE_LOADER + ".modificationCheckInterval", "2" ); + Velocity.init( ); + } + + private void processTemplate( VelocityContext context, + String templateLocation, + File outputFile ) + throws Exception + { + /* + * get the Template object. This is the parsed version of your + * template input file. Note that getTemplate() can throw + * ResourceNotFoundException : if it doesn't find the template + * ParseErrorException : if there is something wrong with the VTL + * Exception : if something else goes wrong (this is generally + * indicative of as serious problem...) + */ + try + { + Template template = Velocity.getTemplate( templateLocation ); + + /* + * Now have the template engine process your template using the + * data placed into the context. Think of it as a 'merge' + * of the template and the data to produce the output stream. + */ + FileWriter writer = new FileWriter( outputFile ); + if ( template != null ) + { + template.merge( context, writer ); + } + + writer.flush( ); + writer.close( ); + } + catch ( Exception e ) + { + System.err.println( "Error processing template " + templateLocation ); + e.printStackTrace( ); + } + } + + private void processTemplates( ResourceDefinition resourceDef, + String wsdlFileName ) + throws Exception + { + String serviceName = StringUtils.capitalize( resourceDef.getName( ) ); + try + { + VelocityContext context = new VelocityContext( ); + ServiceProperties props = buildServiceProperties( serviceName, resourceDef, wsdlFileName ); + + //add to context + context.put( "generated", props ); + context.put( "qnames", + new ConstQNames( ) ); + + //generate files + File packageDir = getPackageDir( resourceDef.getDefinition( ).getTargetNamespace( ) ); + packageDir.mkdirs( ); + File outputFile = new File( packageDir, "Abstract" + serviceName + "Service.java" ); + processTemplate( context, "templates/AbstractService.vm", outputFile ); + + outputFile = new File( packageDir, serviceName + "Service.java" ); + + //only generate if it doesn't exist + if ( !outputFile.exists( ) ) + { + processTemplate( context, "templates/Service.vm", outputFile ); + } + + outputFile = new File( packageDir, "Abstract" + serviceName + "Resource.java" ); + processTemplate( context, "templates/AbstractResource.vm", outputFile ); + + outputFile = new File( packageDir, serviceName + "Resource.java" ); + + //only generate if it doesn't exist + if ( !outputFile.exists( ) ) + { + processTemplate( context, "templates/Resource.vm", outputFile ); + } + + outputFile = new File( packageDir, serviceName + "Home.java" ); + + //only generate if it doesn't exist + if ( !outputFile.exists( ) ) + { + processTemplate( context, "templates/Home.vm", outputFile ); + } + + //only if they implemented properties does this make sense. + if ( resourceDef.hasProperties( ) ) + { + outputFile = new File( packageDir, serviceName + "PropertyQNames.java" ); + processTemplate( context, "templates/PropertyQNames.vm", outputFile ); + } + + outputFile = new File( packageDir, serviceName + "_deploy.wsdd" ); + processTemplate( context, "templates/deploy.vm", outputFile ); + + outputFile = new File( packageDir, serviceName + "_jndi-config.xml" ); + processTemplate( context, "templates/jndi.vm", outputFile ); + + outputFile = new File( packageDir, serviceName + "CustomOperationsPortType.java" ); + processTemplate( context, "templates/CustomOperationsPortType.vm", outputFile ); + } + catch ( Exception e ) + { + e.printStackTrace( ); + } + } + + /** + * DOCUMENT_ME + * + * @version $Revision: 1.8 $ + * @author $author$ + */ + static interface LongOpts + { + /** DOCUMENT_ME */ + String SRC_OUTPUT_DIR = "srcOutputDir"; + + /** DOCUMENT_ME */ + String JAR_OUTPUT_DIR = "jarOutputDir"; + + /** DOCUMENT_ME */ + String VERBOSE = "verbose"; + + /** DOCUMENT_ME */ + String DEBUG = "debug"; + + /** DOCUMENT_ME */ + String CLASSPATH = "classpath"; + + /** DOCUMENT_ME */ + String SINGLETON = "singleton"; + + /** DOCUMENT_ME */ + String RESOURCE_KEY = "resourceKey"; + } + + /** + * DOCUMENT_ME + * + * @version $Revision: 1.8 $ + * @author $author$ + */ + static interface Opts + { + /** DOCUMENT_ME */ + String SRC_OUTPUT_DIR = "s"; + + /** DOCUMENT_ME */ + String JAR_OUTPUT_DIR = "j"; + + /** DOCUMENT_ME */ + String VERBOSE = "v"; + + /** DOCUMENT_ME */ + String DEBUG = "d"; + + /** DOCUMENT_ME */ + String CLASSPATH = "C"; + } + + /** + * DOCUMENT_ME + * + * @author $author$ + * @version $Revision: 1.8 $ + */ + public static class Wsdl2JavaOptions + { + private boolean m_verbose; + private boolean m_debug; + private File[] m_classpath; + + /** + * DOCUMENT_ME + * + * @param classpath DOCUMENT_ME + */ + public void setClasspath( File[] classpath ) + { + m_classpath = classpath; + } + + /** + * DOCUMENT_ME + * + * @param classpath DOCUMENT_ME + */ + public void setClasspath( String classpath ) + { + List classpathItems = new ArrayList( ); + for ( StringTokenizer tokenizer = new StringTokenizer( classpath, File.pathSeparator ); + tokenizer.hasMoreTokens( ); ) + { + classpathItems.add( new File( tokenizer.nextToken( ) ) ); + } + + m_classpath = (File[]) classpathItems.toArray( new File[0] ); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File[] getClasspath( ) + { + return m_classpath; + } + + /** + * DOCUMENT_ME + * + * @param debug DOCUMENT_ME + */ + public void setDebug( boolean debug ) + { + m_debug = debug; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public boolean isDebug( ) + { + return m_debug; + } + + /** + * DOCUMENT_ME + * + * @param verbose DOCUMENT_ME + */ + public void setVerbose( boolean verbose ) + { + m_verbose = verbose; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public boolean isVerbose( ) + { + return m_verbose; + } + } } Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java?view=diff&rev=124282&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java&r1=124281&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java&r2=124282 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2JavaTask.java Wed Jan 5 14:10:36 2005 @@ -22,9 +22,7 @@ import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; -import org.apache.ws.resource.tool.Wsdl2Java; -import javax.xml.namespace.QName; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -48,32 +46,20 @@ } private List m_wsdls = new ArrayList(); - private File m_classesOutputDir; + private File m_jarOutputDir; private File m_srcOutputDir; private Path m_classpath; private Boolean m_verbose; private Boolean m_debug; - private Boolean m_singleton; - private String m_resourceKey; - - public void setSingleton( Boolean singleton ) - { - m_singleton = singleton; - } - - public void setResourceKey( String resourceKey ) - { - m_resourceKey = resourceKey; - } public void setSrcOutputDir( File srcOutputDir ) { m_srcOutputDir = srcOutputDir; } - public void setClassesOutputDir( File classesOutputDir ) + public void setJarOutputDir( File jarOutputDir ) { - m_classesOutputDir = classesOutputDir; + m_jarOutputDir = jarOutputDir; } /** @@ -235,10 +221,6 @@ { options.setClasspath( m_classpath.toString() ); } - if ( m_resourceKey != null ) - { - options.setResourceKey( QName.valueOf( m_resourceKey ) ); - } if ( m_verbose != null ) { @@ -248,12 +230,9 @@ { options.setDebug( m_debug.booleanValue() ); } - if ( m_singleton != null ) - { - options.setSingleton( m_singleton.booleanValue() ); - } - Wsdl2Java wsdl2Java = new Wsdl2Java( (File[]) m_wsdls.toArray( new File[0] ), m_srcOutputDir, m_classesOutputDir, options ); + + Wsdl2Java wsdl2Java = new Wsdl2Java( (File[]) m_wsdls.toArray( new File[0] ), m_srcOutputDir, m_jarOutputDir, options ); try { wsdl2Java.generate(); Modified: incubator/apollo/trunk/src/site/content/tutorial/build.xml Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/site/content/tutorial/build.xml?view=diff&rev=124282&p1=incubator/apollo/trunk/src/site/content/tutorial/build.xml&r1=124281&p2=incubator/apollo/trunk/src/site/content/tutorial/build.xml&r2=124282 ============================================================================== --- incubator/apollo/trunk/src/site/content/tutorial/build.xml (original) +++ incubator/apollo/trunk/src/site/content/tutorial/build.xml Wed Jan 5 14:10:36 2005 @@ -11,6 +11,7 @@ <property name="generated.src.dir" location="build/src"/> <property name="classes.dir" location="build/classes"/> + <property name="jar.dir" location="build/output"/> <property name="src.dir" location="src" /> <property name="filesystem.wsdl" location="FileSystem.wsdl" /> <property name="sysprop.wsdl" location="SysProps.wsdl" /> @@ -48,7 +49,7 @@ <taskdef name="wsdl2Java" classname="org.apache.ws.resource.Wsdl2JavaTask" classpath="${apollo.classpath}" /> <wsdl2Java wsdl="${tmp.dir}/filesystem.wsdl" srcOutputDir="${generated.src.dir}" - classesOutputDir="${classes.dir}" + jarOutputDir="${jar.dir}" classpath="${apollo.classpath}" debug="off" proxyHost="${http.proxyHost}" @@ -57,7 +58,7 @@ <copy file="${sysprop.wsdl}" todir="${tmp.dir}" overwrite="true" /> <wsdl2Java wsdl="${tmp.dir}/SysProps.wsdl" srcOutputDir="${generated.src.dir}" - classesOutputDir="${classes.dir}" + jarOutputDir="${jar.dir}" classpath="${apollo.classpath}" debug="off" proxyHost="${http.proxyHost}" --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
