Author: ips Date: Thu Jan 6 13:36:14 2005 New Revision: 124451 URL: http://svn.apache.org/viewcvs?view=rev&rev=124451 Log: now has only one output option (-o)
Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java 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=124451&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java&r1=124450&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java&r2=124451 ============================================================================== --- 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 Thu Jan 6 13:36:14 2005 @@ -40,7 +40,7 @@ String RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"; /** - * @msg output directory for generated source files. + * @msg Output directory for generated files. */ String OPT_OUTPUT_DIR_FOR_GEN_SRC = "OPT_OUTPUT_DIR_FOR_GEN_SRC"; @@ -70,7 +70,7 @@ String WARN_EMPTY_WSDLS = "WARN_EMPTY_WSDLS"; /** - * @msg Calling Wsdl2Java with: {0} wsdl files, {1} src dir, {2} classes dir. + * @msg Calling Wsdl2Java with: {0} wsdl files, {1} output dir. */ String WSDL4J_PASSED_ARGUMENTS = "WSDL4J_PASSED_ARGUMENTS"; 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=124451&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java&r1=124450&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/tool/Wsdl2Java.java&r2=124451 ============================================================================== --- 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 Thu Jan 6 13:36:14 2005 @@ -41,6 +41,7 @@ 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; @@ -64,655 +65,641 @@ */ 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(); + } - /** - * 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( ); - private File m_srcXmlBeansDir; - private WSDLReader m_wsdlReader; - - /** - * 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 ) throws Exception - { - m_wsdlFiles = wsdlFiles; - if ( m_wsdlFiles.length == 0 ) - { - System.out.println( MSG.getMessage( Keys.WARN_EMPTY_WSDLS ) ); - } - m_srcXmlBeansDir = new File(srcOutputDir, "xmlbeans"); - m_srcOutputDir = new File(srcOutputDir, "java"); - m_jarOutputDir = classesOutputDir; - m_options = ( options != null ) ? options : new Wsdl2JavaOptions( ); - m_wsdlReader = WSDLFactory.newInstance( ).newWSDLReader( ); - initVelocity( ); - 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 - { - for ( int i = 0; i < m_wsdlFiles.length; i++ ) - { - processWsdlFile( m_wsdlFiles[i] ); - } - } + private File[] m_wsdlFiles; + private Wsdl2JavaOptions m_options; + private Map m_portTypeInfoMap = new HashMap(); + private WSDLReader m_wsdlReader; + private File m_outputDir; + private File m_javaSrcOutputDir; + private File m_xBeanSrcOutputDir; + private File m_classesOutputDir; + private File m_libOutputDir; + + /** + * Creates a new [EMAIL PROTECTED] Wsdl2Java} object. + * + * @param wsdlFiles DOCUMENT_ME + * @param outputDir DOCUMENT_ME + * @param options DOCUMENT_ME + */ + public Wsdl2Java( File[] wsdlFiles, + File outputDir, + Wsdl2JavaOptions options ) throws Exception + { + m_wsdlFiles = wsdlFiles; + if ( m_wsdlFiles.length == 0 ) + { + System.out.println( MSG.getMessage( Keys.WARN_EMPTY_WSDLS ) ); + } + m_outputDir = outputDir; + m_javaSrcOutputDir = new File( outputDir, "src/java" ); + m_xBeanSrcOutputDir = new File( outputDir, "src/xmlbeans" ); + m_classesOutputDir = new File( outputDir, "classes" ); + m_libOutputDir = new File( outputDir, "lib" ); + m_options = ( options != null ) ? options : new Wsdl2JavaOptions(); + m_wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + initVelocity(); + initPortTypeInfoMap(); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public Wsdl2JavaOptions getOptions() + { + return m_options; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File getOutputDir() + { + return m_outputDir; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public File[] getWsdlFiles() + { + return m_wsdlFiles; + } + + /** + * DOCUMENT_ME + * + * @throws Exception DOCUMENT_ME + */ + public void generate() + throws Exception + { + for ( int i = 0; i < m_wsdlFiles.length; i++ ) + { + processWsdlFile( m_wsdlFiles[i] ); + } + } private void processWsdlFile( File wsdlFile ) throws Exception { System.out.println( "Processing WSDL file \"" + wsdlFile + "\"..." ); - Definition def = m_wsdlReader.readWSDL( wsdlFile.getPath( ) ); - Iterator serviceIter = def.getServices( ).values( ).iterator( ); - while ( serviceIter.hasNext( ) ) - { - Service service = (Service) serviceIter.next( ); - ResourceDefinition resourceDef = new ResourceDefinitionImpl( def, service ); - System.out.println( "Processing WSRF service \"" + resourceDef.getName() + "\"..." ); - processTemplates( resourceDef, wsdlFile ); + Definition def = m_wsdlReader.readWSDL( wsdlFile.getPath() ); + Iterator serviceIter = def.getServices().values().iterator(); + while ( serviceIter.hasNext() ) + { + Service service = (Service) serviceIter.next(); + ResourceDefinition resourceDef = new ResourceDefinitionImpl( def, service ); + System.out.println( "Processing WSRF service \"" + resourceDef.getName() + "\"..." ); + processTemplates( resourceDef, wsdlFile ); } generateXmlBeans( wsdlFile ); } /** - * DOCUMENT_ME - * - * @param args DOCUMENT_ME - * - * @throws ParseException DOCUMENT_ME - */ - public static void main( String[] args ) - throws ParseException - { - 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( ResourceDefinition resourceDef, - String wsdlFileName ) - { - ServiceProperties props = new ServiceProperties( ); - String targetNamespace = resourceDef.getDefinition( ).getTargetNamespace( ); - props.setPackageName( GenerationUtils.getJavaPackageName( targetNamespace ) ); - String serviceName = resourceDef.getName(); - String upperCaseServiceName = getUpperCaseServiceName(serviceName); - props.setServiceName( upperCaseServiceName ); - props.setJarDir(m_jarOutputDir.getAbsolutePath()); - props.setSrcDir(m_srcOutputDir.getAbsolutePath()); - props.setClassesDir(new File(m_srcOutputDir.getParentFile().getParentFile(),"classes").getAbsolutePath()); - props.setEndpointURL( resourceDef.getEndpointURL()); - props.setEndpointServiceName(serviceName); - props.setServiceImplements( ImplementsListBuilder.getServiceImplementsList( resourceDef, m_portTypeInfoMap ) ); - props.setNamespace( targetNamespace ); - props.setPrefix( GenerationUtils.getPrefix( targetNamespace ) ); - props.setCustomMappings( GenerationUtils.getOperationInfoMap( resourceDef ) ); - props.setHasProperties(resourceDef.hasProperties()); - 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 ) + * DOCUMENT_ME + * + * @param args DOCUMENT_ME + * + * @throws ParseException DOCUMENT_ME + */ + public static void main( String[] args ) + throws ParseException + { + CommandLine cmdLine = new PosixParser().parse( CMD_LINE_OPTIONS, args, true ); + checkForRequiredOption( cmdLine, Opts.OUTPUT_DIR ); + File outputDir = new File( cmdLine.getOptionValue( Opts.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 ), + outputDir ) ); + new Wsdl2Java( wsdlFiles, outputDir, 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.OUTPUT_DIR, + LongOpts.OUTPUT_DIR, + true, + MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_SRC ) ); + CMD_LINE_OPTIONS.addOption( Opts.CLASSPATH, + LongOpts.CLASSPATH, + true, + MSG.getMessage( Keys.OPT_CLASSPATH_SENT_TO_XMLBEANS ) ); + 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 ) ); + } + + private String getJarFileName( File wsdlFile ) + { + String wsdlFileName = wsdlFile.getName(); + String baseName = wsdlFileName.substring( 0, wsdlFileName.lastIndexOf( "." ) ); + return baseName + "-xbeans.jar"; + } + + private File getPackageDir( String targetNamespace ) + { + String javaPackageName = GenerationUtils.getJavaPackageName( targetNamespace ); + return new File( m_javaSrcOutputDir, + 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( ResourceDefinition resourceDef, + String wsdlFileName ) + { + ServiceProperties props = new ServiceProperties(); + String targetNamespace = resourceDef.getDefinition().getTargetNamespace(); + props.setPackageName( GenerationUtils.getJavaPackageName( targetNamespace ) ); + String serviceName = resourceDef.getName(); + String upperCaseServiceName = getUpperCaseServiceName( serviceName ); + props.setServiceName( upperCaseServiceName ); + props.setJarDir( m_libOutputDir.getAbsolutePath() ); + props.setSrcDir( m_javaSrcOutputDir.getAbsolutePath() ); + props.setClassesDir( m_classesOutputDir.getAbsolutePath() ); + props.setEndpointURL( resourceDef.getEndpointURL() ); + props.setEndpointServiceName( serviceName ); + props.setServiceImplements( ImplementsListBuilder.getServiceImplementsList( resourceDef, m_portTypeInfoMap ) ); + props.setNamespace( targetNamespace ); + props.setPrefix( GenerationUtils.getPrefix( targetNamespace ) ); + props.setCustomMappings( GenerationUtils.getOperationInfoMap( resourceDef ) ); + props.setHasProperties( resourceDef.hasProperties() ); + 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 ) ) { - props.addResourceIncludeFile( ptInfo.getResourceTemplateFileName( ) ); + propName = propName + count; + count++; } - if ( ptInfo.getServiceTemplateFileName( ) != null ) + 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 ) { - props.addServiceIncludeFile( ptInfo.getServiceTemplateFileName( ) ); + if ( ptInfo.getResourceTemplateFileName() != null ) + { + props.addResourceIncludeFile( ptInfo.getResourceTemplateFileName() ); + } + + if ( ptInfo.getServiceTemplateFileName() != null ) + { + props.addServiceIncludeFile( ptInfo.getServiceTemplateFileName() ); + } } - } - } - - return props; - } + } + return props; + } - private void generateXmlBeans( File wsdlFile ) - throws Exception - { - System.out.println( "Generating XMLBeans for WSDL file \"" + wsdlFile + "\"..." ); - SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters( ); - scompParams.setSrcDir( m_srcXmlBeansDir ); - - 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( ) ); - } - //copy wsdl to subdir of src - copyWsdlFile(wsdlFile); - } - finally - { - //delete the temp directory - FileUtils.deleteDirectory( tempClassesDir ); - } - } + private void generateXmlBeans( File wsdlFile ) + throws Exception + { + System.out.println( "Generating XMLBeans for WSDL file \"" + wsdlFile + "\"..." ); + SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters(); + scompParams.setSrcDir( m_xBeanSrcOutputDir ); + 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_javaSrcOutputDir.mkdirs( ); // necessary? + m_libOutputDir.mkdirs( ); + String wsdlJarFileName = getJarFileName( wsdlFile ); + scompParams.setOutputJar( new File( m_libOutputDir, wsdlJarFileName ) ); + try + { + if ( !SchemaCompiler.compile( scompParams ) ) + { + throw new Exception( xErrorListener.toString() ); + } + //copy wsdl to subdir of src + copyWsdlFile( wsdlFile ); + } + finally + { + //delete the temp directory + FileUtils.deleteDirectory( tempClassesDir ); + } + } - private void copyWsdlFile(File wsdlFile) + private void copyWsdlFile( File wsdlFile ) throws IOException { - File wsdlDir = new File(m_srcOutputDir, "wsdl"); + File wsdlDir = new File( m_javaSrcOutputDir, "wsdl" ); wsdlDir.mkdirs(); - FileUtils.copyFile(wsdlFile, new File(wsdlDir,wsdlFile.getName())); + FileUtils.copyFile( wsdlFile, new File( wsdlDir, wsdlFile.getName() ) ); + } + + 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 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, - File wsdlFile ) - throws Exception - { - String serviceName = getUpperCaseServiceName(resourceDef.getName()); - try - { - VelocityContext context = new VelocityContext( ); - ServiceProperties props = buildServiceProperties( resourceDef, wsdlFile.getName() ); - - //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 ); - - outputFile = new File( m_srcOutputDir.getParentFile().getParentFile(), "build.xml" ); - processTemplate( context, "templates/build.xml.vm", outputFile ); - - outputFile = new File( m_srcOutputDir.getParentFile().getParentFile(), "build.properties" ); - processTemplate( context, "templates/build.properties.vm", outputFile ); - } - catch ( Exception e ) - { - e.printStackTrace( ); - } - } + private void processTemplates( ResourceDefinition resourceDef, + File wsdlFile ) + throws Exception + { + String serviceName = getUpperCaseServiceName( resourceDef.getName() ); + try + { + VelocityContext context = new VelocityContext(); + ServiceProperties props = buildServiceProperties( resourceDef, wsdlFile.getName() ); + + //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 ); + + outputFile = new File( m_javaSrcOutputDir.getParentFile().getParentFile(), "build.xml" ); + processTemplate( context, "templates/build.xml.vm", outputFile ); + + outputFile = new File( m_javaSrcOutputDir.getParentFile().getParentFile(), "build.properties" ); + processTemplate( context, "templates/build.properties.vm", outputFile ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } - private String getUpperCaseServiceName(String name) + private String getUpperCaseServiceName( String name ) { String serviceName = StringUtils.capitalize( name ); return serviceName; } /** - * 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; - } - } + * DOCUMENT_ME + * + * @author $author$ + * @version $Revision: 1.8 $ + */ + static interface LongOpts + { + /** + * DOCUMENT_ME + */ + String OUTPUT_DIR = "outputDir"; + + /** + * DOCUMENT_ME + */ + String VERBOSE = "verbose"; + + /** + * DOCUMENT_ME + */ + String DEBUG = "debug"; + + /** + * DOCUMENT_ME + */ + String CLASSPATH = "classpath"; + } + + /** + * DOCUMENT_ME + * + * @author $author$ + * @version $Revision: 1.8 $ + */ + static interface Opts + { + /** + * DOCUMENT_ME + */ + String OUTPUT_DIR = "o"; + + /** + * 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; + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
