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/08/22 05:49:42 UTC

svn commit: r433492 - in /webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer: AggregateSynthesizer.java ClassInfo.java Messages.properties ProxySynthesizer.java ServerSynthesizer.java Synthesizer.java

Author: aeberbac
Date: Mon Aug 21 20:49:41 2006
New Revision: 433492

URL: http://svn.apache.org/viewvc?rev=433492&view=rev
Log:
Added some javadoc. Removed the Messages file since it isn't used anymore here.

Changed to use new Synthesizer API that takes a ConfigurationData object as a parameter, thereby cleaning up the API a bit.


Removed:
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Messages.properties
Modified:
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AggregateSynthesizer.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ClassInfo.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxySynthesizer.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ServerSynthesizer.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Synthesizer.java

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AggregateSynthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AggregateSynthesizer.java?rev=433492&r1=433491&r2=433492&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AggregateSynthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AggregateSynthesizer.java Mon Aug 21 20:49:41 2006
@@ -1,45 +1,106 @@
-/*=============================================================================*
- *  Copyright 2006 The Apache Software Foundation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *=============================================================================*/
-
-package org.apache.muse.tools.generator.synthesizer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 
- * AggregateSynthesizer is ...
- *
- * @author Andrew Eberbach
- *
- */
-
-public class AggregateSynthesizer implements Synthesizer {
-	
-	private Synthesizer[] _generators;
-
-	public AggregateSynthesizer(Synthesizer[] generators) {
-		_generators = generators;
-	}
-	
-	public Map generateFiles(Map capabilities) {
-		HashMap result = new HashMap();
-		for(int i=0; i < _generators.length; i++) {
-			result.putAll(_generators[i].generateFiles(capabilities));
-		}		
-		return result;
-	}
-}
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.tools.generator.synthesizer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.muse.tools.generator.util.ConfigurationData;
+import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
+
+/**
+ * 
+ * AggregateSynthesizer is a <code>Synthesizer</code> that wraps calling
+ * other <code>Synthesizer</code>s. This class iterates through its list
+ * of <code>Synthesizer</code>s and invokes <code>synthesize</code> on each
+ * one combining the resulting <code>ConfigurationData</code>.
+ *
+ * @author Andrew Eberbach (aeberbac)
+ *
+ */
+public class AggregateSynthesizer implements Synthesizer {
+	
+	private Synthesizer[] _synthesizers;
+	private ConfigurationDataDescriptor[] _requiredParameters;
+
+	public AggregateSynthesizer(Synthesizer[] synthesizers) {
+		_synthesizers = synthesizers;
+		_requiredParameters = getRequiredParameters(synthesizers);
+	}
+	
+	/**
+	 * Simply combines the required parameters from each of the given <code>Synthesizer</code>s.
+	 * 
+	 * @param synthesizers <code>Synthesizer</code>s who's parameters we will combine
+	 * @return A list containing all of the parameters (duplicates possible).
+	 */
+	private ConfigurationDataDescriptor[] getRequiredParameters(Synthesizer[] synthesizers) {
+		ArrayList list = new ArrayList();
+		for(int i=0; i < synthesizers.length; i++) {
+			Synthesizer synthesizer = synthesizers[i];
+			
+			ConfigurationDataDescriptor[] descriptors = 
+				synthesizer.getConfigurationDataDescriptions();
+			
+			for(int j=0; j < descriptors.length; j++) {
+				list.add(descriptors[j]);
+			}
+		}
+		
+		return (ConfigurationDataDescriptor[])
+			list.toArray(new ConfigurationDataDescriptor[list.size()]);
+	}
+
+	public ConfigurationData synthesize(ConfigurationData capabilities) throws Exception {
+		ConfigurationData result = new ConfigurationData();
+		for(int i=0; i < _synthesizers.length; i++) {
+			merge(_synthesizers[i].synthesize(capabilities), result);
+		}		
+		return result;
+	}
+
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return _requiredParameters;
+	}
+		
+	/**
+	 * Merge two <code>ConfigurationData</code> objects. This will do a 
+	 * shallow copy on parameters. If a parameter already exists in the target
+	 * and it is a Map, we will shallow copy the Map as well. Otherwise, the parameter
+	 * is ignored.
+	 * 
+	 * @param data <code>ConfigurationData</code> to merge.
+	 * @param result <code>ConfigurationData</code> accumulator for the merge.
+	 */
+	public void merge(ConfigurationData data, ConfigurationData result) {
+		for(Iterator i = data.getProperties().entrySet().iterator(); i.hasNext();) {
+			Map.Entry next = (Entry) i.next();
+					
+			Object existingValue = result.getParameter((String)next.getKey());
+			Object newValue = next.getValue();
+			if(existingValue != null) {
+				if(existingValue instanceof Map && newValue instanceof Map) {
+					((Map)existingValue).putAll((Map)newValue);
+				}
+			} else {
+				result.addParameter((String)next.getKey(), next.getValue());
+			}
+		}
+	}
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ClassInfo.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ClassInfo.java?rev=433492&r1=433491&r2=433492&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ClassInfo.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ClassInfo.java Mon Aug 21 20:49:41 2006
@@ -1,161 +1,158 @@
-/*=============================================================================*
- *  Copyright 2006 The Apache Software Foundation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *=============================================================================*/
-
-package org.apache.muse.tools.generator.synthesizer;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.muse.tools.generator.Capability;
-import org.apache.muse.tools.inspector.JavaMethod;
-import org.apache.muse.tools.inspector.JavaProperty;
-import org.apache.muse.util.ReflectUtils;
-
-/**
- * 
- * ClassInfo is ...
- *
- * @author Andrew Eberbach
- *
- */
-
-public class ClassInfo {
-
-	private static final String JAVA_CLASS_NAME = "MyCapability";
-	
-	private static final String IMPLEMENTATION_SUFFIX = "Impl";
-	
-	String _packageName = null;
-
-	String _classShortName = null;
-
-	Capability _capability = null;
-	
-	Set _imports = new HashSet();
-
-	Map _conflicts = new HashMap();
-
-	private String _classFullName;
-	
-	public ClassInfo(Capability capability) {
-		_packageName = getPackageName(capability.getURI());
-		_classShortName = JAVA_CLASS_NAME;
-		_classFullName = _packageName + "." + _classShortName;
-		_capability = capability;
-		
-		if(_capability.getImplementingClass() == null) {
-			_capability.setImplementingClass(_classFullName + IMPLEMENTATION_SUFFIX);
-		}
-		
-		findImports();
-	}
-
-	private void findImports() {		
-		for(Iterator i = _capability.getOperations().iterator(); i.hasNext();) {
-			JavaMethod method = (JavaMethod)i.next();
-			addImport(method.getReturnType());			
-			Class[] parameterTypes = method.getParameterTypes();
-			for(int j = 0; j < parameterTypes.length; j++) {
-				addImport(parameterTypes[j]);
-			}
-		}
-		
-		for(Iterator i = _capability.getProperties().iterator(); i.hasNext(); ) {
-			JavaProperty property = (JavaProperty)i.next();
-			addImport(property.getJavaType());
-		}
-	}
-
-	public void addImport(Class theClass) {
-		if(theClass.isArray()) {
-			theClass = ReflectUtils.getClassFromArrayClass(theClass);
-		}
-		String shortName = ReflectUtils.getShortName(theClass);
-		Set matches = (Set)_conflicts.get(shortName);
-		if(matches == null) {
-			matches = new HashSet();
-			matches.add(theClass);
-		} else {
-			
-			if(!matches.contains(theClass)) {
-				matches.add(theClass);
-			}
-		}
-		_conflicts.put(shortName, matches);		
-		_imports.add(theClass);
-	}
-	
-	public String getClassShortName() {
-		return _classShortName;
-	}
-
-	public String getPackageName() {
-		return _packageName;
-	}
-	
-	public String getClassFullName() {
-		return _classFullName;
-	}
-	
-	public Set getImports() {
-		return _imports;
-	}
-	
-	private String getPackageName(String uri) {
-		try {
-			String result = new String();
-			URL url = new URL(uri);
-
-			String[] hostParts = url.getHost().split("\\.");
-			for (int i = hostParts.length - 1; i >= 0; i--) {
-				if (hostParts[i].matches("^[^a-zA-Z_].*")) {
-					hostParts[i] = "_" + hostParts[i];
-				}
-				result += hostParts[i] + ".";
-			}
-
-			String[] fileParts = url.getPath().split("/");
-			for (int i = 0; i < fileParts.length - 1; i++) {
-				if (fileParts[i].matches("^[^a-zA-Z_].*")) {
-					fileParts[i] = "_" + fileParts[i];
-				}
-				if (fileParts[i].length() != 0) {
-					result += fileParts[i] + ".";
-				}
-			}
-			result += fileParts[fileParts.length - 1];
-
-			result = result.replaceAll("[^.a-z0-9_]", "_");
-			return result;
-		} catch (MalformedURLException e) {
-			return "org.tempuri";
-		}
-	}
-
-	public boolean hasConflict(Class theClass) {
-		Integer count = (Integer)_conflicts.get(theClass);		
-		return (count != null) && (count.intValue() > 1); 
-	}
-
-	public Capability getCapability() {
-		return _capability;
-	}
-}
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.tools.generator.synthesizer;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.muse.tools.generator.util.Capability;
+import org.apache.muse.tools.inspector.JavaMethod;
+import org.apache.muse.tools.inspector.JavaProperty;
+import org.apache.muse.util.ReflectUtils;
+
+/**
+ * 
+ * ClassInfo is ...
+ *
+ * @author Andrew Eberbach
+ *
+ */
+
+public class ClassInfo {
+
+	private static final String JAVA_CLASS_NAME = "MyCapability";
+	
+	String _packageName = null;
+
+	String _classShortName = null;
+
+	Capability _capability = null;
+	
+	Set _imports = new HashSet();
+
+	Map _conflicts = new HashMap();
+
+	private String _classFullName;
+	
+	public ClassInfo(Capability capability) {	
+		_packageName = getPackageName(capability.getURI());
+		_classShortName = JAVA_CLASS_NAME;
+		_classFullName = _packageName + "." + _classShortName;
+		_capability = capability;
+		
+		if(_capability.getImplementingClass() == null) {
+			_capability.setImplementingClass(_classFullName);
+		}
+		
+		findImports();
+	}
+
+	private void findImports() {		
+		for(Iterator i = _capability.getOperations().iterator(); i.hasNext();) {
+			JavaMethod method = (JavaMethod)i.next();
+			addImport(method.getReturnType());			
+			Class[] parameterTypes = method.getParameterTypes();
+			for(int j = 0; j < parameterTypes.length; j++) {
+				addImport(parameterTypes[j]);
+			}
+		}
+		
+		for(Iterator i = _capability.getProperties().iterator(); i.hasNext(); ) {
+			JavaProperty property = (JavaProperty)i.next();
+			addImport(property.getJavaType());
+		}
+	}
+
+	public void addImport(Class theClass) {
+		if(theClass.isArray()) {
+			theClass = ReflectUtils.getClassFromArrayClass(theClass);
+		}
+		String shortName = ReflectUtils.getShortName(theClass);
+		Set matches = (Set)_conflicts.get(shortName);
+		if(matches == null) {
+			matches = new HashSet();
+			matches.add(theClass);
+		} else {
+			
+			if(!matches.contains(theClass)) {
+				matches.add(theClass);
+			}
+		}
+		_conflicts.put(shortName, matches);		
+		_imports.add(theClass);
+	}
+	
+	public String getClassShortName() {
+		return _classShortName;
+	}
+
+	public String getPackageName() {
+		return _packageName;
+	}
+	
+	public String getClassFullName() {
+		return _classFullName;
+	}
+	
+	public Set getImports() {
+		return _imports;
+	}
+	
+	public static String getPackageName(String uri) {
+		try {
+			String result = new String();
+			URL url = new URL(uri);
+
+			String[] hostParts = url.getHost().split("\\.");
+			for (int i = hostParts.length - 1; i >= 0; i--) {
+				if (hostParts[i].matches("^[^a-zA-Z_]")) {
+					hostParts[i] = "_" + hostParts[i];
+				}
+				result += hostParts[i] + ".";
+			}
+
+			String[] fileParts = url.getPath().split("/");
+			for (int i = 0; i < fileParts.length - 1; i++) {
+				if (fileParts[i].matches("^[^a-zA-Z_]")) {
+					fileParts[i] = "_" + fileParts[i];
+				}
+				if (fileParts[i].length() != 0) {
+					result += fileParts[i] + ".";
+				}
+			}
+			result += fileParts[fileParts.length - 1];
+
+			result = result.replaceAll("[^.a-zA-Z0-9_]", "_");
+			return result;
+		} catch (Exception e) {
+			return "org.tempuri";
+		}
+	}
+
+	public boolean hasConflict(Class theClass) {
+		Integer count = (Integer)_conflicts.get(theClass);		
+		return (count != null) && (count.intValue() > 1); 
+	}
+
+	public Capability getCapability() {
+		return _capability;
+	}
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxySynthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxySynthesizer.java?rev=433492&r1=433491&r2=433492&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxySynthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxySynthesizer.java Mon Aug 21 20:49:41 2006
@@ -16,9 +16,6 @@
 
 package org.apache.muse.tools.generator.synthesizer;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -30,17 +27,13 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.muse.core.Resource;
-import org.apache.muse.tools.generator.LocalEnvironment;
+import org.apache.muse.tools.generator.util.ConfigurationData;
+import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
+import org.apache.muse.tools.generator.util.LocalEnvironment;
 import org.apache.muse.tools.inspector.ResourceInspector;
-import org.apache.muse.util.CommandLine;
 import org.apache.muse.util.ReflectUtils;
-import org.apache.muse.util.messages.Messages;
-import org.apache.muse.util.messages.MessagesFactory;
 import org.apache.muse.util.xml.XmlUtils;
 import org.apache.muse.util.xml.XsdUtils;
-import org.apache.muse.ws.notification.remote.NotificationConsumerClient;
-import org.apache.muse.ws.notification.remote.NotificationProducerClient;
 import org.apache.muse.ws.resource.metadata.WsrmdConstants;
 import org.apache.muse.ws.wsdl.WsdlUtils;
 import org.w3c.dom.Document;
@@ -55,111 +48,32 @@
  * directly from Java code.
  *
  * @author Dan Jemiolo (danj)
+ * @author Andrew Eberbach (aeberbac)
  * 
- * @see #main(String[])
- * @see #run(String, String)
- *
  */
-
 public class ProxySynthesizer implements Synthesizer
 {
-    //
-    // Used to lookup all exception messages
-    //
-    private static Messages _MESSAGES = MessagesFactory.get(ProxySynthesizer.class);
-    
-    //
-    // Used to request trace info during code gen
-    //
-    private static final String _VERBOSE_FLAG = "-v";
-        
-    /**
-     * 
-     * Creates a web service proxy class from a WSDL file.
-     *
-     * @param args
-     *        <ol>
-     *        <li>WSDL file - The WSDL that contains the resource type's
-     *        portType.</li>
-     *        <li>Java interface - The name of the interface that the tool 
-     *        should generate and the proxy class will implement.</li>
-     *        </ol>
-     *        <br><br>
-     *        <b>There is also</b> a <em>-v</em> flag that can be used (at 
-     *        any point) to turn on verbose mode (useful for debugging).
-     * 
-     * @see #run(String, String)
-     *
-     */
-    public static void main(String[] args) throws Exception
-    {
-        CommandLine cmdLine = new CommandLine();        
-        cmdLine.parse(args);
-        
-        boolean verbose = cmdLine.hasFlag(_VERBOSE_FLAG);
-        args = cmdLine.getArguments();
-        
-        if (args.length != 2)
-            printUsageAndQuit();
-        
-        ProxySynthesizer theApp = new ProxySynthesizer();
-        theApp.setVerbose(verbose);
-        
-        try
-        {
-            Map files = theApp.run(args[0], args[1]);
-            Iterator i = files.keySet().iterator();
-            
-            while (i.hasNext())
-            {
-                String typeName = (String)i.next();
-                theApp.writeToFile(typeName, (String)files.get(typeName));
-            }
-        }
-        
-        catch (Throwable error)
-        {
-            error.printStackTrace();
-        }
-    }
-    
-    private static void printUsageAndQuit()
-    {
-        System.err.println("\nUsage is:\n");
-        System.err.println("\t> ProxyGenerator [WSDL file] [Java interface name]\n");
+	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
+		new ConfigurationDataDescriptor[] {
+			ConfigurationData.CAPABILITIES_MAP_CONFIGURATION,
+		};
+	
+    private static final String SERVICE_NAME = "MyService";
+
+	private static final String TARGET_NS_ATTR = "targetNamespace";
         
-        System.exit(0);
-    }
-    
     private LocalEnvironment _environment = new LocalEnvironment(false);
-    
-    //
-    // True if the tool should print trace info to stdout during code gen
-    //
-    private boolean _isVerbose = false;
         
     private String createProxyClass(ResourceInspector inspector, 
                                     String interfaceName, 
                                     String proxyName)
     {   
-        if (isVerbose())
-        {
-            Object[] filler = { proxyName };
-            System.out.println(_MESSAGES.get("StartCodeGen", filler));
-        }
-        
         StringBuffer writer = new StringBuffer(10000);
         
         generateProxyHeader(writer, inspector, interfaceName, proxyName);
         generateMethods(writer, inspector, false);        
         generateProxyConstructors(writer, inspector, proxyName);
-        generateProxyFooter(writer, inspector);
-        
-        if (isVerbose())
-        {
-            Object[] filler = { proxyName };
-            System.out.println(_MESSAGES.get("FinishCodeGen", filler));
-        }
+        generateProxyFooter(writer, inspector);        
         
         return writer.toString();
     }
@@ -171,11 +85,6 @@
 
     private String createRemoteInterface(ResourceInspector inspector, String interfaceName)
     {
-        if (isVerbose())
-        {
-            Object[] filler = { interfaceName };
-            System.out.println(_MESSAGES.get("StartCodeGen", filler));
-        }
         
         StringBuffer writer = new StringBuffer(10000);
         
@@ -183,12 +92,6 @@
         generateMethods(writer, inspector, true);        
         generateRemoteFooter(writer, inspector);
         
-        if (isVerbose())
-        {
-            Object[] filler = { interfaceName };
-            System.out.println(_MESSAGES.get("FinishCodeGen", filler));
-        }
-        
         return writer.toString();
     }
     
@@ -215,8 +118,8 @@
         
         Map results = new HashMap();
         
-        results.put(interfaceName, interfaceJava);
-        results.put(proxyName, proxyJava);
+        results.put(createFileName(interfaceName), interfaceJava);
+        results.put(createFileName(proxyName), proxyJava);
         
         return results;
     }
@@ -319,17 +222,19 @@
     {
         writer.append("public interface ");
         writer.append(ReflectUtils.getShortName(remoteClassName));
-        writer.append(" extends ");
-        
-        Iterator i = extendsTypes.iterator();
-        
-        while (i.hasNext())
-        {
-            Class type = (Class)i.next();
-            writer.append(ReflectUtils.getShortName(type));
-            
-            if (i.hasNext())
-                writer.append(", ");
+                
+        if(extendsTypes.size() > 0) {
+        	writer.append(" extends ");
+	        Iterator i = extendsTypes.iterator();
+	        
+	        while (i.hasNext())
+	        {
+	            Class type = (Class)i.next();
+	            writer.append(ReflectUtils.getShortName(type));
+	            
+	            if (i.hasNext())
+	                writer.append(", ");
+	        }
         }
         
         writer.append("\n{");
@@ -373,11 +278,6 @@
                                 String methodName, 
                                 boolean justSignature)
     {
-        if (isVerbose())
-        {
-            Object[] filler = { methodName };
-            System.out.println(_MESSAGES.get("MethodGen", filler));
-        }
 
         writer.append("\n\t");
         
@@ -394,7 +294,7 @@
         Class[] paramTypes = inspector.getParameterTypes(methodName);
         generateParamList(writer, paramNames, paramTypes);
         
-        writer.append("\t\tthrows RemoteException");
+        writer.append("\t\tthrows SoapFault");
         
         if (justSignature)
             writer.append(';');
@@ -545,12 +445,6 @@
     {
         Collection properties = inspector.getProperties();
         
-        if (isVerbose())
-        {
-            Object[] filler = { new Integer(properties.size()) };
-            System.out.println(_MESSAGES.get("PropertiesGen", filler));
-        }
-        
         writer.append("\n\tQName[] PROPERTIES = {\n");
         
         Iterator i = properties.iterator();
@@ -575,11 +469,6 @@
                                         int propertyIndex, 
                                         boolean justSignature)
     {
-        if (isVerbose())
-        {
-            Object[] filler = { "delete" + propertyName.getLocalPart() };
-            System.out.println(_MESSAGES.get("MethodGen", filler));
-        }
 
         writer.append("\n\t");
         
@@ -593,7 +482,7 @@
         
         writer.append("void delete" + propertyName.getLocalPart());
         writer.append("()\n");
-        writer.append("\t\tthrows RemoteException");
+        writer.append("\t\tthrows SoapFault");
         
         if (justSignature)
             writer.append(';');
@@ -618,11 +507,6 @@
                                      int propertyIndex, 
                                      boolean justSignature)
     {
-        if (isVerbose())
-        {
-            Object[] filler = { "get" + propertyName.getLocalPart() };
-            System.out.println(_MESSAGES.get("MethodGen", filler));
-        }
 
         writer.append("\n\t");
         
@@ -635,7 +519,7 @@
         writer.append(' ');
         writer.append("get" + propertyName.getLocalPart());
         writer.append("()\n");        
-        writer.append("\t\tthrows RemoteException");
+        writer.append("\t\tthrows SoapFault");
         
         if (justSignature)
             writer.append(';');
@@ -700,12 +584,6 @@
                                      boolean justSignature, 
                                      String setType)
     {
-        if (isVerbose())
-        {
-            Object[] filler = { setType + propertyName.getLocalPart() };
-            System.out.println(_MESSAGES.get("MethodGen", filler));
-        }
-
         writer.append("\n\t");
         
         if (!justSignature)
@@ -719,7 +597,7 @@
         writer.append('(');
         writer.append(ReflectUtils.getShortName(type));
         writer.append(" value)\n");
-        writer.append("\t\tthrows RemoteException");
+        writer.append("\t\tthrows SoapFault");
         
         if (justSignature)
             writer.append(';');
@@ -810,12 +688,6 @@
         Class extendsType = inspector.getBaseProxyClass();
         String extendsName = extendsType.getName();
         
-        if (isVerbose())
-        {
-            Object[] filler = { proxyName, extendsName };
-            System.out.println(_MESSAGES.get("Extending", filler));
-        }
-        
         generateComment(writer, proxyName);
         generatePackage(writer, proxyName);
         generateProxyImports(writer, extendsName);
@@ -826,7 +698,7 @@
     private void generateProxyImports(StringBuffer writer, String extendsType)
     {
         writer.append("import java.lang.reflect.Array;\n");
-        writer.append("import java.rmi.RemoteException;\n");
+        writer.append("import org.apache.muse.ws.addressing.soap.SoapFault;\n");
         writer.append("import java.util.Date;\n");
         writer.append("import java.util.HashMap;\n");
         writer.append("import java.util.Map;\n\n");
@@ -876,12 +748,6 @@
     {
         List extendsTypes = getRemoteExtends(inspector);
         
-        if (isVerbose())
-        {
-            Object[] filler = { remoteClassName, extendsTypes };
-            System.out.println(_MESSAGES.get("Extending", filler));
-        }
-        
         generateComment(writer, remoteClassName);
         generatePackage(writer, remoteClassName);
         generateRemoteImports(writer, extendsTypes);
@@ -892,21 +758,20 @@
     private void generateRemoteImports(StringBuffer writer, List extendsTypes)
     {
         writer.append("import java.util.Date;\n\n");
-        writer.append("import java.rmi.RemoteException;\n\n");
+        writer.append("import org.apache.muse.ws.addressing.soap.SoapFault;\n\n");
         writer.append("import javax.xml.namespace.QName;\n\n");
         writer.append("import org.w3c.dom.Element;\n\n");
         
         writer.append("import org.apache.muse.ws.addressing.EndpointReference;\n");
         
-        Iterator i = extendsTypes.iterator();
-        
-        while (i.hasNext())
-        {
-            Class type = (Class)i.next();
-            writer.append("import " + type.getName() + ";\n");
-        }
+		Iterator i = extendsTypes.iterator();
+
+		while (i.hasNext()) {
+			Class type = (Class) i.next();
+			writer.append("import " + type.getName() + ";\n");
+		}
         
-        writer.append('\n');
+        writer.append('\n');        
     }
     
     private void generateRequestNames(StringBuffer writer, 
@@ -1168,46 +1033,23 @@
     private List getRemoteExtends(ResourceInspector inspector)
     {
         List types = new ArrayList();
-        types.add(Resource.class);
         
-        Class proxyClass = inspector.getBaseProxyClass();
-        
-        if (proxyClass.equals(NotificationProducerClient.class))
-            types.add(NotificationProducerClient.class);
-        
-        if (proxyClass.equals(NotificationConsumerClient.class))
-            types.add(NotificationConsumerClient.class);
+        //TODO was this needed?
+//        types.add(Resource.class);
+//        
+//        Class proxyClass = inspector.getBaseProxyClass();
+//        
+//        if (proxyClass.equals(NotificationProducerClient.class))
+//            types.add(NotificationProducerClient.class);
+//        
+//        if (proxyClass.equals(NotificationConsumerClient.class))
+//            types.add(NotificationConsumerClient.class);
         
         return types;
     }
-    
-    public File getWorkingDirectory()
-    {
-        return _environment.getRealDirectory();
-    }
-    
-    public boolean isVerbose()
-    {
-        return _isVerbose;
-    }
-    
-    /**
-     * 
-     * Allows users to execute the proxy generator from their own Java 
-     * code rather than running from a command line (via main()).
-     * 
-     * @param wsdlPath 
-     *        The path of the WSDL file to analyze.
-     * 
-     * @param interfaceName
-     *        The desired interface name for the new proxy.
-     * 
-     * @return A Map of Java type names (String) to Java code (String).
-     * 
-     */
-    public Map run(String wsdlPath, String interfaceName)
-    {
-        Document wsdlDoc = WsdlUtils.createWSDL(_environment, wsdlPath, true);
+	
+	public ConfigurationData synthesize(ConfigurationData data) throws Exception {
+        Document wsdlDoc = (Document) data.getParameter(ConfigurationData.WSDL_DOCUMENT);
         Element wsdlDef = XmlUtils.getFirstElement(wsdlDoc);
         
         WsdlUtils.removeSchemaReferences(wsdlDef);
@@ -1215,42 +1057,32 @@
         ResourceInspector inspector = new ResourceInspector();
         inspector.run(wsdlDef, _environment);
         
-        Element rmd = getMetadata(wsdlPath, wsdlDef, inspector);
-        
-        if (rmd != null)
-            inspector.setMetadata(rmd);
-        
-        return generate(interfaceName, inspector);
-    }
+        //TODO later
+//        Element rmd = getMetadata(wsdlPath, wsdlDef, inspector);
         
-    public void setVerbose(boolean isVerbose)
-    {
-        _isVerbose = isVerbose;
-    }
-    
-    public void setWorkingDirectory(File directory)
-    {
-        _environment.setRealDirectory(directory);
-    }
-    
-    public void writeToFile(String javaName, String javaCode)
-        throws IOException
-    {
-        String fileName = javaName.replace('.', '/') + ".java";
-        File javaFile = new File(_environment.getRealDirectory(), fileName);
+//        if (rmd != null)
+//            inspector.setMetadata(rmd);
         
-        File dir = javaFile.getParentFile();
-        dir.mkdirs();
+        String interfaceName = createInterface(wsdlDoc);
         
-        FileWriter writer = new FileWriter(javaFile);
-        writer.write(javaCode);
-        writer.flush();
-        writer.close();
-    }
+        Map files = generate(interfaceName, inspector);
+        
+        ConfigurationData configuration = (ConfigurationData)data.clone();
+        configuration.addParameter(ConfigurationData.FILES_MAP, files);
+        return configuration;
+	}
+	
+	private String createInterface(Document wsdlDocument) {
+		String packageName = 
+			ClassInfo.getPackageName(wsdlDocument.getDocumentElement().getAttribute(TARGET_NS_ATTR));
+		return packageName + "." + SERVICE_NAME;
+	}
+	
+	private String createFileName(String interfaceName) {
+		return interfaceName.replaceAll("\\.", "\\\\") + ".java";	
+	}
 
-	public Map generateFiles(Map capabilities) {
-		// TODO Auto-generated method stub
-//		CounterResourceIdFactory
-		return new HashMap();
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return REQUIRED_PARAMETERS;
 	}
 }

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ServerSynthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ServerSynthesizer.java?rev=433492&r1=433491&r2=433492&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ServerSynthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ServerSynthesizer.java Mon Aug 21 20:49:41 2006
@@ -24,11 +24,12 @@
 import javax.xml.namespace.QName;
 
 import org.apache.muse.core.AbstractCapability;
-import org.apache.muse.tools.generator.Capability;
+import org.apache.muse.tools.generator.util.Capability;
+import org.apache.muse.tools.generator.util.ConfigurationData;
+import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
 import org.apache.muse.tools.inspector.JavaMethod;
 import org.apache.muse.tools.inspector.JavaProperty;
 import org.apache.muse.util.ReflectUtils;
-import org.apache.muse.ws.resource.WsResourceCapability;
 import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
 
 /**
@@ -42,11 +43,23 @@
 public class ServerSynthesizer implements Synthesizer {
 
 	private static final String INDENT = "    ";
+
+	private static final String REQUEST_SUFFIX = "Request";
+	
+	private static final String IMPLEMENTATION_SUFFIX = "Impl";
 	
-	private HashMap _files;
+	protected HashMap _files;
+	
+	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
+		new ConfigurationDataDescriptor[] {
+			ConfigurationData.CAPABILITIES_MAP_CONFIGURATION,
+		};
 
-	public Map generateFiles(Map capabilities) {
-		_files = new HashMap();
+	public ConfigurationData synthesize(ConfigurationData configuration) throws Exception {
+		ConfigurationData.checkConfiguration(this, configuration);
+		
+		Map capabilities = (Map)configuration.getParameter(ConfigurationData.CAPABILITIES_MAP);
+		_files = new HashMap();				
 		
 		for (Iterator i = capabilities.values().iterator(); i.hasNext();) {
 			Capability capability = (Capability)i.next();
@@ -55,17 +68,20 @@
 			}
 		}
 		
-		return _files;
+		ConfigurationData resultData = (ConfigurationData) configuration.clone();
+		resultData.addParameter(ConfigurationData.FILES_MAP, _files);
+		
+		return resultData;
 	}
 	
-	private void generateCapability(Capability capability) {
+	protected void generateCapability(Capability capability) {
 		ClassInfo classInfo = new ClassInfo(capability);
 			
 		makeInterface(classInfo);
 		makeAbstractClass(classInfo);
 	}
 
-	private void makeInterface(ClassInfo classInfo) {
+	protected void makeInterface(ClassInfo classInfo) {
 		StringBuffer code = new StringBuffer();
 		
 		generatePackageHeader(classInfo, code);
@@ -81,7 +97,7 @@
 		
 		generateCloseBlock(code);
 		
-		String className = makeFileName(classInfo, false);
+		String className = makeFileName(classInfo);
 		
 		_files.put(className, code.toString());
 	}
@@ -102,26 +118,23 @@
 		
 		generateCloseBlock(code);
 		
-		String className = makeFileName(classInfo, true);
+		String className = makeFileName(classInfo,IMPLEMENTATION_SUFFIX);
 		
 		_files.put(className, code.toString());
 	}
 
 	private void generateInterfaceDeclaration(ClassInfo classInfo, StringBuffer code) {
-		Capability capability = classInfo.getCapability();
 		code.append("public interface " 
-			+ classInfo.getClassShortName() 
-			+ " extends "
-			+ convertType(getBaseClass(capability, false),classInfo));
+			+ classInfo.getClassShortName());
 		newLine(code);
 	}
 
-	private void generateClassDeclaration(ClassInfo classInfo, StringBuffer code) {
+	protected void generateClassDeclaration(ClassInfo classInfo, StringBuffer code) {
 		Capability capability = classInfo.getCapability();
 		code.append("public class " 
-			+ ReflectUtils.getShortName(capability.getImplementingClass())
+			+ ReflectUtils.getShortName(capability.getImplementingClass() + IMPLEMENTATION_SUFFIX)
 			+ " extends "
-			+ convertType(getBaseClass(capability, true),classInfo));
+			+ convertType(getBaseClass(capability),classInfo));
 		code.append(" implements " + classInfo.getClassShortName());
 		newLine(code);
 	}
@@ -151,7 +164,7 @@
 			code.append("new " 
 				+ convertType(QName.class, classInfo) 
 				+ "(NAMESPACE_URI, \"" 
-				+ getPropertyName(property) 
+				+ getPropertyName(property, false) 
 				+ "\", PREFIX)");
 			if(i.hasNext()) {
 				code.append(",");
@@ -188,17 +201,22 @@
 			code.append("private " 
 				+ convertType(property.getJavaType(), classInfo) 
 				+ " _" 
-				+ getPropertyName(property) 
+				+ getPropertyName(property, false) 
 				+ ";");
 			newLine(2, code);
 		}
 	}
 
-	private String getPropertyName(JavaProperty property) {
-		return property.getName().getLocalPart(); 
+	private String getPropertyName(JavaProperty property, boolean forSetter)  {		
+		String name = property.getName().getLocalPart();
+		if(!forSetter) {
+			return name;
+		}
+		name = name.substring(0,1).toUpperCase() + name.substring(1);
+		return name;
 	}
 
-	private void generateOperations(ClassInfo classInfo, StringBuffer code, boolean generateBody) {
+	protected void generateOperations(ClassInfo classInfo, StringBuffer code, boolean generateBody) {
 		Capability capability = classInfo.getCapability();
 		
 		for(Iterator i=capability.getOperations().iterator(); i.hasNext();) {
@@ -226,7 +244,7 @@
 					+ "param" + j);
 			}
 			
-			code.append(")");
+			code.append(") throws Exception");	
 			
 			if(generateBody) {
 				indent(code);
@@ -263,7 +281,7 @@
 			code.append("public "
 				+ convertType(property.getJavaType(), classInfo)
 				+ " get" 
-				+ getPropertyName(property) 
+				+ getPropertyName(property, true) 
 				+ "()");
 			
 			if(generateBody) {
@@ -274,7 +292,7 @@
 				
 				indent(2,code);
 				statement("return _" 
-					+ getPropertyName(property) 
+					+ getPropertyName(property, false) 
 					+  ";",code);
 				newLine(code);
 				
@@ -288,7 +306,7 @@
 			indent(code);
 			code.append("public void");
 			code.append(" set" 
-				+ getPropertyName(property) 
+				+ getPropertyName(property, true) 
 				+ "(" 
 				+ convertType(property.getJavaType(), classInfo) 
 				+ " param0)");
@@ -301,7 +319,7 @@
 				
 				indent(2,code);
 				statement("_" 
-					+ getPropertyName(property) 
+					+ getPropertyName(property, false) 
 					+ " = param0;",code);				
 				newLine(code);
 				
@@ -325,12 +343,12 @@
 		newLine(2,code);
 	}
 
-	private void generateImports(ClassInfo classInfo, boolean isImpl, StringBuffer code) {
+	protected void generateImports(ClassInfo classInfo, boolean isImpl, StringBuffer code) {
 		Set imports = classInfo.getImports();
 		
-		Class baseClass = getBaseClass(classInfo.getCapability(), isImpl);
+		Class baseClass = getBaseClass(classInfo.getCapability());
 			
-		if(!imports.contains(baseClass)) {
+		if(isImpl && !imports.contains(baseClass)) {
 			generateImport(baseClass, code);
 		}
 		
@@ -356,18 +374,21 @@
 	}
 
 
-	private void generatePackageHeader(ClassInfo classInfo, StringBuffer code) {
+	protected void generatePackageHeader(ClassInfo classInfo, StringBuffer code) {
 		statement("package " + classInfo.getPackageName() + ";",code);
 		newLine(2, code);
 	}
 	
-	private String getMethodName(JavaMethod method) {
+	protected String getMethodName(JavaMethod method) {
 		String name = method.getName().getLocalPart();
 		name = name.substring(0,1).toLowerCase() + name.substring(1);
+		if(name.endsWith(REQUEST_SUFFIX)) {
+			name = name.substring(0, name.indexOf(REQUEST_SUFFIX));
+		}
 		return name;
 	}
 
-	private String needsImport(Class className) {
+	protected String needsImport(Class className) {
 		if(className.isPrimitive()) {
 			return null;
 		}
@@ -380,7 +401,7 @@
 		return className.getName();
  	 }
 	
-	private String convertType(Class returnType, ClassInfo classInfo) {
+	protected String convertType(Class returnType, ClassInfo classInfo) {
 		boolean isArray = returnType.isArray();
 		returnType = isArray?ReflectUtils.getClassFromArrayClass(returnType):returnType;
 		
@@ -391,58 +412,58 @@
         return ReflectUtils.getShortName(returnType);		
 	}
 
-	private Class getBaseClass(Capability capability, boolean isImpl) {
-		if(isImpl) {
-			if(capability.getProperties().size() > 0) {
-				return AbstractWsResourceCapability.class;
-			}
-            return AbstractCapability.class;
+	protected Class getBaseClass(Capability capability) {
+		if(capability.getProperties().size() > 0) {
+			return AbstractWsResourceCapability.class;
 		}
-        if(capability.getProperties().size() > 0) {
-        	return WsResourceCapability.class;
-        }
-        return org.apache.muse.core.Capability.class;
+        return AbstractCapability.class;
 	}
 	
-	private String makeFileName(ClassInfo classInfo, boolean isImpl) {
-		String name = null;
-		if(isImpl) {
-			name = classInfo.getCapability().getImplementingClass();
-		} else {
-			name = classInfo.getClassFullName();
+	protected String makeFileName(ClassInfo classInfo) {
+		return makeFileName(classInfo, null);
+	}
+	
+	protected String makeFileName(ClassInfo classInfo, String implSuffix) {
+		String name = name = classInfo.getClassFullName();
+		if(implSuffix != null) {
+			name += implSuffix;
 		}
 		return name.replaceAll("\\.", "\\\\") + ".java";
 	}
 
-	private void statement(String statement, StringBuffer code) {
+	protected void statement(String statement, StringBuffer code) {
 		code.append(statement);
 	}
 
-	private void newLine(StringBuffer code) {
+	protected void newLine(StringBuffer code) {
 		newLine(1,code);
 	}
 	
-	private void newLine(int n, StringBuffer code) {
+	protected void newLine(int n, StringBuffer code) {
 		for(int i=0; i < n; i++) {
 			code.append("\n");
 		}
 	}
 
-	private void generateCloseBlock(StringBuffer code) {
+	protected void generateCloseBlock(StringBuffer code) {
 		code.append("}");
 	}
 
-	private void generateOpenBlock(StringBuffer code) {
+	protected void generateOpenBlock(StringBuffer code) {
 		code.append("{");
 	}
 
-	private void indent(StringBuffer code) {
+	protected void indent(StringBuffer code) {
 		indent(1,code);
 	}
 	
-	private void indent(int indent, StringBuffer code) {
+	protected void indent(int indent, StringBuffer code) {
 		for(int i=0; i < indent; i++) {
 			code.append(INDENT);
 		}
+	}
+
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return REQUIRED_PARAMETERS;
 	}
 }

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Synthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Synthesizer.java?rev=433492&r1=433491&r2=433492&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Synthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/Synthesizer.java Mon Aug 21 20:49:41 2006
@@ -1,30 +1,28 @@
-/*=============================================================================*
- *  Copyright 2006 The Apache Software Foundation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *=============================================================================*/
-
-package org.apache.muse.tools.generator.synthesizer;
-
-import java.util.Map;
-
-/**
- * Interface for code generators. These classes take a map
- * of capabilities and produce the necessary implementation
- * classes and write them out to disk.
- * 
- * @author Andrew Eberbach 
- */
-public interface Synthesizer  {	
-	Map generateFiles(Map capabilities);
-}
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.tools.generator.synthesizer;
+
+import org.apache.muse.tools.generator.util.Configurable;
+import org.apache.muse.tools.generator.util.ConfigurationData;
+
+/**
+ * 
+ * @author Andrew Eberbach 
+ */
+public interface Synthesizer extends Configurable {	
+	ConfigurationData synthesize(ConfigurationData data) throws Exception;
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org