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 07:59:35 UTC

svn commit: r433535 - /webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/

Author: aeberbac
Date: Mon Aug 21 22:59:34 2006
New Revision: 433535

URL: http://svn.apache.org/viewvc?rev=433535&view=rev
Log:
moved to new projectizer API. Still needs some clean up and string externalization.


Added:
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java   (with props)
Removed:
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/ProjectizerConstants.java
Modified:
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/AbstractProjectizer.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2Projectizer.java
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Messages.properties
    webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Projectizer.java

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/AbstractProjectizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/AbstractProjectizer.java?rev=433535&r1=433534&r2=433535&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/AbstractProjectizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/AbstractProjectizer.java Mon Aug 21 22:59:34 2006
@@ -16,86 +16,50 @@
 
 package org.apache.muse.tools.generator.projectizer;
 
-import java.io.File;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.xml.namespace.QName;
-
 import org.apache.muse.util.xml.XmlUtils;
 import org.apache.muse.ws.wsdl.WsdlUtils;
 import org.w3c.dom.Element;
 
 /**
  * 
- * AbstractProjectizer is ...
- *
- * @author Andrew Eberbach
+ * AbstractProjectizer contains methods that are useful to projectizers built so far.
  *
+ * @author Andrew Eberbach (aeberbac)
  */
 
 public abstract class AbstractProjectizer implements Projectizer {
 
-	private static final String SERVICES = "services";
-
-	protected Element _descriptor;
-
-	protected boolean _overwrite;
-
-	protected QName _portType;
-
-	protected File _wsdlFile;
+	static String VERSION = "2.0.0-M2"; 
 	
-	protected String _serviceName;
-
-	protected Element _wsdlDefinition;
-
-	protected File _targetDirectory;
+	final static String POM_PROPERTIES = "/META-INF/maven/muse/muse-tools/pom.properties";
 	
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.muse.tools.generator.Generator#setDescriptor(java.io.File)
-	 */
-	public void setDescriptor(Element descriptor) {
-		_descriptor = descriptor;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.muse.tools.generator.Generator#setOverwrite(boolean)
-	 */
-	public void setOverwrite(boolean overwrite) {
-		_overwrite = overwrite;
-	}
-	
-	public void setTargetDirectory(File targetDirectory) {
-		_targetDirectory = targetDirectory;
-	}
+	final static String POM_VERSION_PROPERTY = "version";
+		
+	private static final String SERVICES = "services";
 	
-	public void setPortType(QName portType) {
-		_portType = portType;
-	}
-
-	public void setWSDL(File wsdlFile, Element wsdlDefinition) {
-		_wsdlFile = wsdlFile;
-		_wsdlDefinition = wsdlDefinition;
+	protected static final String DEFAULT_WSDL_NAME_SUFFIX = ".wsdl";
 		
-		_serviceName = getServiceName();
+	String DEFAULT_SERVICE_NAME = "MyService";
+	
+	static {
+		InputStream pomProperties = 
+			AbstractProjectizer.class.getResourceAsStream(POM_PROPERTIES);
+		Properties properties = new Properties();
+		try {
+			properties.load(pomProperties);
+			VERSION = properties.getProperty(POM_VERSION_PROPERTY);
+		} catch (Exception e) {}
 	}
 
-	protected void propagateSettings(Projectizer writer) {
-		writer.setDescriptor(_descriptor);
-		writer.setWSDL(_wsdlFile, _wsdlDefinition);
-		writer.setPortType(_portType);
-		writer.setOverwrite(_overwrite);
-	}
-	
-	protected String getServiceName() {
-		Element address = XmlUtils.findFirstInSubTree(_wsdlDefinition,
+	protected String getServiceName(Element wsdlDefinition) {
+		Element address = XmlUtils.findFirstInSubTree(wsdlDefinition,
 				WsdlUtils.ADDRESS_QNAME);
 		if (address != null) {
 			String location = address.getAttribute(WsdlUtils.LOCATION);

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2Projectizer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2Projectizer.java?rev=433535&r1=433534&r2=433535&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2Projectizer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2Projectizer.java Mon Aug 21 22:59:34 2006
@@ -27,7 +27,9 @@
 import javax.xml.namespace.QName;
 
 import org.apache.muse.core.descriptor.DescriptorConstants;
-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.util.FileUtils;
 import org.apache.muse.util.messages.Messages;
@@ -46,7 +48,22 @@
  *
  */
 
-public class Axis2Projectizer extends AbstractProjectizer {
+public class Axis2Projectizer extends AbstractProjectizer implements Axis2ProjectizerConstants {
+	
+	String[] MUSE_JARS = new String[] {
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsdm-muws-adv-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsdm-muws-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsdm-wef-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsn-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsrf-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-api","muse-wsx-api-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsdm-muws-adv-impl-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsdm-muws-impl-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsdm-wef-impl-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsn-impl-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsrf-impl-" + VERSION + ".jar"}),
+		FileUtils.makePath(new String[] {"modules","ws-fx-impl","muse-wsx-impl-" + VERSION + ".jar"})
+	};
 	
     //
     // Used to lookup all exception messages
@@ -58,58 +75,106 @@
 	private static final QName PROPERTY_QNAME = new QName("property");
 	private static final String ACTION_MAPPING = "actionMapping";
 	private static final String MUSE_HOME_PROPERTY = "MUSE_HOME";
-	private static final String BUILD_XML = "/build.xml";
-	private static final String SERVICES_XML = "/services.xml";
+	private static final String BUILD_XML = "/resources/axis2/build.xml";
+	private static final String SERVICES_XML = "/resources/axis2/services.xml";
 	public static final String WEBCONTENT_DIR = "WebContent";
 	public static final String JAVASRC_DIR = "JavaSource";
 	private static final String NAME_ATTRIBUTE = "name";
 	private static final String VALUE_ATTRIBUTE = "value";
+
+	static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS = 
+		new ConfigurationDataDescriptor[] {
+			ConfigurationData.FILES_MAP_CONFIGURATION,
+			ConfigurationData.DESCRIPTOR_DOCUMENT_CONFIGURATION,
+			ConfigurationData.WSDL_DOCUMENT_CONFIGURATION, 
+			ConfigurationData.OVERWRITE_CONFIGURATION,
+			ConfigurationData.PORT_TYPE_CONFIGURATION,
+			ConfigurationData.CAPABILITIES_MAP_CONFIGURATION
+		};
+
+	private File _targetDirectory = null;
+
+	private Map _capabilities = null;
+
+	private Map _files = null;
+
+	private boolean _overwrite = false;
+
+	private Document _descriptor = null;
+
+	private QName _portType = null;
+
+	private Document _wsdl = null;
+
+	private String _serviceName = null;
+
+	private String _wsdlFileName;
 	
-	public void writeFiles(Map capabilities, Map files) {
-		try {				
-			File baseTargetDir = _targetDirectory == null?FileUtils.CURRENT_DIR: _targetDirectory;							
-			File webContentDir = copyTemplate(baseTargetDir);
-						
-			createDescriptor(webContentDir, capabilities);
+	public void projectize(ConfigurationData configuration) throws Exception {
+		ConfigurationData.checkConfiguration(this, configuration);
+		
+		loadParameters(configuration);
+		
+		File baseTargetDir = _targetDirectory == null?FileUtils.CURRENT_DIR: _targetDirectory;							
+		
+		File webContentDir = copyTemplate(baseTargetDir);
 					
-			createJavaSources(baseTargetDir, files);
+		createDescriptor(webContentDir, _capabilities);
+				
+		createJavaSources(baseTargetDir, _files);
 
-			createServicesDescriptor(webContentDir, capabilities);
+		createServicesDescriptor(webContentDir, _capabilities);
 
-			createBuildFile(baseTargetDir);
-			
-			createWSDLFile(webContentDir);				
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
+		createBuildFile(baseTargetDir);
+		
+		createWSDLFile(webContentDir);				
+	}
+
+	private void loadParameters(ConfigurationData configuration) {
+		_capabilities = (Map)configuration.getParameter(ConfigurationData.CAPABILITIES_MAP);
+		_files = (Map)configuration.getParameter(ConfigurationData.FILES_MAP);
+		_overwrite = ((Boolean)configuration.getParameter(ConfigurationData.OVERWRITE)).booleanValue();
+		_descriptor = (Document)configuration.getParameter(ConfigurationData.DESCRIPTOR_DOCUMENT);
+		_portType = (QName)configuration.getParameter(ConfigurationData.PORT_TYPE);
+		_wsdl = (Document)configuration.getParameter(ConfigurationData.WSDL_DOCUMENT);
+		_targetDirectory = (File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY);
+		
+		_serviceName = getServiceName(_wsdl.getDocumentElement());
+		_wsdlFileName = _serviceName + DEFAULT_WSDL_NAME_SUFFIX;
 	}
 
 	protected void createWSDLFile(File webContentDir) throws IOException {
 		File wsdldir = new File(webContentDir, WSDL_TEMPLATE_PATH);
 		wsdldir.mkdirs();
-		File wsdlFile = new File(wsdldir, _wsdlFile.getName());
-		writeToFileCheck(_wsdlDefinition, wsdlFile);
+		File wsdlFile = new File(wsdldir, _wsdlFileName);
+		writeToFileCheck(_wsdl, wsdlFile);
 	}
 
-	private void createBuildFile(File baseTargetDir) throws IOException {
+	private void createBuildFile(File baseTargetDir) throws Exception {
+		File buildXmlFile = new File(BUILD_XML);
 		InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),BUILD_XML);
-		File build = new File(baseTargetDir, BUILD_XML);
+		File build = new File(baseTargetDir, buildXmlFile.getName());
 		copyStreamCheck(buildTemplate, build);			
 		updateBuild(build);
 	}
 
-	protected void createServicesDescriptor(File webContentDir, Map capabilities) throws IOException {		
+	protected void createServicesDescriptor(File webContentDir, Map capabilities) throws Exception {		
 		InputStream servicesDescriptorTemplate = FileUtils.loadFromContext(this.getClass(), SERVICES_XML);
 		File servicesDescriptor = new File(webContentDir,SERVICES_TEMPLATE_PATH);
 		copyStreamCheck(servicesDescriptorTemplate, servicesDescriptor);
 		updateServices(servicesDescriptor, capabilities);
 	}
 
-	private void copyStreamCheck(InputStream inputStream, File destination) throws IOException {
+	private void copyStreamCheck(InputStream inputStream, File destination) throws Exception {
 		if(!destination.exists() || _overwrite) {
-			if(destination.getParentFile().mkdirs()) {
-				FileUtils.copyFile(inputStream,destination);
+			File parent = destination.getAbsoluteFile().getParentFile();
+			if(!parent.exists()) {
+				if(!parent.mkdirs()) {
+					throw new Exception("Could not make dir: " + parent);
+				}
 			}
+			
+			FileUtils.copyFile(inputStream,destination);		
 		} else {
 			System.out.println(_MESSAGES.get("NotOverwriting", new String[] {destination.getPath()}));
 		}
@@ -206,7 +271,7 @@
 			XmlUtils.setNamespaceAttribute(descriptorDocument.getDocumentElement(),prefix  , _portType.getNamespaceURI());
 			
 			Element wsdlFile = XmlUtils.findFirstInSubTree(resourceType, DescriptorConstants.WSDL_FILE_QNAME);
-			XmlUtils.setElementText(wsdlFile, "/wsdl/" + _wsdlFile.getName());
+			XmlUtils.setElementText(wsdlFile, "/wsdl/" + _wsdlFileName);
 			
 			Element contextPath = XmlUtils.findFirstInSubTree(resourceType, DescriptorConstants.CONTEXT_PATH_QNAME);
 			XmlUtils.setElementText(contextPath, _serviceName);
@@ -308,4 +373,8 @@
                    path.endsWith(SIMPLE_TEMPLATE_PATH));
         }
     }
+
+	public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
+		return REQUIRED_PARAMETERS;
+	}
 }

Added: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java?rev=433535&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java (added)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java Mon Aug 21 22:59:34 2006
@@ -0,0 +1,45 @@
+/*=============================================================================*
+ *  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.util.FileUtils;
+
+/**
+ * 
+ *
+ * ProjectizerConstants is ...
+ *
+ * @author Andrew Eberbach
+ *
+ */
+
+public interface Axis2ProjectizerConstants {		
+	
+	String DESCRIPTOR_TEMPLATE_PATH = FileUtils
+		.makePath(new String[] { "WEB-INF", "services", "muse", "muse.xml" });
+	
+	String SERVICES_TEMPLATE_PATH = FileUtils
+		.makePath(new String[] { "WEB-INF", "services", "muse", "META-INF",
+				"services.xml" });
+	
+	String WSDL_TEMPLATE_PATH = FileUtils
+		.makePath(new String[] { "WEB-INF", "services", "muse", "wsdl"});
+	
+	String SIMPLE_TEMPLATE_PATH = FileUtils
+		.makePath(new String[] { "WEB-INF", "lib", "simple.jar" });	
+	    
+}

Propchange: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Axis2ProjectizerConstants.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Messages.properties?rev=433535&r1=433534&r2=433535&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Messages.properties (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/projectizer/Messages.properties Mon Aug 21 22:59:34 2006
@@ -1,2 +1 @@
-#Wed Aug 16 21:49:58 EDT 2006
-NotOverwriting=Not Overwriting\: XXX
+NotOverwriting = Not Overwriting: XXX. Setting the overwrite parameter will force existing files to be overwritten.
\ No newline at end of file

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?rev=433535&r1=433534&r2=433535&view=diff
==============================================================================
--- 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 Mon Aug 21 22:59:34 2006
@@ -16,12 +16,8 @@
 
 package org.apache.muse.tools.generator.projectizer;
 
-import java.io.File;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Element;
+import org.apache.muse.tools.generator.util.Configurable;
+import org.apache.muse.tools.generator.util.ConfigurationData;
 
 /**
  * 
@@ -31,11 +27,7 @@
  *
  */
 
-public interface Projectizer extends ProjectizerConstants {
-	void setOverwrite(boolean overwrite);
-	void setDescriptor(Element descriptor);
-	void setPortType(QName portType);
-	void setWSDL(File wsdlFile, Element wsdl);
-	void setTargetDirectory(File targetDirectory);
-	void writeFiles(Map capabilities, Map files);
+public interface Projectizer extends Configurable {
+	
+	void projectize(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