Hi Dims, There are a lot of new System.err.println() calls in this patch.
Are we sure we want to do this? The Emitter is the class that get called programmatically by people who embed Axis.... -- Tom Jordahl Macromedia Server Development -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, December 30, 2002 1:06 PM To: [EMAIL PROTECTED] Subject: cvs commit: xml-axis/java/tools/org/apache/axis/tools/ant/wsdl Wsdl2javaAntTask.java dims 2002/12/30 10:05:42 Modified: java/src/org/apache/axis/wsdl/toJava Emitter.java java/src/org/apache/axis/i18n resource.properties java/tools/org/apache/axis/tools/ant/wsdl Wsdl2javaAntTask.java Log: Fix for Bug 15675 - Ant Task WDSL2java - property namespacemappingfile broken from [EMAIL PROTECTED] (Karl Guggisberg) Revision Changes Path 1.55 +64 -30 xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java Index: Emitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- Emitter.java 11 Dec 2002 22:38:30 -0000 1.54 +++ Emitter.java 30 Dec 2002 18:05:42 -0000 1.55 @@ -58,6 +58,7 @@ import org.apache.axis.encoding.DefaultTypeMappingImpl; import org.apache.axis.encoding.TypeMapping; import org.apache.axis.enum.Scope; +import org.apache.axis.i18n.Messages; import org.apache.axis.utils.ClassUtils; import org.apache.axis.utils.JavaUtils; import org.apache.axis.wsdl.gen.GeneratorFactory; @@ -88,12 +89,14 @@ * @author Steve Graham ([EMAIL PROTECTED]) */ public class Emitter extends Parser { + + public static final String DEFAULT_NSTOPKG_FILE = "NStoPkg.properties"; + protected HashMap namespaceMap = new HashMap(); protected String typeMappingVersion = "1.1"; protected BaseTypeMapping baseTypeMapping = null; protected Namespaces namespaces = null; - protected String NStoPkgFilename = "NStoPkg.properties"; - protected File NStoPkgFile = null; + protected String NStoPkgFilename = null; private boolean bEmitServer = false; private boolean bDeploySkeleton = false; @@ -249,12 +252,7 @@ } } // setNStoPkg - /** - * Set the NStoPkg mappings file. - */ - public void setNStoPkg(File NStoPkgFile) { - this.NStoPkgFile = NStoPkgFile; - } // setNStoPkg + /** * Set a map of namespace -> Java package names @@ -422,36 +420,72 @@ } } // setup + /** - * Look for a NStoPkg.properties file in the CLASSPATH. If it exists, - * then collect the namespace->package mappings from it. + * Tries to load the namespace-to-package mapping file. + * <ol> + * <li>if a file name is explicitly set using <code>setNStoPkg()</code>, tries + * to load the mapping from this file. If this fails, the built-in default + * mapping is used. + * + * <li>if no file name is set, tries to load the file <code>DEFAULT_NSTOPKG_FILE</code> + * as a java resource. If this fails, the built-in dfault mapping is used. + * </ol> + * + * @param namespaces a hashmap which is filled with the namespace-to-package mapping + * in this method + * + * @see #setNStoPkg(String) + * @see #DEFAULT_NSTOPKG_FILE + * @see org.apache.axis.utils.ClassUtils#getResourceAsStream(java.lang.Class,String) + * */ private void getNStoPkgFromPropsFile(HashMap namespaces) { - try { - Properties mappings = new Properties(); - if (NStoPkgFile != null) { - try { - mappings.load(new FileInputStream(NStoPkgFilename)); - } catch (Throwable t) { - mappings.load(ClassUtils.getResourceAsStream( - Emitter.class, NStoPkgFilename)); - } - } - else { + + Properties mappings = new Properties(); + if (NStoPkgFilename != null) { + try { mappings.load(new FileInputStream(NStoPkgFilename)); + System.out.println( + Messages.getMessage("nsToPkgFileLoaded00", NStoPkgFilename) + ); + } catch (Throwable t) { + // loading the custom mapping file failed. We do not try + // to load the mapping from a default mapping file. + System.err.println( + Messages.getMessage("nsToPkgFileNotFound00", NStoPkgFilename) + ); } - Enumeration keys = mappings.propertyNames(); - while (keys.hasMoreElements()) { - try { - String key = (String) keys.nextElement(); - namespaces.put(key, mappings.getProperty(key)); - } - catch (Throwable t) { - } + } + else { + try { + mappings.load(new FileInputStream(DEFAULT_NSTOPKG_FILE)); + System.out.println( + Messages.getMessage("nsToPkgFileLoaded00", DEFAULT_NSTOPKG_FILE) + ); + } catch (Throwable t) { + try { + mappings.load(ClassUtils.getResourceAsStream( + Emitter.class, DEFAULT_NSTOPKG_FILE)); + System.out.println( + Messages.getMessage("nsToPkgDefaultFileLoaded00", DEFAULT_NSTOPKG_FILE) + ); + + } catch(Throwable t1) { + // loading the default mapping file failed. The built-in default + // mapping is used + System.err.println( + Messages.getMessage("nsToPkgDefaultFileNotFound00", DEFAULT_NSTOPKG_FILE) + ); + } } } - catch (Throwable t) { + + Enumeration keys = mappings.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + namespaces.put(key, mappings.getProperty(key)); } } // getNStoPkgFromPropsFile 1.39 +4 -0 xml-axis/java/src/org/apache/axis/i18n/resource.properties Index: resource.properties =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/resource.properties,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- resource.properties 20 Dec 2002 17:28:22 -0000 1.38 +++ resource.properties 30 Dec 2002 18:05:42 -0000 1.39 @@ -1083,3 +1083,7 @@ wsdlFileMissing=Unable to find WSDL file or resource {0} nullEngine=Null engine passed to SOAPService.setEngine()! servletEngineWebInfError03=Unable to find config file. Creating new servlet engine config file: {0} +nsToPkgFileNotFound00=WARNING: Unable to open namespace-to-package mapping file "{0}". Using default mappings. +nsToPkgFileLoaded00=INFO: Loaded namespace-to-package mapping file "{0}". +nsToPkgDefaultFileLoaded00=INFO: Loaded default namespace-to-package mapping file "{0}" as java resource. +nsToPkgDefaultFileNotFound00=WARNING: Unable to open default namespace-to-package mapping file "{0}". Using default mappings. 1.9 +5 -6 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java Index: Wsdl2javaAntTask.java =================================================================== RCS file: /home/cvs/xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Wsdl2javaAntTask.java 11 Dec 2002 22:42:53 -0000 1.8 +++ Wsdl2javaAntTask.java 30 Dec 2002 18:05:42 -0000 1.9 @@ -196,9 +196,7 @@ public void execute() throws BuildException { //before we get any further, if the user didnt spec a namespace mapping //file, we load in the default - if(namespaceMappingFile==null) { - namespaceMappingFile = getProject().resolveFile("NStoPkg.properties"); - } + traceParams(Project.MSG_VERBOSE); validate(); try { @@ -234,7 +232,9 @@ emitter.setVerbose(verbose); emitter.setDebug(debug); emitter.setTypeMappingVersion(typeMappingVersion); - emitter.setNStoPkg(namespaceMappingFile); + if (namespaceMappingFile != null) { + emitter.setNStoPkg(namespaceMappingFile.toString()); + } emitter.setTimeout(timeout); Authenticator.setDefault(new DefaultAuthenticator(username,password)); @@ -432,7 +432,7 @@ } */ - + /** * should the task fail the build if there is a network error? * optional: defaults to false @@ -459,7 +459,6 @@ public void setUsername(String username) { this.username = username; } - /** * set any password required for BASIC authenticated access to the WSDL;