[savara-commits] savara SVN: r285 - trunk/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jun 29 09:44:20 EDT 2010


Author: objectiser
Date: 2010-06-29 09:44:20 -0400 (Tue, 29 Jun 2010)
New Revision: 285

Modified:
   branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
   trunk/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
Log:
SAVARA-111 - now deals with xsd includes.

Modified: branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-06-29 11:36:53 UTC (rev 284)
+++ branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-06-29 13:44:20 UTC (rev 285)
@@ -17,6 +17,8 @@
  */
 package org.jboss.savara.tools.bpel.generator;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -56,6 +58,12 @@
  */
 public class Generator {
 
+	private static final String SCHEMA_LOCATION_ATTR = "schemaLocation";
+
+	private static final String INCLUDE_ELEMENT = "include";
+
+	private static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+
 	private static final String WSDL_IMPORT = "wsdl:import";
 
 	private static final String BPEL_DEPLOY_DESCRIPTOR_FILENAME = "bpel-deploy.xml";
@@ -377,18 +385,52 @@
 					firstDefn.addImport(imp);					
 					
 					IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
-		
+					
 					IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
 
-					if (artifactFile.exists() == false) {
-						GeneratorUtil.createFolder(artifactFile.getParent());
+					copySchema(file, artifactFile, bpelFolderPath);
+				}
+			}
+		}
+	}
 
-						artifactFile.create(null, true,
-								new org.eclipse.core.runtime.NullProgressMonitor());
-					}
+	protected void copySchema(IFile srcXSDFile, IFile targetXSDFile, IPath bpelFolderPath) throws Exception {
+
+		if (targetXSDFile.exists() == false) {
+			GeneratorUtil.createFolder(targetXSDFile.getParent());
+
+			targetXSDFile.create(null, true,
+					new org.eclipse.core.runtime.NullProgressMonitor());
+		}
+		
+		targetXSDFile.setContents(srcXSDFile.getContents(), true, false,
+					new org.eclipse.core.runtime.NullProgressMonitor());
+		
+		// Check XSD for further 'include' statements
+		DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+		fact.setNamespaceAware(true);
+
+		DocumentBuilder builder=fact.newDocumentBuilder();
+		org.w3c.dom.Document doc=builder.parse(srcXSDFile.getContents());
+
+		org.w3c.dom.NodeList nl=doc.getElementsByTagNameNS(XML_SCHEMA, INCLUDE_ELEMENT);
+		
+		for (int i=0; i < nl.getLength(); i++) {
+			org.w3c.dom.Node includeNode=nl.item(i);
+			
+			if (includeNode instanceof org.w3c.dom.Element) {
+				String schemaLocation=((org.w3c.dom.Element)includeNode).getAttribute(SCHEMA_LOCATION_ATTR);
+				
+				// Check if a relative path
+				IFile file=srcXSDFile.getParent().getFile(new Path(schemaLocation));
+				
+				if (file.exists()) {
 					
-					artifactFile.setContents(file.getContents(), true, false,
-								new org.eclipse.core.runtime.NullProgressMonitor());
+					IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+					
+					IFile artifactFile=file.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+					copySchema(file, artifactFile, bpelFolderPath);
 				}
 			}
 		}

Modified: trunk/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- trunk/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-06-29 11:36:53 UTC (rev 284)
+++ trunk/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java	2010-06-29 13:44:20 UTC (rev 285)
@@ -17,6 +17,8 @@
  */
 package org.jboss.savara.tools.bpel.generator;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -56,6 +58,12 @@
  */
 public class Generator {
 
+	private static final String SCHEMA_LOCATION_ATTR = "schemaLocation";
+
+	private static final String INCLUDE_ELEMENT = "include";
+
+	private static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+
 	private static final String WSDL_IMPORT = "wsdl:import";
 
 	private static final String BPEL_DEPLOY_DESCRIPTOR_FILENAME = "bpel-deploy.xml";
@@ -377,18 +385,52 @@
 					firstDefn.addImport(imp);					
 					
 					IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
-		
+					
 					IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
 
-					if (artifactFile.exists() == false) {
-						GeneratorUtil.createFolder(artifactFile.getParent());
+					copySchema(file, artifactFile, bpelFolderPath);
+				}
+			}
+		}
+	}
 
-						artifactFile.create(null, true,
-								new org.eclipse.core.runtime.NullProgressMonitor());
-					}
+	protected void copySchema(IFile srcXSDFile, IFile targetXSDFile, IPath bpelFolderPath) throws Exception {
+
+		if (targetXSDFile.exists() == false) {
+			GeneratorUtil.createFolder(targetXSDFile.getParent());
+
+			targetXSDFile.create(null, true,
+					new org.eclipse.core.runtime.NullProgressMonitor());
+		}
+		
+		targetXSDFile.setContents(srcXSDFile.getContents(), true, false,
+					new org.eclipse.core.runtime.NullProgressMonitor());
+		
+		// Check XSD for further 'include' statements
+		DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+		fact.setNamespaceAware(true);
+
+		DocumentBuilder builder=fact.newDocumentBuilder();
+		org.w3c.dom.Document doc=builder.parse(srcXSDFile.getContents());
+
+		org.w3c.dom.NodeList nl=doc.getElementsByTagNameNS(XML_SCHEMA, INCLUDE_ELEMENT);
+		
+		for (int i=0; i < nl.getLength(); i++) {
+			org.w3c.dom.Node includeNode=nl.item(i);
+			
+			if (includeNode instanceof org.w3c.dom.Element) {
+				String schemaLocation=((org.w3c.dom.Element)includeNode).getAttribute(SCHEMA_LOCATION_ATTR);
+				
+				// Check if a relative path
+				IFile file=srcXSDFile.getParent().getFile(new Path(schemaLocation));
+				
+				if (file.exists()) {
 					
-					artifactFile.setContents(file.getContents(), true, false,
-								new org.eclipse.core.runtime.NullProgressMonitor());
+					IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+					
+					IFile artifactFile=file.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+					copySchema(file, artifactFile, bpelFolderPath);
 				}
 			}
 		}



More information about the savara-commits mailing list