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 da...@apache.org on 2007/03/24 14:14:24 UTC

svn commit: r522019 [5/12] - in /webservices/muse/trunk/modules: muse-tools/src/org/apache/muse/tools/generator/ muse-tools/src/org/apache/muse/tools/generator/analyzer/ muse-tools/src/org/apache/muse/tools/generator/projectizer/ muse-tools/src/org/apa...

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiMiniProjectizerConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiMiniProjectizerConstants.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiMiniProjectizerConstants.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiMiniProjectizerConstants.java Sat Mar 24 06:14:20 2007
@@ -1,23 +1,27 @@
-/*=============================================================================*
- *  Copyright 2007 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.projectizer;
-
-public interface OsgiMiniProjectizerConstants {
-
-	String[] REQUIRED_MODULES = { "osgi/core", "osgi/ws-fx-api", "osgi/ws-fx-impl", "osgi/mini"};
-
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.projectizer;
+
+public interface OsgiMiniProjectizerConstants {
+
+	String[] REQUIRED_MODULES = { "osgi/core", "osgi/ws-fx-api", "osgi/ws-fx-impl", "osgi/mini"};
+
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiProjectizerConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiProjectizerConstants.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiProjectizerConstants.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/OsgiProjectizerConstants.java Sat Mar 24 06:14:20 2007
@@ -1,62 +1,66 @@
-/*=============================================================================*
- *  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.projectizer;
-
-/**
- * Contains constant values for the <code>OsgiProjectizer</code>.
- * 
- * @author Andrew Eberbach (aeberbac)
- *
- */
-public interface OsgiProjectizerConstants {
-
-	String TEMPLATE_DIR = "lib/eclipse-osgi";	
-	
-	String MUSE_DESCRIPTOR_FILE = "config/muse.xml";
-	
-	String OSGI_MANIFEST_FILE = "config/MANIFEST.MF";
-	
-	String PLUGINS_DIR = "plugins";
-	
-	String JAVA_SRC_DIR = "src";
-	
-	String WSDL_DIR = "wsdl";
-	
-	String RESOURCES_DIR = "/resources/osgi/";
-	
-	String BUILD_FILE = "build.xml";
-	
-	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml";
-	
-	String ACTIVATOR_FILE_RESOURCE = RESOURCES_DIR + "Activator";
-	
-	String OSGI_MANIFEST_FILE_RESOURCE = RESOURCES_DIR + "MANIFEST.MF";
-	
-	String CONFIG_FILE_RESOURCE = RESOURCES_DIR + "config.ini";
-	
-	String CONFIG_FILE = "config/config.ini";
-	
-	String ACTIVATOR_NAME = "Activator";
-	
-	String ROUTER_ENTRIES_DIR = "router-entries";
-
-	String MODULES_DIR = "modules";
-	
-	String LIB_DIR = "lib";
-
-	String[] REQUIRED_LIBS = { "core", "ws-fx-api", "ws-fx-impl"};
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.projectizer;
+
+/**
+ * Contains constant values for the <code>OsgiProjectizer</code>.
+ * 
+ * @author Andrew Eberbach (aeberbac)
+ *
+ */
+public interface OsgiProjectizerConstants {
+
+	String TEMPLATE_DIR = "lib/eclipse-osgi";	
+	
+	String MUSE_DESCRIPTOR_FILE = "config/muse.xml";
+	
+	String OSGI_MANIFEST_FILE = "config/MANIFEST.MF";
+	
+	String PLUGINS_DIR = "plugins";
+	
+	String JAVA_SRC_DIR = "src";
+	
+	String WSDL_DIR = "wsdl";
+	
+	String RESOURCES_DIR = "/resources/osgi/";
+	
+	String BUILD_FILE = "build.xml";
+	
+	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml";
+	
+	String ACTIVATOR_FILE_RESOURCE = RESOURCES_DIR + "Activator";
+	
+	String OSGI_MANIFEST_FILE_RESOURCE = RESOURCES_DIR + "MANIFEST.MF";
+	
+	String CONFIG_FILE_RESOURCE = RESOURCES_DIR + "config.ini";
+	
+	String CONFIG_FILE = "config/config.ini";
+	
+	String ACTIVATOR_NAME = "Activator";
+	
+	String ROUTER_ENTRIES_DIR = "router-entries";
+
+	String MODULES_DIR = "modules";
+	
+	String LIB_DIR = "lib";
+
+	String[] REQUIRED_LIBS = { "core", "ws-fx-api", "ws-fx-impl"};
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Projectizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Projectizer.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Projectizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Projectizer.java Sat Mar 24 06:14:20 2007
@@ -1,34 +1,38 @@
-/*=============================================================================*
- *  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.projectizer;
-
-import org.apache.muse.tools.generator.util.Configurable;
-import org.apache.muse.tools.generator.util.ConfigurationData;
-
-/**
- * 
- * The third phase of code generation that takes the data from
- * previous phases and creates a platform-specific layout on disk.
- * 
- * For example, this phase creates all of the files and descriptors necessary
- * for an Axis2 J2EE project. 
- *
- * @author Andrew Eberbach (aeberbac)
- */
-public interface Projectizer extends Configurable {	
-	void projectize(ConfigurationData data) throws Exception;
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.projectizer;
+
+import org.apache.muse.tools.generator.util.Configurable;
+import org.apache.muse.tools.generator.util.ConfigurationData;
+
+/**
+ * 
+ * The third phase of code generation that takes the data from
+ * previous phases and creates a platform-specific layout on disk.
+ * 
+ * For example, this phase creates all of the files and descriptors necessary
+ * for an Axis2 J2EE project. 
+ *
+ * @author Andrew Eberbach (aeberbac)
+ */
+public interface Projectizer extends Configurable {	
+	void projectize(ConfigurationData data) throws Exception;
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizer.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizer.java Sat Mar 24 06:14:20 2007
@@ -1,88 +1,92 @@
-/*=============================================================================*
- *  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.projectizer;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Map;
-
-import org.apache.muse.tools.generator.util.ConfigurationData;
-import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
-import org.apache.muse.util.FileUtils;
-
-/**
- * Creates a simple java project that is necessary for 
- * compiling a proxy.
- * 
- * @author Andrew Eberbach (aeberbac)
- */
-public class ProxyProjectizer extends AbstractProjectizer {
-
-	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
-		new ConfigurationDataDescriptor[] {
-			ConfigurationData.FILES_MAP_LIST_CONFIGURATION,
-			ConfigurationData.OVERWRITE_CONFIGURATION
-		};
-	
-	protected Map[] _filesMaps;
-
-	public void projectize(ConfigurationData configuration) throws Exception {
-		ConfigurationData.checkConfiguration(this, configuration);
-		
-		loadParameters(configuration);
-		
-		File javaSourceDir = new File(
-				_targetDirectory, 
-				ProxyProjectizerConstants.JAVA_SRC_DIR);
-		
-		createDirectoryStructure();
-		createJavaSources(javaSourceDir, _filesMaps);
-		createArtifacts();	
-		
-		createOverwriteManifest();
-	}
-
-	protected void createArtifacts() throws Exception {
-		createBuildFile(_targetDirectory, ProxyProjectizerConstants.BUILD_FILE_RESOURCE, ProxyProjectizerConstants.BUILD_FILE);
-	}
-
-	protected void createDirectoryStructure() throws Exception {
-		File libDir = new File(_targetDirectory, ProxyProjectizerConstants.LIB_DIR);
-		File modulesDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),Axis2ProjectizerConstants.MODULES_DIR);
-		File museLibDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),Axis2ProjectizerConstants.MUSE_LIB_DIR);
-		copyJars(ProxyProjectizerConstants.REQUIRED_MODULES, modulesDir, libDir);
-		copyJars(ProxyProjectizerConstants.REQUIRED_MUSE_LIBS, museLibDir, libDir);
-	}
-
-	protected void loadParameters(ConfigurationData configuration) {
-		_filesMaps = (Map[])configuration.getParameter(ConfigurationData.FILES_MAP_LIST);
-		_targetDirectory = (File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY);
-		
-		boolean overwrite = ((Boolean)configuration.getParameter(ConfigurationData.OVERWRITE)).booleanValue();
-		setTargetDirectory((File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY), overwrite);
-	}
-	
-	protected void createBuildFile(File baseTargetDir, String buildFileResource, String buildFile) throws Exception {
-		InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),buildFileResource);
-		File build = new File(baseTargetDir, buildFile);
-		copyStreamCheck(buildTemplate, build);			
-	}
-
-	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
-		return REQUIRED_PARAMETERS;
-	}
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.projectizer;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.muse.tools.generator.util.ConfigurationData;
+import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
+import org.apache.muse.util.FileUtils;
+
+/**
+ * Creates a simple java project that is necessary for 
+ * compiling a proxy.
+ * 
+ * @author Andrew Eberbach (aeberbac)
+ */
+public class ProxyProjectizer extends AbstractProjectizer {
+
+	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
+		new ConfigurationDataDescriptor[] {
+			ConfigurationData.FILES_MAP_LIST_CONFIGURATION,
+			ConfigurationData.OVERWRITE_CONFIGURATION
+		};
+	
+	protected Map[] _filesMaps;
+
+	public void projectize(ConfigurationData configuration) throws Exception {
+		ConfigurationData.checkConfiguration(this, configuration);
+		
+		loadParameters(configuration);
+		
+		File javaSourceDir = new File(
+				_targetDirectory, 
+				ProxyProjectizerConstants.JAVA_SRC_DIR);
+		
+		createDirectoryStructure();
+		createJavaSources(javaSourceDir, _filesMaps);
+		createArtifacts();	
+		
+		createOverwriteManifest();
+	}
+
+	protected void createArtifacts() throws Exception {
+		createBuildFile(_targetDirectory, ProxyProjectizerConstants.BUILD_FILE_RESOURCE, ProxyProjectizerConstants.BUILD_FILE);
+	}
+
+	protected void createDirectoryStructure() throws Exception {
+		File libDir = new File(_targetDirectory, ProxyProjectizerConstants.LIB_DIR);
+		File modulesDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),Axis2ProjectizerConstants.MODULES_DIR);
+		File museLibDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),Axis2ProjectizerConstants.MUSE_LIB_DIR);
+		copyJars(ProxyProjectizerConstants.REQUIRED_MODULES, modulesDir, libDir);
+		copyJars(ProxyProjectizerConstants.REQUIRED_MUSE_LIBS, museLibDir, libDir);
+	}
+
+	protected void loadParameters(ConfigurationData configuration) {
+		_filesMaps = (Map[])configuration.getParameter(ConfigurationData.FILES_MAP_LIST);
+		_targetDirectory = (File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY);
+		
+		boolean overwrite = ((Boolean)configuration.getParameter(ConfigurationData.OVERWRITE)).booleanValue();
+		setTargetDirectory((File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY), overwrite);
+	}
+	
+	protected void createBuildFile(File baseTargetDir, String buildFileResource, String buildFile) throws Exception {
+		InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),buildFileResource);
+		File build = new File(baseTargetDir, buildFile);
+		copyStreamCheck(buildTemplate, build);			
+	}
+
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return REQUIRED_PARAMETERS;
+	}
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizerConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizerConstants.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizerConstants.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProxyProjectizerConstants.java Sat Mar 24 06:14:20 2007
@@ -1,40 +1,44 @@
-/*=============================================================================*
- *  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.projectizer;
-
-/**
- * Contains constant values for the <code>ProxyProjectizer</code>.
- * 
- * @author Andrew Eberbach (aeberbac)
- */
-public interface ProxyProjectizerConstants {
-
-	String[] REQUIRED_MODULES = { "core", "ws-fx-api", "ws-fx-impl"};
-	
-	String JAVA_SRC_DIR = "src";
-
-	String BUILD_FILE = "build.xml";
-
-	String RESOURCES_DIR = "/resources/proxy/";
-
-	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml";
-
-	String LIB_DIR = "lib";
-
-	String[] REQUIRED_MUSE_LIBS = { "common" };
-
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.projectizer;
+
+/**
+ * Contains constant values for the <code>ProxyProjectizer</code>.
+ * 
+ * @author Andrew Eberbach (aeberbac)
+ */
+public interface ProxyProjectizerConstants {
+
+	String[] REQUIRED_MODULES = { "core", "ws-fx-api", "ws-fx-impl"};
+	
+	String JAVA_SRC_DIR = "src";
+
+	String BUILD_FILE = "build.xml";
+
+	String RESOURCES_DIR = "/resources/proxy/";
+
+	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml";
+
+	String LIB_DIR = "lib";
+
+	String[] REQUIRED_MUSE_LIBS = { "common" };
+
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AbstractSynthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AbstractSynthesizer.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AbstractSynthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/AbstractSynthesizer.java Sat Mar 24 06:14:20 2007
@@ -1,343 +1,347 @@
-/*=============================================================================*
- *  Copyright 2007 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.io.File;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-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;
-
-public abstract class AbstractSynthesizer implements Synthesizer {
-	static final String INDENT = "    ";
-
-	static final String REQUEST_SUFFIX = "Request";
-	
-	private static final String JAVA_CLASS_NAME = "MyCapability";
-
-	static final String INTERFACE_PREFIX = "I";
-	
-	private int _prefixCounter = 0;
-
-	private HashMap _prefixes = new HashMap();
-
-	protected String createFileName(String interfaceName) {
-		return interfaceName.replaceAll("\\.", "\\" + File.separator) + ".java";
-	}
-
-	protected String generateClassName(Capability capability) {
-		return generateClassName(null, capability);
-	}
-
-	protected String generateClassName(String prefix, Capability capability) {
-		String implementingClass = capability.getImplementingClass();
-		
-		String packageName = null;
-		String shortClassName = null;
-		
-		if(implementingClass == null) {
-			packageName = ClassInfo.getPackageName(capability.getURI());
-			shortClassName = JAVA_CLASS_NAME;
-		} else {
-			packageName = ReflectUtils.getPackageName(implementingClass);
-			shortClassName = ReflectUtils.getShortName(implementingClass);
-		}
-		
-		if(prefix != null) {
-			shortClassName = prefix + shortClassName;
-		}
-		
-		return packageName + "." + shortClassName;
-	}
-	
-	protected String getMethodName(JavaMethod method) {
-		String name = method.getJavaName();
-		if (name.endsWith(REQUEST_SUFFIX)) {
-			name = name.substring(0, name.indexOf(REQUEST_SUFFIX));
-		}
-		return name;
-	}
-	
-	protected void generateClassDef(String remoteClassName, boolean isInterface, StringBuffer code) {
-		generateClassDef(remoteClassName, null, null, isInterface, code);
-	}
-	
-	protected void generateClassDef(String remoteClassName, String extendsClass, String[] implementsClasses ,boolean isInterface, StringBuffer code) {
-		code.append("public ");
-		code.append(isInterface?"interface":"class");
-		code.append(" ");
-		code.append(ReflectUtils.getShortName(remoteClassName));
-		
-		if(extendsClass != null) {
-			code.append(" extends " + extendsClass);			
-		}
-		
-		if(implementsClasses != null && implementsClasses.length > 0) {
-			code.append(" implements ");
-			code.append(implementsClasses[0]);
-			
-			for(int i=1; i < implementsClasses.length; i++) {				
-				code.append(", " + implementsClasses[i]);				
-			}
-		}
-		
-		newLine(code);
-		generateOpenBlock(code);
-		newLine(code);
-	}
-	
-	protected void generateImports(ClassInfo classInfo, StringBuffer code) {
-		Iterator i = classInfo.getImports().iterator();
-
-		while (i.hasNext()) {
-			String className = needsImport((Class) i.next());
-			if (className != null) {
-				statement("import " + className + ";", code);
-				newLine(code);
-			}
-		}
-
-		newLine(code);
-	}
-
-	protected String needsImport(Class className) {
-		if (className.isPrimitive()) {
-			return null;
-		}
-		if (className.isArray()) {
-			className = ReflectUtils.getClassFromArrayClass(className);
-		}
-		if (className.getName().startsWith("java.lang.")) {
-			return null;
-		}
-		return className.getName();
-	}
-
-	protected String convertType(Class returnType, ClassInfo classInfo) {
-		boolean isArray = returnType.isArray();
-
-		returnType = isArray ? ReflectUtils.getClassFromArrayClass(returnType)
-				: returnType;
-
-		// Use fully-qualified name if conflict exists
-		if (classInfo.hasConflict(returnType)) {
-			return returnType.getName();
-		}
-		return ReflectUtils.getShortName(returnType) + (isArray ? "[]" : "");
-	}
-
-	protected 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;
-	}
-
-	protected String getParamName(QName paramName, int position) {
-		String name;
-
-		if (paramName == null) {
-			name = "param" + position;
-		} else {
-			name = paramName.getLocalPart();
-		}
-
-		return name;
-	}
-
-	protected void statement(String statement, StringBuffer code) {
-		code.append(statement);
-	}
-
-	protected void generateHeaderComment(String className, StringBuffer code) {
-		String shortName = ReflectUtils.getShortName(className);
-		String fileName = shortName + ".java";
-
-		comment(code);
-		newLine(code);
-
-		comment(fileName, code);
-		newLine(code);
-
-		comment(new Date().toString(), code);
-		newLine(code);
-
-		comment("Generated by the Apache Muse Code Generation Tool", code);
-		newLine(code);
-
-		comment(code);
-		newLine(code);
-	}
-	
-	protected void generatePackage(String className, StringBuffer code) {
-		String packageName = ReflectUtils.getPackageName(className);
-
-		if (packageName != null) {
-			statement("package " + packageName + ";", code);
-			newLine(2, code);
-		}
-
-	}
-
-	protected void comment(StringBuffer code) {
-		comment("", code);
-	}
-
-	protected void comment(String comment, StringBuffer code) {
-		code.append("// " + comment);
-	}
-
-	protected void newLine(StringBuffer code) {
-		newLine(1, code);
-	}
-
-	protected void newLine(int n, StringBuffer code) {
-		for (int i = 0; i < n; i++) {
-			code.append("\n");
-		}
-	}
-
-	protected void generateCloseBlock(StringBuffer code) {
-		code.append("}");
-	}
-
-	protected void generateOpenBlock(StringBuffer code) {
-		code.append("{");
-	}
-
-	protected void indent(StringBuffer code) {
-		indent(1, code);
-	}
-
-	protected void indent(int indent, StringBuffer code) {
-		for (int i = 0; i < indent; i++) {
-			code.append(INDENT);
-		}
-	}
-
-	protected String getObjectName(String name, Class type) {
-		if (!type.isPrimitive())
-			return name;
-
-		else if (type == boolean.class)
-			return "new Boolean(" + name + ')';
-
-		else if (type == double.class)
-			return "new Double(" + name + ')';
-
-		else if (type == float.class)
-			return "new Float(" + name + ')';
-
-		else if (type == int.class)
-			return "new Integer(" + name + ')';
-
-		else if (type == long.class)
-			return "new Long(" + name + ')';
-
-		return "new Short(" + name + ')';
-	}
-
-	protected String getPrimitiveClassName(Class type) {
-		if (type == boolean.class)
-			return "Boolean";
-
-		else if (type == float.class || type == double.class)
-			return "Float";
-
-		return "Integer";
-	}
-
-	protected String getPrimitiveConvertMethodName(String type) {
-		if (type.endsWith("Boolean"))
-			return "booleanValue";
-
-		else if (type.endsWith("Float") || type.endsWith("Double"))
-			return "floatValue";
-
-		return "intValue";
-	}
-
-	protected String getArrayValue(Class type) {
-		if (!type.isPrimitive())
-			return "value";
-
-		if (type == boolean.class)
-			return "Boolean.toString(value)";
-
-		else if (type == float.class || type == double.class)
-			return "Double.toString(value)";
-
-		return "Long.toString(value)";
-	}
-
-	protected String getNullValue(Class type) {
-		if (!type.isPrimitive())
-			return "null";
-
-		if (type == boolean.class)
-			return "false";
-
-		return "0";
-	}
-	
-	protected void generateQName(QName qname, StringBuffer code) {
-		generateQName(qname.getNamespaceURI(), qname.getLocalPart(), code);
-	}
-
-	protected void generateQName(String uri, String name, StringBuffer code) {
-		code.append("new QName(\"");
-
-		if (uri != null && uri.length() > 0) {
-			code.append(uri);
-			code.append("\", \"");
-		}
-
-		code.append(name);
-		code.append("\", \"");
-
-		code.append(getPrefix(uri));
-		code.append("\")");
-	}
-
-	protected String getPrefix(String uri) {
-		String prefix = (String) _prefixes.get(uri);
-
-		if (prefix == null) {
-			prefix = "pfx" + _prefixCounter++;
-			_prefixes.put(uri, prefix);
-		}
-
-		return prefix;
-	}
-	
-	protected StringBuffer beginHeaderCode(String className) {
-		StringBuffer code = new StringBuffer();
-		
-		generateHeaderComment(className, code);
-		generatePackage(className, code);
-
-		return code;
-	}
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.io.File;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+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;
+
+public abstract class AbstractSynthesizer implements Synthesizer {
+	static final String INDENT = "    ";
+
+	static final String REQUEST_SUFFIX = "Request";
+	
+	private static final String JAVA_CLASS_NAME = "MyCapability";
+
+	static final String INTERFACE_PREFIX = "I";
+	
+	private int _prefixCounter = 0;
+
+	private HashMap _prefixes = new HashMap();
+
+	protected String createFileName(String interfaceName) {
+		return interfaceName.replaceAll("\\.", "\\" + File.separator) + ".java";
+	}
+
+	protected String generateClassName(Capability capability) {
+		return generateClassName(null, capability);
+	}
+
+	protected String generateClassName(String prefix, Capability capability) {
+		String implementingClass = capability.getImplementingClass();
+		
+		String packageName = null;
+		String shortClassName = null;
+		
+		if(implementingClass == null) {
+			packageName = ClassInfo.getPackageName(capability.getURI());
+			shortClassName = JAVA_CLASS_NAME;
+		} else {
+			packageName = ReflectUtils.getPackageName(implementingClass);
+			shortClassName = ReflectUtils.getShortName(implementingClass);
+		}
+		
+		if(prefix != null) {
+			shortClassName = prefix + shortClassName;
+		}
+		
+		return packageName + "." + shortClassName;
+	}
+	
+	protected String getMethodName(JavaMethod method) {
+		String name = method.getJavaName();
+		if (name.endsWith(REQUEST_SUFFIX)) {
+			name = name.substring(0, name.indexOf(REQUEST_SUFFIX));
+		}
+		return name;
+	}
+	
+	protected void generateClassDef(String remoteClassName, boolean isInterface, StringBuffer code) {
+		generateClassDef(remoteClassName, null, null, isInterface, code);
+	}
+	
+	protected void generateClassDef(String remoteClassName, String extendsClass, String[] implementsClasses ,boolean isInterface, StringBuffer code) {
+		code.append("public ");
+		code.append(isInterface?"interface":"class");
+		code.append(" ");
+		code.append(ReflectUtils.getShortName(remoteClassName));
+		
+		if(extendsClass != null) {
+			code.append(" extends " + extendsClass);			
+		}
+		
+		if(implementsClasses != null && implementsClasses.length > 0) {
+			code.append(" implements ");
+			code.append(implementsClasses[0]);
+			
+			for(int i=1; i < implementsClasses.length; i++) {				
+				code.append(", " + implementsClasses[i]);				
+			}
+		}
+		
+		newLine(code);
+		generateOpenBlock(code);
+		newLine(code);
+	}
+	
+	protected void generateImports(ClassInfo classInfo, StringBuffer code) {
+		Iterator i = classInfo.getImports().iterator();
+
+		while (i.hasNext()) {
+			String className = needsImport((Class) i.next());
+			if (className != null) {
+				statement("import " + className + ";", code);
+				newLine(code);
+			}
+		}
+
+		newLine(code);
+	}
+
+	protected String needsImport(Class className) {
+		if (className.isPrimitive()) {
+			return null;
+		}
+		if (className.isArray()) {
+			className = ReflectUtils.getClassFromArrayClass(className);
+		}
+		if (className.getName().startsWith("java.lang.")) {
+			return null;
+		}
+		return className.getName();
+	}
+
+	protected String convertType(Class returnType, ClassInfo classInfo) {
+		boolean isArray = returnType.isArray();
+
+		returnType = isArray ? ReflectUtils.getClassFromArrayClass(returnType)
+				: returnType;
+
+		// Use fully-qualified name if conflict exists
+		if (classInfo.hasConflict(returnType)) {
+			return returnType.getName();
+		}
+		return ReflectUtils.getShortName(returnType) + (isArray ? "[]" : "");
+	}
+
+	protected 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;
+	}
+
+	protected String getParamName(QName paramName, int position) {
+		String name;
+
+		if (paramName == null) {
+			name = "param" + position;
+		} else {
+			name = paramName.getLocalPart();
+		}
+
+		return name;
+	}
+
+	protected void statement(String statement, StringBuffer code) {
+		code.append(statement);
+	}
+
+	protected void generateHeaderComment(String className, StringBuffer code) {
+		String shortName = ReflectUtils.getShortName(className);
+		String fileName = shortName + ".java";
+
+		comment(code);
+		newLine(code);
+
+		comment(fileName, code);
+		newLine(code);
+
+		comment(new Date().toString(), code);
+		newLine(code);
+
+		comment("Generated by the Apache Muse Code Generation Tool", code);
+		newLine(code);
+
+		comment(code);
+		newLine(code);
+	}
+	
+	protected void generatePackage(String className, StringBuffer code) {
+		String packageName = ReflectUtils.getPackageName(className);
+
+		if (packageName != null) {
+			statement("package " + packageName + ";", code);
+			newLine(2, code);
+		}
+
+	}
+
+	protected void comment(StringBuffer code) {
+		comment("", code);
+	}
+
+	protected void comment(String comment, StringBuffer code) {
+		code.append("// " + comment);
+	}
+
+	protected void newLine(StringBuffer code) {
+		newLine(1, code);
+	}
+
+	protected void newLine(int n, StringBuffer code) {
+		for (int i = 0; i < n; i++) {
+			code.append("\n");
+		}
+	}
+
+	protected void generateCloseBlock(StringBuffer code) {
+		code.append("}");
+	}
+
+	protected void generateOpenBlock(StringBuffer code) {
+		code.append("{");
+	}
+
+	protected void indent(StringBuffer code) {
+		indent(1, code);
+	}
+
+	protected void indent(int indent, StringBuffer code) {
+		for (int i = 0; i < indent; i++) {
+			code.append(INDENT);
+		}
+	}
+
+	protected String getObjectName(String name, Class type) {
+		if (!type.isPrimitive())
+			return name;
+
+		else if (type == boolean.class)
+			return "new Boolean(" + name + ')';
+
+		else if (type == double.class)
+			return "new Double(" + name + ')';
+
+		else if (type == float.class)
+			return "new Float(" + name + ')';
+
+		else if (type == int.class)
+			return "new Integer(" + name + ')';
+
+		else if (type == long.class)
+			return "new Long(" + name + ')';
+
+		return "new Short(" + name + ')';
+	}
+
+	protected String getPrimitiveClassName(Class type) {
+		if (type == boolean.class)
+			return "Boolean";
+
+		else if (type == float.class || type == double.class)
+			return "Float";
+
+		return "Integer";
+	}
+
+	protected String getPrimitiveConvertMethodName(String type) {
+		if (type.endsWith("Boolean"))
+			return "booleanValue";
+
+		else if (type.endsWith("Float") || type.endsWith("Double"))
+			return "floatValue";
+
+		return "intValue";
+	}
+
+	protected String getArrayValue(Class type) {
+		if (!type.isPrimitive())
+			return "value";
+
+		if (type == boolean.class)
+			return "Boolean.toString(value)";
+
+		else if (type == float.class || type == double.class)
+			return "Double.toString(value)";
+
+		return "Long.toString(value)";
+	}
+
+	protected String getNullValue(Class type) {
+		if (!type.isPrimitive())
+			return "null";
+
+		if (type == boolean.class)
+			return "false";
+
+		return "0";
+	}
+	
+	protected void generateQName(QName qname, StringBuffer code) {
+		generateQName(qname.getNamespaceURI(), qname.getLocalPart(), code);
+	}
+
+	protected void generateQName(String uri, String name, StringBuffer code) {
+		code.append("new QName(\"");
+
+		if (uri != null && uri.length() > 0) {
+			code.append(uri);
+			code.append("\", \"");
+		}
+
+		code.append(name);
+		code.append("\", \"");
+
+		code.append(getPrefix(uri));
+		code.append("\")");
+	}
+
+	protected String getPrefix(String uri) {
+		String prefix = (String) _prefixes.get(uri);
+
+		if (prefix == null) {
+			prefix = "pfx" + _prefixCounter++;
+			_prefixes.put(uri, prefix);
+		}
+
+		return prefix;
+	}
+	
+	protected StringBuffer beginHeaderCode(String className) {
+		StringBuffer code = new StringBuffer();
+		
+		generateHeaderComment(className, code);
+		generatePackage(className, code);
+
+		return code;
+	}
+}

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?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- 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 Sat Mar 24 06:14:20 2007
@@ -1,154 +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.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;
-
-/**
- * Wraps a <code>Capability</code> during the synthesis phase
- * to keep track of imports that are needed for the implementations
- * and the names of the implementing classes. 
- *
- * @author Andrew Eberbach (aeberbac)
- */
-public class ClassInfo {
-
-	Capability _capability = null;
-	
-	Set _imports = new HashSet();
-
-	Map _conflicts = new HashMap();
-
-	public ClassInfo(Capability capability) {			
-		_capability = capability;		
-		findImports();
-	}
-
-	public ClassInfo() {
-		// do nothing
-	}
-
-	public void setCapability(Capability capability) {
-		_capability = capability;		
-		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 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; i++) {
-				if (fileParts[i].matches("^[^a-zA-Z_].*$")) {
-					fileParts[i] = "_" + fileParts[i];
-				}
-				if (fileParts[i].length() != 0) {
-					result += fileParts[i] + ((i != 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;
-	}
-
-	public boolean needsInitializer() {
-		for(Iterator i = _capability.getProperties().iterator(); i.hasNext(); ) {
-			JavaProperty next = (JavaProperty)i.next();
-			if(!next.getJavaType().isPrimitive()) {
-				return true;
-			}
-		}
-		
-		return _capability.isEmpty();
-	}
-
-	public void addImports(Set set) {
-		for(Iterator i=set.iterator(); i.hasNext(); ) {
-			addImport((Class) i.next());
-		}
-	}
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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;
+
+/**
+ * Wraps a <code>Capability</code> during the synthesis phase
+ * to keep track of imports that are needed for the implementations
+ * and the names of the implementing classes. 
+ *
+ * @author Andrew Eberbach (aeberbac)
+ */
+public class ClassInfo {
+
+	Capability _capability = null;
+	
+	Set _imports = new HashSet();
+
+	Map _conflicts = new HashMap();
+
+	public ClassInfo(Capability capability) {			
+		_capability = capability;		
+		findImports();
+	}
+
+	public ClassInfo() {
+		// do nothing
+	}
+
+	public void setCapability(Capability capability) {
+		_capability = capability;		
+		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 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; i++) {
+				if (fileParts[i].matches("^[^a-zA-Z_].*$")) {
+					fileParts[i] = "_" + fileParts[i];
+				}
+				if (fileParts[i].length() != 0) {
+					result += fileParts[i] + ((i != 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;
+	}
+
+	public boolean needsInitializer() {
+		for(Iterator i = _capability.getProperties().iterator(); i.hasNext(); ) {
+			JavaProperty next = (JavaProperty)i.next();
+			if(!next.getJavaType().isPrimitive()) {
+				return true;
+			}
+		}
+		
+		return _capability.isEmpty();
+	}
+
+	public void addImports(Set set) {
+		for(Iterator i=set.iterator(); i.hasNext(); ) {
+			addImport((Class) i.next());
+		}
+	}
+}

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxyClassSynthesizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxyClassSynthesizer.java?view=diff&rev=522019&r1=522018&r2=522019
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxyClassSynthesizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/synthesizer/ProxyClassSynthesizer.java Sat Mar 24 06:14:20 2007
@@ -1,640 +1,644 @@
-/*=============================================================================*
- *  Copyright 2007 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.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import org.apache.muse.core.proxy.ProxyHandler;
-import org.apache.muse.core.proxy.ReflectionProxyHandler;
-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.tools.inspector.ResourceInspector;
-import org.apache.muse.util.ReflectUtils;
-import org.apache.muse.util.xml.XsdUtils;
-import org.w3c.dom.Document;
-
-public class ProxyClassSynthesizer extends ProxyInterfaceSynthesizer {
-	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
-		new ConfigurationDataDescriptor[] {
-			ConfigurationData.CAPABILITIES_MAP_LIST_CONFIGURATION,
-			ConfigurationData.GENERATE_CUSTOM_HEADERS_CONFIGURATION,
-			ConfigurationData.WSDL_DOCUMENT_LIST_CONFIGURATION
-		};
-	
-	StringBuffer _operationNamesCode;
-	StringBuffer _returnTypesCode;
-	StringBuffer _actionsCode;
-	
-	StringBuffer _requestNamesCode;
-	StringBuffer _responseNamesCode;
-	StringBuffer _requestParamNamesCode;
-	
-	StringBuffer _propertiesOperationsCode;
-	private String _interfaceName;
-
-	private boolean _hasMethods = false;
-	private boolean _hasProperties = false;
-	
-	protected String generateClassName(Document wsdlDocument) {
-		_interfaceName = super.generateClassName(wsdlDocument);
-		return _interfaceName + "Proxy";
-	}
-
-	protected void initializeCode(String className) {
-		_importSet = new HashSet();
-		addImport(_baseClientClass);
-		
-        _className = className;
-		_headerCode = beginHeaderCode(_className);
-        _operationsCode = beginOperationsCode();
-        
-        _operationNamesCode = beginOperationNamesCode();
-        _returnTypesCode = beginReturnTypesCode();
-        _actionsCode = beginActionsCode();
-        
-        _requestNamesCode = beginRequestNamesCode();
-        _responseNamesCode = beginResponseNamesCode();
-        _requestParamNamesCode = beginRequestParamNamesCode();
-        
-        resetIndex();
-	}
-	
-	private StringBuffer beginRequestParamNamesCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final QName[][] _REQUEST_PARAM_NAMES = {");
-		newLine(code);
-		_importSet.add(QName.class);
-		return code;
-	}
-
-	private StringBuffer beginResponseNamesCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final QName[] _RESPONSE_NAMES = {");
-		newLine(code);
-		indent(2,code);
-		_importSet.add(QName.class);
-		return code;
-	}
-
-	private StringBuffer beginRequestNamesCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final QName[] _REQUEST_NAMES = {");
-		newLine(code);
-		indent(2,code);
-		_importSet.add(QName.class);
-		return code;
-	}
-
-	private StringBuffer beginActionsCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final String[] _ACTIONS = {");
-		newLine(code);
-		indent(2,code);
-		return code;
-	}
-
-	private StringBuffer beginReturnTypesCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final Class[] _RETURN_TYPES = {");
-		newLine(code);
-		indent(2,code);
-		return code;
-	}
-
-	private StringBuffer beginOperationsCode() {
-		return new StringBuffer();
-	}
-
-	private StringBuffer beginOperationNamesCode() {
-		StringBuffer code = new StringBuffer();
-		
-		indent(code);
-		code.append("private static final String[] _METHOD_NAMES = {");
-		newLine(code);
-		indent(2,code);
-		return code;
-	}
-	
-	protected void updateCode(ClassInfo classInfo) {
-		updateMethods(classInfo, _operationsCode);		
-		classInfo.addImports(_importSet);
-	}
-	
-	protected void generateMethodQualifier(StringBuffer code) {
-		code.append("public ");
-	}
-	
-	protected void generateMethodBody(JavaMethod method, ClassInfo classInfo, StringBuffer code) {
-		_hasMethods = true;
-		
-		newLine(code);
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-
-		generateParamConversion(method, code);
-		generateHandler(method, classInfo, code);
-		generateInvoke(method, code);
-
-		indent(code);
-		generateCloseBlock(code);
-		
-		updateMethodNames(method);
-		updateReturnTypes(method);
-		updateActions(method);
-		
-		updateRequestNames(method);
-		updateResponseNames(method);
-		updateRequestParamNamesCode(method);
-	}
-	
-	private void generateParamConversion(JavaMethod operation, StringBuffer code) {
-		QName[] paramNames = operation.getParameterTypeNames();
-		Class[] paramTypes = operation.getParameterTypes();
-
-		indent(2, code);
-		code.append("Object[] params = new Object[");
-		code.append(paramTypes.length);
-		code.append("];");
-		newLine(code);
-
-		if (paramTypes.length > 0)
-			newLine(code);
-
-		for (int n = 0; n < paramTypes.length; ++n) {
-			indent(2, code);
-			code.append("params[");
-			code.append(n);
-			code.append("] = ");
-
-			String name = ResourceInspector.getLowerCamelName(paramNames[n]
-					.getLocalPart());
-			code.append(getObjectName(name, paramTypes[n]));
-			code.append(";");
-			newLine(code);
-		}
-
-		newLine(code);
-	}
-
-	private void generateHandler(JavaMethod method, ClassInfo classInfo, StringBuffer code) {
-		indent(2, code);
-		code.append("ProxyHandler handler = getHandler(\"");
-		code.append(method.getJavaName());
-		code.append("\");");
-		newLine(code);
-		
-		classInfo.addImport(ProxyHandler.class);
-	}
-	
-	private void generateInvoke(JavaMethod method, StringBuffer code) {
-		indent(2, code);
-
-		Class returnType = method.getReturnType();
-
-		if (returnType == void.class) {
-			code.append(getInvokeString() + ";");
-		}
-		else if (!returnType.isPrimitive()) {
-			code.append("return (");
-			code.append(ReflectUtils.getShortName(returnType));
-			code.append(")" + getInvokeString() + ";");
-			
-		} else {
-			String className = getPrimitiveClassName(returnType);
-			String convertMethodName = getPrimitiveConvertMethodName(className);
-
-			code.append(className);
-			code.append(" result = (");
-			code.append(className);
-			code.append(")" + getInvokeString() + ";");
-			newLine(code);
-
-			indent(2, code);
-			code.append("return result.");
-			code.append(convertMethodName);
-			code.append("();");
-		}
-		
-		newLine(code);
-	}
-	
-	private String getInvokeString() {
-		if(_generateCustomHeaders) {
-			return "invoke(handler, params, customHeaders)";
-		}
-
-		return "invoke(handler, params)";
-	}
-
-	private void updateRequestParamNamesCode(JavaMethod method) {
-		QName[] names = method.getParameterTypeNames();
-		
-		indent(2, _requestParamNamesCode);
-		generateOpenBlock(_requestParamNamesCode);
-		newLine(_requestParamNamesCode);
-		
-		for(int i=0; i < names.length; i++) {
-			indent(3, _requestParamNamesCode);
-			generateQName(names[i], _requestParamNamesCode);
-			_requestParamNamesCode.append(",");
-			newLine(_requestParamNamesCode);
-		}
-				
-		if(names.length > 0) {
-			int length = _requestParamNamesCode.length();
-			_requestParamNamesCode.delete(length - 2, length);
-		}
-		
-		newLine(_requestParamNamesCode);
-		indent(2, _requestParamNamesCode);
-		generateCloseBlock(_requestParamNamesCode);
-		_requestParamNamesCode.append(",");
-		newLine(_requestParamNamesCode);
-	}
-
-	private void updateResponseNames(JavaMethod method) {
-		QName returnName = method.getReturnName();
-		if (returnName != null && !returnName.equals(XsdUtils.ANY_TYPE_QNAME))
-			generateQName(returnName, _responseNamesCode);
-        
-        else
-        	_responseNamesCode.append("null");
-		
-		_responseNamesCode.append(", ");
-	}
-
-	private void updateRequestNames(JavaMethod method) {
-		QName returnName = method.getName();
-		if (returnName != null && !returnName.equals(XsdUtils.ANY_TYPE_QNAME))
-			generateQName(returnName, _requestNamesCode);
-        
-        else
-        	_requestNamesCode.append("null");
-		
-		_requestNamesCode.append(", ");
-	}
-	
-	private void updateMethodNames(JavaMethod method) {
-		_operationNamesCode.append('"');
-		_operationNamesCode.append(method.getJavaName());
-		_operationNamesCode.append('"');
-		_operationNamesCode.append(", ");
-	}
-	
-	private void updateReturnTypes(JavaMethod method) {
-		Class type = method.getReturnType();
-		
-		if(type.isArray()) {
-			type = ReflectUtils.getClassFromArrayClass(type);
-		}
-		
-		_returnTypesCode.append(ReflectUtils.getShortName(type));
-		_returnTypesCode.append(".class");
-		_returnTypesCode.append(", ");
-	}
-	
-	private void updateActions(JavaMethod method) {
-		_actionsCode.append('"');
-		_actionsCode.append(method.getActionURI());
-		_actionsCode.append('"');
-		_actionsCode.append(", ");
-	}
-
-	protected void generatePropertyDeleteBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, StringBuffer code) {		
-		_hasProperties = true;
-		
-		newLine(code);
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-
-		indent(2, code);
-		code.append("deleteResourceProperty(PROPERTIES[");
-		code.append(propertyIndex);
-		code.append("]);\n");
-
-		indent(code);
-		generateCloseBlock(code);
-	}
-
-	protected void generatePropertyGetBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, StringBuffer code) {
-		_hasProperties = true;
-		
-		Class type = property.getJavaType();
-		newLine(code);
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-
-		if (type.isArray()) {
-			indent(2, code);
-			code.append("return (");
-			code.append(ReflectUtils.getShortName(type));
-			code.append(")getPropertyAsObject(");
-			code.append("PROPERTIES[");
-			code.append(propertyIndex);
-			code.append("], ");
-
-			type = ReflectUtils.getClassFromArrayClass(type);
-			code.append(ReflectUtils.getShortName(type));
-			code.append(".class);");
-			newLine(code);
-		}
-
-		else {
-			indent(2, code);
-
-			Class array = ReflectUtils.getArrayClassFromClass(type);
-			code.append(ReflectUtils.getShortName(array));
-
-			code.append(" results = (");
-			code.append(ReflectUtils.getShortName(array));
-			code.append(")getPropertyAsObject(");
-			code.append("PROPERTIES[");
-			code.append(propertyIndex);
-			code.append("], ");
-			code.append(ReflectUtils.getShortName(type));
-			code.append(".class);");
-			newLine(code);
-			indent(2, code);
-			code.append("return results.length == 0 ? ");
-			code.append(getNullValue(type));
-			code.append(" : results[0];");
-			newLine(code);
-		}
-
-		indent(code);
-		generateCloseBlock(code);
-	}
-
-	protected void generatePropertySetBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, String setType, StringBuffer code) {
-		_hasProperties = true;
-		
-		Class type = property.getJavaType();
-		if(type.isArray()) {
-			type = ReflectUtils.getClassFromArrayClass(type);
-		}
-		
-		newLine(code);
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-		indent(2, code);
-
-		code.append(setType);
-		code.append("ResourceProperty(PROPERTIES[");
-		code.append(propertyIndex);
-		code.append("], ");
-
-		if (type.isArray())
-			code.append("value");
-
-		else {
-			code.append("new Object[]{ ");
-			code.append(getArrayValue(type));
-			code.append(" }");
-		}
-
-		code.append(");");
-		newLine(code);
-
-		indent(code);
-		generateCloseBlock(code);		
-	}
-	
-	public String generateCombinedCode(ClassInfo classInfo) {			
-		endDeclarationCode(_operationNamesCode);
-		endDeclarationCode(_returnTypesCode);
-		endDeclarationCode(_actionsCode);
-		
-		endDeclarationCode(_requestNamesCode);
-		endDeclarationCode(_responseNamesCode);
-		endDeclarationCode(_requestParamNamesCode);
-		
-		StringBuffer footerCode = generateFooterCode();
-		
-		classInfo.addImports(_importSet);
-		endHeaderCode(classInfo);
-		
-		StringBuffer code = new StringBuffer();
-		
-		code.append(_headerCode);
-
-		if(_hasProperties || _hasMethods) {
-			code.append(_operationsCode);     
-			newLine(code);
-		}
-		
-		if(_hasMethods) {			
-        	code.append(_operationNamesCode);
-        	newLine(code);
-        	code.append(_returnTypesCode);
-        	newLine(code);
-        	code.append(_actionsCode);
-        	newLine(code);
-        	code.append(_requestNamesCode);
-        	newLine(code);
-        	code.append(_responseNamesCode);
-        	newLine(code);
-        	code.append(_requestParamNamesCode);
-		}
-        
-		code.append(footerCode);
-		
-		return code.toString();
-	}
-	
-	protected void endHeaderCode(ClassInfo classInfo) {
-		generateImports(classInfo, _headerCode);
-		String[] interfaces = { ReflectUtils.getShortName(_interfaceName) };
-		String parentClass = ReflectUtils.getShortName(_baseClientClass);
-		generateClassDef(_className, parentClass, interfaces, false, _headerCode);
-	}
-	
-	private StringBuffer generateFooterCode() {
-		StringBuffer code = new StringBuffer();
-		
-		generateProxyConstructors(code);
-
-		if(_hasMethods) {		
-			generateGetHandler(code);
-			
-			newLine(code);
-			generateStatic(code);					
-		}
-		
-		generateCloseBlock(code);	
-		
-		newLine(code);
-		return code;
-	}
-	
-	private void generateProxyConstructors(StringBuffer code) {		
-		String className = ReflectUtils.getShortName(_className);
-
-		Constructor[] ctors = _baseClientClass.getConstructors();
-
-		for (int n = 0; n < ctors.length; ++n) {
-			indent(code);
-			code.append("public ");
-			code.append(className);
-
-			Class[] params = ctors[n].getParameterTypes();
-			generateParamList(null, ctors[n].getParameterTypes(), code);
-			addImports(ctors[n].getParameterTypes());
-
-			indent(code);
-			generateOpenBlock(code);
-			newLine(code);
-			
-			indent(2,code);
-			code.append("super(");
-
-			for (int i = 0; i < params.length; ++i) {
-				code.append(PARAM_NAME + i);
-
-				if (i != params.length - 1)
-					code.append(", ");
-			}
-
-			code.append(");");
-			newLine(code);
-			
-			indent(code);
-			generateCloseBlock(code);
-			newLine(2, code);
-		}
-	}
-
-	private void generateGetHandler(StringBuffer code) {
-		indent(code);
-		code.append("protected ProxyHandler getHandler(String methodName)");
-		addImport(ProxyHandler.class);
-		newLine(code);
-
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-
-		indent(2, code);
-		statement("return (ProxyHandler)_HANDLERS_BY_NAME.get(methodName);",
-				code);
-		newLine(code);
-
-		indent(code);
-		generateCloseBlock(code);
-	}
-	
-	private void generateStatic(StringBuffer code) {
-		
-		newLine(code);
-		indent(code);
-		statement(
-				"private static final Map _HANDLERS_BY_NAME = new HashMap();",
-				code);
-		
-		addImport(Map.class);
-		addImport(HashMap.class);
-		
-		newLine(2, code);
-		indent(code);
-		code.append("static");
-		
-		newLine(code);
-		indent(code);
-		generateOpenBlock(code);
-		newLine(code);
-
-		indent(2,code);
-		code.append("for (int n = 0; n < _METHOD_NAMES.length; ++n)");
-		
-		newLine(code);
-		indent(2,code);
-		generateOpenBlock(code);
-		
-		newLine(code);
-		indent(3,code);
-		code.append("ProxyHandler handler = new ReflectionProxyHandler();");
-		addImport(ReflectionProxyHandler.class);
-		
-		newLine(code);
-		indent(3,code);
-		code.append("handler.setAction(_ACTIONS[n]);");
-		
-		newLine(code);
-		indent(3,code);
-		code.append("handler.setRequestName(_REQUEST_NAMES[n]);");
-		
-		newLine(code);
-		indent(3,code);
-		code.append("handler.setRequestParameterNames(_REQUEST_PARAM_NAMES[n]);");
-		
-		newLine(code);
-		indent(3,code);
-		code.append("handler.setResponseName(_RESPONSE_NAMES[n]);");
-		
-		newLine(code);
-		indent(3,code);
-		code.append("handler.setReturnType(_RETURN_TYPES[n]);");
-
-		newLine(2,code);
-		indent(3,code);
-		code
-				.append("_HANDLERS_BY_NAME.put(_METHOD_NAMES[n], handler);");
-		
-		newLine(code);
-		indent(2,code);
-		generateCloseBlock(code);
-		newLine(code);
-		
-		indent(code);
-		generateCloseBlock(code);
-	}		
-	
-	private void endDeclarationCode(StringBuffer code) {
-    	int length = code.length();
-    	code.delete(length - 2, length);
-        
-    	newLine(code);
-    	indent(code);
-    	generateCloseBlock(code);
-    	code.append(";");
-    	newLine(code);   
-	}	
-
-	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
-		return REQUIRED_PARAMETERS;
-	}
-}
\ No newline at end of file
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.muse.core.proxy.ProxyHandler;
+import org.apache.muse.core.proxy.ReflectionProxyHandler;
+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.tools.inspector.ResourceInspector;
+import org.apache.muse.util.ReflectUtils;
+import org.apache.muse.util.xml.XsdUtils;
+import org.w3c.dom.Document;
+
+public class ProxyClassSynthesizer extends ProxyInterfaceSynthesizer {
+	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
+		new ConfigurationDataDescriptor[] {
+			ConfigurationData.CAPABILITIES_MAP_LIST_CONFIGURATION,
+			ConfigurationData.GENERATE_CUSTOM_HEADERS_CONFIGURATION,
+			ConfigurationData.WSDL_DOCUMENT_LIST_CONFIGURATION
+		};
+	
+	StringBuffer _operationNamesCode;
+	StringBuffer _returnTypesCode;
+	StringBuffer _actionsCode;
+	
+	StringBuffer _requestNamesCode;
+	StringBuffer _responseNamesCode;
+	StringBuffer _requestParamNamesCode;
+	
+	StringBuffer _propertiesOperationsCode;
+	private String _interfaceName;
+
+	private boolean _hasMethods = false;
+	private boolean _hasProperties = false;
+	
+	protected String generateClassName(Document wsdlDocument) {
+		_interfaceName = super.generateClassName(wsdlDocument);
+		return _interfaceName + "Proxy";
+	}
+
+	protected void initializeCode(String className) {
+		_importSet = new HashSet();
+		addImport(_baseClientClass);
+		
+        _className = className;
+		_headerCode = beginHeaderCode(_className);
+        _operationsCode = beginOperationsCode();
+        
+        _operationNamesCode = beginOperationNamesCode();
+        _returnTypesCode = beginReturnTypesCode();
+        _actionsCode = beginActionsCode();
+        
+        _requestNamesCode = beginRequestNamesCode();
+        _responseNamesCode = beginResponseNamesCode();
+        _requestParamNamesCode = beginRequestParamNamesCode();
+        
+        resetIndex();
+	}
+	
+	private StringBuffer beginRequestParamNamesCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final QName[][] _REQUEST_PARAM_NAMES = {");
+		newLine(code);
+		_importSet.add(QName.class);
+		return code;
+	}
+
+	private StringBuffer beginResponseNamesCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final QName[] _RESPONSE_NAMES = {");
+		newLine(code);
+		indent(2,code);
+		_importSet.add(QName.class);
+		return code;
+	}
+
+	private StringBuffer beginRequestNamesCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final QName[] _REQUEST_NAMES = {");
+		newLine(code);
+		indent(2,code);
+		_importSet.add(QName.class);
+		return code;
+	}
+
+	private StringBuffer beginActionsCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final String[] _ACTIONS = {");
+		newLine(code);
+		indent(2,code);
+		return code;
+	}
+
+	private StringBuffer beginReturnTypesCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final Class[] _RETURN_TYPES = {");
+		newLine(code);
+		indent(2,code);
+		return code;
+	}
+
+	private StringBuffer beginOperationsCode() {
+		return new StringBuffer();
+	}
+
+	private StringBuffer beginOperationNamesCode() {
+		StringBuffer code = new StringBuffer();
+		
+		indent(code);
+		code.append("private static final String[] _METHOD_NAMES = {");
+		newLine(code);
+		indent(2,code);
+		return code;
+	}
+	
+	protected void updateCode(ClassInfo classInfo) {
+		updateMethods(classInfo, _operationsCode);		
+		classInfo.addImports(_importSet);
+	}
+	
+	protected void generateMethodQualifier(StringBuffer code) {
+		code.append("public ");
+	}
+	
+	protected void generateMethodBody(JavaMethod method, ClassInfo classInfo, StringBuffer code) {
+		_hasMethods = true;
+		
+		newLine(code);
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+
+		generateParamConversion(method, code);
+		generateHandler(method, classInfo, code);
+		generateInvoke(method, code);
+
+		indent(code);
+		generateCloseBlock(code);
+		
+		updateMethodNames(method);
+		updateReturnTypes(method);
+		updateActions(method);
+		
+		updateRequestNames(method);
+		updateResponseNames(method);
+		updateRequestParamNamesCode(method);
+	}
+	
+	private void generateParamConversion(JavaMethod operation, StringBuffer code) {
+		QName[] paramNames = operation.getParameterTypeNames();
+		Class[] paramTypes = operation.getParameterTypes();
+
+		indent(2, code);
+		code.append("Object[] params = new Object[");
+		code.append(paramTypes.length);
+		code.append("];");
+		newLine(code);
+
+		if (paramTypes.length > 0)
+			newLine(code);
+
+		for (int n = 0; n < paramTypes.length; ++n) {
+			indent(2, code);
+			code.append("params[");
+			code.append(n);
+			code.append("] = ");
+
+			String name = ResourceInspector.getLowerCamelName(paramNames[n]
+					.getLocalPart());
+			code.append(getObjectName(name, paramTypes[n]));
+			code.append(";");
+			newLine(code);
+		}
+
+		newLine(code);
+	}
+
+	private void generateHandler(JavaMethod method, ClassInfo classInfo, StringBuffer code) {
+		indent(2, code);
+		code.append("ProxyHandler handler = getHandler(\"");
+		code.append(method.getJavaName());
+		code.append("\");");
+		newLine(code);
+		
+		classInfo.addImport(ProxyHandler.class);
+	}
+	
+	private void generateInvoke(JavaMethod method, StringBuffer code) {
+		indent(2, code);
+
+		Class returnType = method.getReturnType();
+
+		if (returnType == void.class) {
+			code.append(getInvokeString() + ";");
+		}
+		else if (!returnType.isPrimitive()) {
+			code.append("return (");
+			code.append(ReflectUtils.getShortName(returnType));
+			code.append(")" + getInvokeString() + ";");
+			
+		} else {
+			String className = getPrimitiveClassName(returnType);
+			String convertMethodName = getPrimitiveConvertMethodName(className);
+
+			code.append(className);
+			code.append(" result = (");
+			code.append(className);
+			code.append(")" + getInvokeString() + ";");
+			newLine(code);
+
+			indent(2, code);
+			code.append("return result.");
+			code.append(convertMethodName);
+			code.append("();");
+		}
+		
+		newLine(code);
+	}
+	
+	private String getInvokeString() {
+		if(_generateCustomHeaders) {
+			return "invoke(handler, params, customHeaders)";
+		}
+
+		return "invoke(handler, params)";
+	}
+
+	private void updateRequestParamNamesCode(JavaMethod method) {
+		QName[] names = method.getParameterTypeNames();
+		
+		indent(2, _requestParamNamesCode);
+		generateOpenBlock(_requestParamNamesCode);
+		newLine(_requestParamNamesCode);
+		
+		for(int i=0; i < names.length; i++) {
+			indent(3, _requestParamNamesCode);
+			generateQName(names[i], _requestParamNamesCode);
+			_requestParamNamesCode.append(",");
+			newLine(_requestParamNamesCode);
+		}
+				
+		if(names.length > 0) {
+			int length = _requestParamNamesCode.length();
+			_requestParamNamesCode.delete(length - 2, length);
+		}
+		
+		newLine(_requestParamNamesCode);
+		indent(2, _requestParamNamesCode);
+		generateCloseBlock(_requestParamNamesCode);
+		_requestParamNamesCode.append(",");
+		newLine(_requestParamNamesCode);
+	}
+
+	private void updateResponseNames(JavaMethod method) {
+		QName returnName = method.getReturnName();
+		if (returnName != null && !returnName.equals(XsdUtils.ANY_TYPE_QNAME))
+			generateQName(returnName, _responseNamesCode);
+        
+        else
+        	_responseNamesCode.append("null");
+		
+		_responseNamesCode.append(", ");
+	}
+
+	private void updateRequestNames(JavaMethod method) {
+		QName returnName = method.getName();
+		if (returnName != null && !returnName.equals(XsdUtils.ANY_TYPE_QNAME))
+			generateQName(returnName, _requestNamesCode);
+        
+        else
+        	_requestNamesCode.append("null");
+		
+		_requestNamesCode.append(", ");
+	}
+	
+	private void updateMethodNames(JavaMethod method) {
+		_operationNamesCode.append('"');
+		_operationNamesCode.append(method.getJavaName());
+		_operationNamesCode.append('"');
+		_operationNamesCode.append(", ");
+	}
+	
+	private void updateReturnTypes(JavaMethod method) {
+		Class type = method.getReturnType();
+		
+		if(type.isArray()) {
+			type = ReflectUtils.getClassFromArrayClass(type);
+		}
+		
+		_returnTypesCode.append(ReflectUtils.getShortName(type));
+		_returnTypesCode.append(".class");
+		_returnTypesCode.append(", ");
+	}
+	
+	private void updateActions(JavaMethod method) {
+		_actionsCode.append('"');
+		_actionsCode.append(method.getActionURI());
+		_actionsCode.append('"');
+		_actionsCode.append(", ");
+	}
+
+	protected void generatePropertyDeleteBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, StringBuffer code) {		
+		_hasProperties = true;
+		
+		newLine(code);
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+
+		indent(2, code);
+		code.append("deleteResourceProperty(PROPERTIES[");
+		code.append(propertyIndex);
+		code.append("]);\n");
+
+		indent(code);
+		generateCloseBlock(code);
+	}
+
+	protected void generatePropertyGetBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, StringBuffer code) {
+		_hasProperties = true;
+		
+		Class type = property.getJavaType();
+		newLine(code);
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+
+		if (type.isArray()) {
+			indent(2, code);
+			code.append("return (");
+			code.append(ReflectUtils.getShortName(type));
+			code.append(")getPropertyAsObject(");
+			code.append("PROPERTIES[");
+			code.append(propertyIndex);
+			code.append("], ");
+
+			type = ReflectUtils.getClassFromArrayClass(type);
+			code.append(ReflectUtils.getShortName(type));
+			code.append(".class);");
+			newLine(code);
+		}
+
+		else {
+			indent(2, code);
+
+			Class array = ReflectUtils.getArrayClassFromClass(type);
+			code.append(ReflectUtils.getShortName(array));
+
+			code.append(" results = (");
+			code.append(ReflectUtils.getShortName(array));
+			code.append(")getPropertyAsObject(");
+			code.append("PROPERTIES[");
+			code.append(propertyIndex);
+			code.append("], ");
+			code.append(ReflectUtils.getShortName(type));
+			code.append(".class);");
+			newLine(code);
+			indent(2, code);
+			code.append("return results.length == 0 ? ");
+			code.append(getNullValue(type));
+			code.append(" : results[0];");
+			newLine(code);
+		}
+
+		indent(code);
+		generateCloseBlock(code);
+	}
+
+	protected void generatePropertySetBody(JavaProperty property, ClassInfo classInfo, int propertyIndex, String setType, StringBuffer code) {
+		_hasProperties = true;
+		
+		Class type = property.getJavaType();
+		if(type.isArray()) {
+			type = ReflectUtils.getClassFromArrayClass(type);
+		}
+		
+		newLine(code);
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+		indent(2, code);
+
+		code.append(setType);
+		code.append("ResourceProperty(PROPERTIES[");
+		code.append(propertyIndex);
+		code.append("], ");
+
+		if (type.isArray())
+			code.append("value");
+
+		else {
+			code.append("new Object[]{ ");
+			code.append(getArrayValue(type));
+			code.append(" }");
+		}
+
+		code.append(");");
+		newLine(code);
+
+		indent(code);
+		generateCloseBlock(code);		
+	}
+	
+	public String generateCombinedCode(ClassInfo classInfo) {			
+		endDeclarationCode(_operationNamesCode);
+		endDeclarationCode(_returnTypesCode);
+		endDeclarationCode(_actionsCode);
+		
+		endDeclarationCode(_requestNamesCode);
+		endDeclarationCode(_responseNamesCode);
+		endDeclarationCode(_requestParamNamesCode);
+		
+		StringBuffer footerCode = generateFooterCode();
+		
+		classInfo.addImports(_importSet);
+		endHeaderCode(classInfo);
+		
+		StringBuffer code = new StringBuffer();
+		
+		code.append(_headerCode);
+
+		if(_hasProperties || _hasMethods) {
+			code.append(_operationsCode);     
+			newLine(code);
+		}
+		
+		if(_hasMethods) {			
+        	code.append(_operationNamesCode);
+        	newLine(code);
+        	code.append(_returnTypesCode);
+        	newLine(code);
+        	code.append(_actionsCode);
+        	newLine(code);
+        	code.append(_requestNamesCode);
+        	newLine(code);
+        	code.append(_responseNamesCode);
+        	newLine(code);
+        	code.append(_requestParamNamesCode);
+		}
+        
+		code.append(footerCode);
+		
+		return code.toString();
+	}
+	
+	protected void endHeaderCode(ClassInfo classInfo) {
+		generateImports(classInfo, _headerCode);
+		String[] interfaces = { ReflectUtils.getShortName(_interfaceName) };
+		String parentClass = ReflectUtils.getShortName(_baseClientClass);
+		generateClassDef(_className, parentClass, interfaces, false, _headerCode);
+	}
+	
+	private StringBuffer generateFooterCode() {
+		StringBuffer code = new StringBuffer();
+		
+		generateProxyConstructors(code);
+
+		if(_hasMethods) {		
+			generateGetHandler(code);
+			
+			newLine(code);
+			generateStatic(code);					
+		}
+		
+		generateCloseBlock(code);	
+		
+		newLine(code);
+		return code;
+	}
+	
+	private void generateProxyConstructors(StringBuffer code) {		
+		String className = ReflectUtils.getShortName(_className);
+
+		Constructor[] ctors = _baseClientClass.getConstructors();
+
+		for (int n = 0; n < ctors.length; ++n) {
+			indent(code);
+			code.append("public ");
+			code.append(className);
+
+			Class[] params = ctors[n].getParameterTypes();
+			generateParamList(null, ctors[n].getParameterTypes(), code);
+			addImports(ctors[n].getParameterTypes());
+
+			indent(code);
+			generateOpenBlock(code);
+			newLine(code);
+			
+			indent(2,code);
+			code.append("super(");
+
+			for (int i = 0; i < params.length; ++i) {
+				code.append(PARAM_NAME + i);
+
+				if (i != params.length - 1)
+					code.append(", ");
+			}
+
+			code.append(");");
+			newLine(code);
+			
+			indent(code);
+			generateCloseBlock(code);
+			newLine(2, code);
+		}
+	}
+
+	private void generateGetHandler(StringBuffer code) {
+		indent(code);
+		code.append("protected ProxyHandler getHandler(String methodName)");
+		addImport(ProxyHandler.class);
+		newLine(code);
+
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+
+		indent(2, code);
+		statement("return (ProxyHandler)_HANDLERS_BY_NAME.get(methodName);",
+				code);
+		newLine(code);
+
+		indent(code);
+		generateCloseBlock(code);
+	}
+	
+	private void generateStatic(StringBuffer code) {
+		
+		newLine(code);
+		indent(code);
+		statement(
+				"private static final Map _HANDLERS_BY_NAME = new HashMap();",
+				code);
+		
+		addImport(Map.class);
+		addImport(HashMap.class);
+		
+		newLine(2, code);
+		indent(code);
+		code.append("static");
+		
+		newLine(code);
+		indent(code);
+		generateOpenBlock(code);
+		newLine(code);
+
+		indent(2,code);
+		code.append("for (int n = 0; n < _METHOD_NAMES.length; ++n)");
+		
+		newLine(code);
+		indent(2,code);
+		generateOpenBlock(code);
+		
+		newLine(code);
+		indent(3,code);
+		code.append("ProxyHandler handler = new ReflectionProxyHandler();");
+		addImport(ReflectionProxyHandler.class);
+		
+		newLine(code);
+		indent(3,code);
+		code.append("handler.setAction(_ACTIONS[n]);");
+		
+		newLine(code);
+		indent(3,code);
+		code.append("handler.setRequestName(_REQUEST_NAMES[n]);");
+		
+		newLine(code);
+		indent(3,code);
+		code.append("handler.setRequestParameterNames(_REQUEST_PARAM_NAMES[n]);");
+		
+		newLine(code);
+		indent(3,code);
+		code.append("handler.setResponseName(_RESPONSE_NAMES[n]);");
+		
+		newLine(code);
+		indent(3,code);
+		code.append("handler.setReturnType(_RETURN_TYPES[n]);");
+
+		newLine(2,code);
+		indent(3,code);
+		code
+				.append("_HANDLERS_BY_NAME.put(_METHOD_NAMES[n], handler);");
+		
+		newLine(code);
+		indent(2,code);
+		generateCloseBlock(code);
+		newLine(code);
+		
+		indent(code);
+		generateCloseBlock(code);
+	}		
+	
+	private void endDeclarationCode(StringBuffer code) {
+    	int length = code.length();
+    	code.delete(length - 2, length);
+        
+    	newLine(code);
+    	indent(code);
+    	generateCloseBlock(code);
+    	code.append(";");
+    	newLine(code);   
+	}	
+
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return REQUIRED_PARAMETERS;
+	}
+}



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