You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by ae...@apache.org on 2006/09/01 07:23:57 UTC
svn commit: r439187 - in
/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator:
Messages.properties Wsdl2Java.java WsdlMerge.java WsdlMergeConstants.java
Author: aeberbac
Date: Thu Aug 31 22:23:56 2006
New Revision: 439187
URL: http://svn.apache.org/viewvc?rev=439187&view=rev
Log:
cleaned up messages, added better error handling and reporting
Added:
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMerge.java
- copied, changed from r438775, webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMerge.java
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMergeConstants.java
- copied, changed from r438775, webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMergeConstants.java
Modified:
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Messages.properties
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Wsdl2Java.java
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Messages.properties?rev=439187&r1=439186&r2=439187&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Messages.properties (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Messages.properties Thu Aug 31 22:23:56 2006
@@ -54,7 +54,7 @@
NoFactory = Failed creating the WSDL Factory. This is a problem with your copy of wsdl4j or your classpath.
FailedWSDLParse = Failed parsing WSDL XXX. Make sure the WSDL is well-formed, valid and all referenced WSDLs and Schemas are specified with relative paths.
FailedWSDLWrite = Failed writing to XXX. See exception message.
-FileExists = The specified file: XXX already exists. To overwrite it use XXX.
+FailedWSDLMerge = Failed merging WSDL. See exception message.
WsdlMergeHelp = Usage: wsdlmerge.[bat|sh] XXX URI XXX URL XXX FILE [OPTIONS] FILES\n\n\
The following arguments are required:\n\
\ \ XXX URI\t\tThe target namespace of the generated WSDL file\n\
@@ -63,4 +63,5 @@
FILES must be at least one WSDL file\n\n\
The following arguments are optional:\n\
\ \ XXX\t\tOverwrite files that exist\n\
-\ \ XXX\t\t\tDisplay this message\n
\ No newline at end of file
+\ \ XXX\t\t\tDisplay this message\n
+CouldNotMakeDir = Could not create the directory XXX.
\ No newline at end of file
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Wsdl2Java.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Wsdl2Java.java?rev=439187&r1=439186&r2=439187&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Wsdl2Java.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/Wsdl2Java.java Thu Aug 31 22:23:56 2006
@@ -367,17 +367,6 @@
}
/**
- * Check to see if the overwrite flag was specified. This
- * is just a call to see if the arguments contain the flag.
- *
- * @param arguments Command line arguments
- * @return true if the arguments contain the flag, false otherwise
- */
- private static boolean checkOverwriteArg(CommandLine arguments) {
- return arguments.hasFlag(OVERWRITE_FLAG);
- }
-
- /**
* Checl to see if the arguments have a WSDL flag. Also
* make sure that the WSDL file exists.
*
Copied: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMerge.java (from r438775, webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMerge.java)
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMerge.java?p2=webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMerge.java&p1=webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMerge.java&r1=438775&r2=439187&rev=439187&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMerge.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMerge.java Thu Aug 31 22:23:56 2006
@@ -14,7 +14,7 @@
* limitations under the License.
*=============================================================================*/
-package org.apache.muse.tools.generator.util;
+package org.apache.muse.tools.generator;
import java.io.File;
import java.io.FileWriter;
@@ -32,6 +32,8 @@
import javax.wsdl.xml.WSDLReader;
import javax.wsdl.xml.WSDLWriter;
+import org.apache.muse.tools.generator.util.AbstractCommandLineApp;
+import org.apache.muse.tools.generator.util.DefinitionInfo;
import org.apache.muse.util.CommandLine;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
@@ -40,7 +42,9 @@
/**
* Utility class to merge all the capability WSDLs into a single WSDL file
- * to represent the resource type
+ * to represent the resource type. This class will take all of the
+ * port types in the provided wsdls and make one port type. It will also
+ * combine the WS-RP documents into one.
*/
public class WsdlMerge extends AbstractCommandLineApp implements WsdlMergeConstants {
@@ -51,7 +55,7 @@
private static WSDLReader _reader;
private static WSDLWriter _writer;
-
+
static {
try {
_factory = WSDLFactory.newInstance();
@@ -61,7 +65,64 @@
handleErrorAndExit(_MESSAGES.get("NoFactory"), e);
}
}
+
+ /**
+ * Venerable main method. Take in the arguments, make sure they're valid
+ * and then try to do the WSDL merging.
+ *
+ * @param args The raw command line arguments
+ */
+ public static void main(String[] args) {
+ CommandLine arguments = parseParameters(args);
+
+ createLogger(arguments);
+
+ checkHelpArg(arguments);
+
+ String uri = checkUriArg(arguments);
+ String address = checkAddressArg(arguments);
+ String outputFileName = checkOutputArg(arguments);
+
+ Collection wsdls = checkWsdlArgs(arguments);
+
+ boolean overwrite = checkOverwriteArg(arguments);
+
+ Definition def = null;
+
+ try {
+ def = WsdlMerge.merge(uri, wsdls, address);
+ } catch (Exception e) {
+ handleErrorAndExit(_MESSAGES.get("FailedWSDLMerge"),e);
+ }
+
+
+ File output = new File(outputFileName);
+
+ try {
+ write(output, def, overwrite);
+ } catch (Exception e) {
+ Object[] filler = { output.getAbsolutePath() };
+ handleErrorAndExit(_MESSAGES.get("FailedWSDLWrite",filler), e);
+ }
+ }
+ /**
+ * Merge the collection of WSDLs into one document. This will
+ * try to take the portTypes and merge them along with the
+ * WS-RP documents (if they exist).
+ *
+ * @param namespaceURI
+ * The target namespace URI of the generated WSDL
+ *
+ * @param wsdlFragments
+ * The WSDL files to merge
+ *
+ * @param address
+ * The address used for the location attribute on the generated
+ * service
+ *
+ * @return The <code>Definition</code> representing the newly created merged WSDL
+ */
public static Definition merge(String namespaceURI,
Collection wsdlFragments, String address) {
@@ -79,6 +140,15 @@
return targetDefinition.getDefinition();
}
+ /**
+ * Copy properties (ie WS-RP Documents) from one WSDL to another.
+ *
+ * @param sourceDefinition
+ * The source WSDL
+ *
+ * @param targetDefinition
+ * The destination (merged) WSDL
+ */
private static void copyProperties(DefinitionInfo sourceDefinition,
DefinitionInfo targetDefinition) {
Types types = sourceDefinition.getTypes();
@@ -91,6 +161,15 @@
targetDefinition.mergeProperties(sourceDefinition);
}
+ /**
+ * Copy operations (ie portType operations) from one WSDL to another.
+ *
+ * @param sourceDefinition
+ * The source WSDL
+ *
+ * @param targetDefinition
+ * The destination (merged) WSDL
+ */
private static void copyOperations(DefinitionInfo sourceDefinition,
DefinitionInfo targetDefinition) {
// Need to keep a map of the messages we're referencing locally
@@ -103,42 +182,36 @@
targetDefinition.addOperation(nextOperation, localMessageMap);
}
}
-
- public static void main(String[] args) {
- CommandLine arguments = parseParameters(args);
-
- checkHelpArg(arguments);
-
- String uri = checkUriArg(arguments);
- String address = checkAddressArg(arguments);
- String output = checkOutputArg(arguments);
-
- Collection wsdls = checkWsdlArgs(arguments);
-
- boolean overwrite = checkOverwriteArg(arguments);
-
- Definition def = WsdlMerge.merge(uri, wsdls, address);
-
- write(output, def, overwrite);
- }
+ /**
+ * Check to see if the user provided the help parameters
+ * and display the appropriate help message (basic or advanced).
+ *
+ * @param arguments Command line arguments
+ */
private static void checkHelpArg(CommandLine arguments) {
if(arguments.hasFlag(HELP_FLAG) || hasNoArguments(arguments)) {
Object[] filler = new Object[] {
URI_FLAG,
ADDRESS_FLAG,
- OUTPUT_FLAG,
+ OUTPUT_FLAG,
+ URI_FLAG,
+ ADDRESS_FLAG,
+ OUTPUT_FLAG,
OVERWRITE_FLAG,
HELP_FLAG
};
- handleErrorAndExit(_MESSAGES.get("Help",filler,false));
+ handleMessage(_MESSAGES.get("WsdlMergeHelp",filler,false));
+ handleExit();
}
}
- private static boolean checkOverwriteArg(CommandLine arguments) {
- return arguments.hasFlag(OVERWRITE_FLAG);
- }
-
+ /**
+ * Check to make sure an address flag and value were provided.
+ *
+ * @param arguments The command line arguments
+ * @return The address provided
+ */
private static String checkAddressArg(CommandLine arguments) {
String addressArg = arguments.getFlagValue(ADDRESS_FLAG);
@@ -153,6 +226,12 @@
return addressArg;
}
+ /**
+ * Check to make sure a URI flag and value were provided.
+ *
+ * @param arguments The command line arguments
+ * @return The URI provided
+ */
private static String checkUriArg(CommandLine arguments) {
String uriArg = arguments.getFlagValue(URI_FLAG);
@@ -167,6 +246,12 @@
return uriArg;
}
+ /**
+ * Check to make sure an ouptut document flag and value were provided.
+ *
+ * @param arguments The command line arguments
+ * @return The output document
+ */
private static String checkOutputArg(CommandLine arguments) {
String outputArg = arguments.getFlagValue(OUTPUT_FLAG);
@@ -181,6 +266,14 @@
return outputArg;
}
+ /**
+ * Go through all of the parameters that are not flags and
+ * are not used and assume they are all WSDL documents. Make sure
+ * all of the documents exist and parse.
+ *
+ * @param arguments The command line arguments
+ * @return A <code>Collection</code> of <code>Definition</code> objects representing the parsed WSDLs.
+ */
private static Collection checkWsdlArgs(CommandLine arguments) {
ArrayList wsdls = new ArrayList();
String[] argWsdls = arguments.getArguments();
@@ -188,7 +281,7 @@
File wsdl = new File(argWsdls[i]);
if(!wsdl.exists()) {
Object[] filler = new Object[] {
- argWsdls[i]
+ wsdl.getAbsoluteFile()
};
handleErrorAndExit(_MESSAGES.get("NonExistantWSDL", filler));
}
@@ -203,6 +296,16 @@
return wsdls;
}
+ /**
+ * Given a <code>File</code> try to parse it and turn it into a
+ * <code>Definition</code>.
+ *
+ * @param wsdl
+ * The <code>File</code> to parse
+ *
+ * @return
+ * A <code>Defintion</code> if parsing was successful
+ */
private static Definition load(File wsdl) {
Document document = null;
Definition definition = null;
@@ -219,30 +322,46 @@
return definition;
}
- private static void write(String output, Definition def, boolean overwrite) {
- try {
- File wsdlFile = new File(output);
- if(wsdlFile.exists() && !overwrite) {
- Object[] filler = new Object[] {
- wsdlFile.getAbsolutePath(),
- OVERWRITE_FLAG
- };
- handleErrorAndExit(_MESSAGES.get("FileExists",filler));
+ /**
+ * Write a <code>Definition</code> to a file.
+ *
+ * @param destination
+ * The file where the definition will be written
+ * @param def
+ * The definition we're writing
+ * @param overwrite
+ * Should we overwrite existing files
+ *
+ * @throws Exception
+ * If anything goes wrong
+ */
+ private static void write(File destination, Definition def, boolean overwrite) throws Exception {
+ if (!destination.exists() || overwrite) {
+ File parent = destination.getAbsoluteFile().getParentFile();
+ if(!parent.exists()) {
+ if(!parent.mkdirs()) {
+ Object[] filler = { parent } ;
+ throw new Exception(_MESSAGES.get("CouldNotMakeDir",filler));
+ }
}
Document wsdlDoc = _writer.getDocument(def);
- FileWriter fileWriter = new FileWriter(wsdlFile);
+ FileWriter fileWriter = new FileWriter(destination);
fileWriter.write(XmlUtils.toString(wsdlDoc));
- fileWriter.close();
- } catch (Exception e) {
- Object[] filler = new Object[] {
- output
- };
- handleErrorAndExit(_MESSAGES.get("FailedWSDLWrite", filler),e);
+ fileWriter.close();
+ } else {
+ handleMessage(_MESSAGES.get("NotOverwriting", new String[] {destination.getPath()}));
}
}
-
+
+ /**
+ * Wraps the raw command line parameters into a <code>CommandLine</code>
+ * which will manage finding the flags passed in on the command line.
+ *
+ * @param args Raw command line parameters
+ * @return Wrapped <code>CommandLine</code> of the given parameters.
+ */
private static CommandLine parseParameters(String[] args) {
CommandLine arguments = new CommandLine();
Copied: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMergeConstants.java (from r438775, webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMergeConstants.java)
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMergeConstants.java?p2=webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMergeConstants.java&p1=webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMergeConstants.java&r1=438775&r2=439187&rev=439187&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/WsdlMergeConstants.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/WsdlMergeConstants.java Thu Aug 31 22:23:56 2006
@@ -14,7 +14,7 @@
* limitations under the License.
*=============================================================================*/
-package org.apache.muse.tools.generator.util;
+package org.apache.muse.tools.generator;
public interface WsdlMergeConstants {
String URI_FLAG = "-uri";
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org