[savara-commits] savara SVN: r206 - in tools/eclipse/trunk/plugins: org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Mar 21 15:04:30 EDT 2010


Author: objectiser
Date: 2010-03-21 15:04:30 -0400 (Sun, 21 Mar 2010)
New Revision: 206

Modified:
   tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/dialogs/GenerateDialog.java
   tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
   tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
   tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java
Log:
Added import of message schema files and copied them into the same folder as the generated WSDL files (SAVARA-54).

Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/dialogs/GenerateDialog.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/dialogs/GenerateDialog.java	2010-03-21 16:53:15 UTC (rev 205)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/dialogs/GenerateDialog.java	2010-03-21 19:04:30 UTC (rev 206)
@@ -336,7 +336,7 @@
 				
 				if (m_roleButtons.get(i).getSelection()) {
 					generator.generateRole(m_localModelRefs.get(i),
-							m_projectNames.get(i).getText());
+							m_projectNames.get(i).getText(), m_file);
 				}
 			}
 			

Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-03-21 16:53:15 UTC (rev 205)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-03-21 19:04:30 UTC (rev 206)
@@ -24,15 +24,18 @@
 
 import org.apache.commons.logging.*;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.jboss.savara.tools.bpel.generator.BuildSystem;
 import org.jboss.savara.tools.bpel.model.*;
 import org.jboss.savara.tools.bpel.model.component.PartnerLink;
 import org.jboss.savara.tools.bpel.util.XMLUtils;
+import org.jboss.savara.tools.wsdl.generator.GeneratorUtil;
 import org.jboss.savara.tools.wsdl.generator.soap.*;
 import org.scribble.contract.model.Contract;
 import org.scribble.contract.model.Interface;
+import org.scribble.contract.model.Namespace;
 import org.scribble.conversation.model.*;
 import org.scribble.extensions.RegistryFactory;
 import org.scribble.model.*;
@@ -155,9 +158,10 @@
 	 * 
 	 * @param localModelRef The local model reference
 	 * @param projectName The project name
+	 * @param cdmResource The original choreography file
 	 * @throws Exception Failed to generate role
 	 */
-	public void generateRole(ModelReference localModelRef, String projectName)
+	public void generateRole(ModelReference localModelRef, String projectName, IFile cdmResource)
 						throws Exception {
 		
 		if (logger.isDebugEnabled()) {
@@ -207,7 +211,7 @@
 								lcm);
 					
 					generateRoleProject(projectName, role,
-								target.getBPELProcess(), lcm, target);
+								target.getBPELProcess(), lcm, target, cdmResource);
 				} else {
 					logger.error("Unable to find model generator");
 				}
@@ -217,7 +221,7 @@
 	
 	protected void generateRoleProject(String projectName, Role role,
 			org.jboss.savara.tools.bpel.model.component.Process bpelProcess, ConversationModel localcm,
-			BPELLanguageModel model) throws Exception {
+			BPELLanguageModel model, IFile cdmResource) throws Exception {
 		
 		final IProject proj=createProject(projectName);
 		
@@ -230,7 +234,8 @@
 							localcm.getModelName().getRole().getName()+".bpel");
 			
 			IFile bpelFile=proj.getProject().getWorkspace().getRoot().getFile(bpelPath);
-			GeneratorUtil.createParentFolder(bpelFile);
+			GeneratorUtil.createFolder(bpelFile);
+			
 			bpelFile.create(null, true,
 					new org.eclipse.core.runtime.NullProgressMonitor());
 			
@@ -243,12 +248,12 @@
 			}
 			
 			// Write the WSDL files
-			generateWSDL(role, proj, localcm);		
+			generateWSDL(role, proj, localcm, cdmResource);		
 			
 			java.util.List<Role> roles=localcm.getConversation().getRoles();
 			
 			for (int i=0; i < roles.size(); i++) {
-				generateWSDL(roles.get(i), proj, localcm);
+				generateWSDL(roles.get(i), proj, localcm, cdmResource);
 			}
 			
 			// Generate WSDL with partner link types
@@ -259,8 +264,8 @@
 		}
 	}
 	
-	protected void generateWSDL(Role role, IProject proj, ConversationModel localcm)
-						throws Exception {		
+	protected void generateWSDL(Role role, IProject proj, ConversationModel localcm,
+						IFile cdmResource) throws Exception {		
 		
 		if (role.getAnnotations().containsKey(Contract.class.getName())) {
 			javax.wsdl.xml.WSDLWriter writer=
@@ -269,6 +274,15 @@
 						new org.jboss.savara.tools.wsdl.generator.WSDLGenerator();
 			Contract contract=(Contract)role.getAnnotations().get(Contract.class.getName());
 
+			// Generate WSDL folder
+			IPath wsdlFolderPath=proj.getFullPath().append(
+					new Path(getBuildSystem().getBPELFilePath()));
+
+			IFolder wsdlFolder=proj.getProject().getWorkspace().getRoot().getFolder(wsdlFolderPath);
+			
+			GeneratorUtil.createFolder(wsdlFolder);
+			
+			// Generate definition
 			java.util.List<javax.wsdl.Definition> defns=generator.generateDefinitions(contract,
 									new SOAPDocLitWSDLBinding());
 			
@@ -301,6 +315,35 @@
 						imp.setLocationURI(filename);
 						
 						defns.get(0).addImport(imp);					
+					} else {
+						
+						// Generate imports for specified message schema
+						for (Namespace ns : contract.getNamespaces()) {
+							
+							if (ns.getSchemaLocation() != null) {
+								IFile file=cdmResource.getParent().getFile(new Path(ns.getSchemaLocation()));
+								
+								javax.wsdl.Import imp=defns.get(0).createImport();
+								
+								imp.setDefinition(defn);
+								imp.setNamespaceURI(ns.getURI());
+								imp.setLocationURI(file.getName());
+								
+								defns.get(0).addImport(imp);					
+								
+								IPath artifactPath=wsdlFolderPath.append(file.getName());
+					
+								IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+								if (artifactFile.exists() == false) {
+									artifactFile.create(null, true,
+											new org.eclipse.core.runtime.NullProgressMonitor());
+								}
+								
+								artifactFile.setContents(file.getContents(), true, false,
+											new org.eclipse.core.runtime.NullProgressMonitor());
+							}
+						}
 					}
 					
 					java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
@@ -311,15 +354,17 @@
 					
 					baos.close();
 					
-					IPath wsdlPath=proj.getFullPath().append(
-							new Path(getBuildSystem().getBPELFilePath())).
-								append(filename);
+					IPath wsdlPath=wsdlFolderPath.append(filename);
 					
 					IFile wsdlFile=proj.getProject().getWorkspace().getRoot().getFile(wsdlPath);
-					GeneratorUtil.createParentFolder(wsdlFile);
-					wsdlFile.create(null, true,
-							new org.eclipse.core.runtime.NullProgressMonitor());
 					
+					GeneratorUtil.createFolder(wsdlFile);
+					
+					if (wsdlFile.exists() == false) {
+						wsdlFile.create(null, true,
+								new org.eclipse.core.runtime.NullProgressMonitor());
+					}
+					
 					wsdlFile.setContents(new java.io.ByteArrayInputStream(b), true, false,
 								new org.eclipse.core.runtime.NullProgressMonitor());
 				}
@@ -431,7 +476,9 @@
 					append(filename);
 		
 		IFile wsdlFile=proj.getProject().getWorkspace().getRoot().getFile(wsdlPath);
-		GeneratorUtil.createParentFolder(wsdlFile);
+		
+		GeneratorUtil.createFolder(wsdlFile);
+		
 		wsdlFile.create(null, true,
 				new org.eclipse.core.runtime.NullProgressMonitor());
 		
@@ -535,7 +582,9 @@
 					append(BPEL_DEPLOY_DESCRIPTOR_FILENAME);
 		
 		IFile wsdlFile=proj.getProject().getWorkspace().getRoot().getFile(wsdlPath);
-		GeneratorUtil.createParentFolder(wsdlFile);
+		
+		GeneratorUtil.createFolder(wsdlFile);
+		
 		wsdlFile.create(null, true,
 				new org.eclipse.core.runtime.NullProgressMonitor());
 		

Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java	2010-03-21 16:53:15 UTC (rev 205)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java	2010-03-21 19:04:30 UTC (rev 206)
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.*;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
@@ -34,6 +35,7 @@
 
 import org.scribble.contract.model.Contract;
 import org.scribble.contract.model.Interface;
+import org.scribble.contract.model.Namespace;
 import org.scribble.conversation.model.ConversationModel;
 import org.scribble.eclipse.util.*;
 import org.scribble.extensions.RegistryFactory;
@@ -134,6 +136,14 @@
 				new org.jboss.savara.tools.wsdl.generator.WSDLGenerator();
 			Contract contract=(Contract)ref.getAnnotations().get(Contract.class.getName());
 		
+			// Generate WSDL folder
+			IPath wsdlFolderPath=cdmResource.getParent().getFullPath().append(new Path("wsdl"));
+
+			IFolder wsdlFolder=cdmResource.getProject().getWorkspace().getRoot().getFolder(wsdlFolderPath);
+			
+			GeneratorUtil.createFolder(wsdlFolder);
+			
+			// Generate definition
 			java.util.List<javax.wsdl.Definition> defns=generator.generateDefinitions(contract,
 						new SOAPDocLitWSDLBinding());
 		
@@ -166,6 +176,35 @@
 						imp.setLocationURI(filename);
 						
 						defns.get(0).addImport(imp);					
+					} else {
+					
+						// Generate imports for specified message schema
+						for (Namespace ns : contract.getNamespaces()) {
+							
+							if (ns.getSchemaLocation() != null) {
+								IFile file=cdmResource.getParent().getFile(new Path(ns.getSchemaLocation()));
+								
+								javax.wsdl.Import imp=defns.get(0).createImport();
+								
+								imp.setDefinition(defn);
+								imp.setNamespaceURI(ns.getURI());
+								imp.setLocationURI(file.getName());
+								
+								defns.get(0).addImport(imp);					
+								
+								IPath artifactPath=wsdlFolderPath.append(file.getName());
+					
+								IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+								if (artifactFile.exists() == false) {
+									artifactFile.create(null, true,
+											new org.eclipse.core.runtime.NullProgressMonitor());
+								}
+								
+								artifactFile.setContents(file.getContents(), true, false,
+											new org.eclipse.core.runtime.NullProgressMonitor());
+							}
+						}
 					}
 					
 					java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
@@ -176,11 +215,10 @@
 					
 					baos.close();
 					
-					IPath wsdlPath=cdmResource.getParent().getFullPath().append(
-								new Path("wsdl")).append(filename);
+					IPath wsdlPath=wsdlFolderPath.append(filename);
 		
 					IFile wsdlFile=cdmResource.getProject().getWorkspace().getRoot().getFile(wsdlPath);
-					GeneratorUtil.createParentFolder(wsdlFile);
+
 					wsdlFile.create(null, true,
 							new org.eclipse.core.runtime.NullProgressMonitor());
 					

Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java	2010-03-21 16:53:15 UTC (rev 205)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java	2010-03-21 19:04:30 UTC (rev 206)
@@ -27,26 +27,27 @@
 public class GeneratorUtil {
 
 	/**
-	 * This method checks whether the parent folder exists,
+	 * This method checks whether the folder exists,
 	 * and if not attempts to create it.
 	 * 
 	 * @param res The current resource
 	 */
-	public static void createParentFolder(IResource res) {
-		
-		if (res.getParent() instanceof IFolder) {
-			IFolder parent=(IFolder)res.getParent();
+	public static void createFolder(IResource res) {
+		if (res instanceof IFolder) {
+			IFolder folder=(IFolder)res;
 			
-			if (parent.exists() == false) {
-				createParentFolder(parent);
+			if (folder.exists() == false) {
+				createFolder(folder.getParent());
 
 				try {
-					parent.create(true, true,
+					folder.create(true, true,
 							new org.eclipse.core.runtime.NullProgressMonitor());
 				} catch(Exception e) {
 					e.printStackTrace();
 				}
 			}
+		} else if (res.getParent() != null) {
+			createFolder(res.getParent());
 		}
 	}
 



More information about the savara-commits mailing list