Author: guixl
Date: Tue Jul 20 14:23:46 2010
New Revision: 965859

URL: http://svn.apache.org/viewvc?rev=965859&view=rev
Log:
improve Apache Commons SCXML runtime class template

Modified:
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/debug/CommonsSCXMLEngine.java
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/debug/CommonsSCXMLEngine.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/debug/CommonsSCXMLEngine.java?rev=965859&r1=965858&r2=965859&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/debug/CommonsSCXMLEngine.java
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/debug/CommonsSCXMLEngine.java
 Tue Jul 20 14:23:46 2010
@@ -1,4 +1,4 @@
-package guixl;
+
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -17,10 +17,10 @@ import org.apache.commons.scxml.model.Mo
 import org.apache.commons.scxml.model.SCXML;
 import org.xml.sax.SAXException;
 
-public class HelloWorld {
+public class $CLASS_NAME$ {
 
        /**
-        * @param args
+        * Apache Commons SCXML engine 
         */
        public static void main(String[] args) {
                List customActions = new ArrayList();
@@ -32,8 +32,8 @@ public class HelloWorld {
         */
         SCXML scxml=null;
         try {
-                       scxml =  
SCXMLParser.parse(HelloWorld.class.getClassLoader().
-                               getResource("guixl/hello-world.xml"), null, 
customActions);
+                       scxml =  
SCXMLParser.parse($CLASS_NAME$.class.getClassLoader().
+                               getResource("$SCXML_DOCUMENT_RESOURCE$"), null, 
customActions);
                        SCXMLExecutor engine = new SCXMLExecutor(new 
JexlEvaluator(), new SimpleDispatcher(),
                            new SimpleErrorReporter());
                engine.setStateMachine(scxml);

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java?rev=965859&r1=965858&r2=965859&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java
 Tue Jul 20 14:23:46 2010
@@ -16,9 +16,11 @@
  */
 package org.apache.commons.scxml.modeling.diagram.part;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.LinkedList;
 import java.util.List;
@@ -73,6 +75,10 @@ public class ModelingNewDebugFileWizard 
         * model file
         */
        private IFile modelFile;
+       
+       private String testCaseClassName;
+       
+       private IPath filePath;
 
        /**
         * @generated
@@ -92,8 +98,8 @@ public class ModelingNewDebugFileWizard 
                myFileCreationPage.setDescription(NLS.bind(
                                
Messages.ModelingNewScxmlFileWizard_CreationPageDescription,
                                ServiceTemplateEditPart.MODEL_ID));
-               IPath filePath;
-               String fileName = 
domainModelURI.trimFileExtension().lastSegment();
+               
+               
testCaseClassName=domainModelURI.trimFileExtension().lastSegment()+"TestCase";
                if (domainModelURI.isPlatformResource()) {
                        filePath = new Path(domainModelURI.trimSegments(1)
                                        .toPlatformString(true));
@@ -105,7 +111,7 @@ public class ModelingNewDebugFileWizard 
                }
                myFileCreationPage.setContainerFullPath(filePath);
                myFileCreationPage.setFileName(ModelingDiagramEditorUtil
-                               .getUniqueFileName(filePath, fileName, 
"java")); //$NON-NLS-1$
+                               .getUniqueFileName(filePath, testCaseClassName, 
"java")); //$NON-NLS-1$
 
                diagramRootElementSelectionPage = new 
DiagramRootElementSelectionPage(
                                
Messages.ModelingNewScxmlFileWizard_RootSelectionPageName);
@@ -133,6 +139,26 @@ public class ModelingNewDebugFileWizard 
                }
                return baos.toString();
        }
+       
+       /**
+        * 
+        * @param str
+        * @return change string to InputStream
+        */
+       public InputStream string2InputStream(String str) {
+               ByteArrayInputStream stream = null;
+               try {
+                       stream = new 
ByteArrayInputStream(str.getBytes("UTF-8"));
+               } catch (UnsupportedEncodingException e) {
+                       e.printStackTrace();
+               }
+               if (stream != null)
+                       return stream;
+               else {
+                       System.out.println("stream is null");
+                       return null;
+               }
+       }
 
        /**
         * @generated
@@ -202,8 +228,15 @@ public class ModelingNewDebugFileWizard 
                        try {
                                InputStream 
fileTemplate=this.getClass().getClassLoader().getResourceAsStream("debug/CommonsSCXMLEngine.java");
                                monitor.worked(1);
-                               debugClassFile.setContents(fileTemplate, 1, 
null);
-                               monitor.worked(8);
+                               String content=inputStream2String(fileTemplate);
+                               content=content.replace("$CLASS_NAME$", 
testCaseClassName);
+                               monitor.worked(1);
+                               String 
wholePath=filePath+"/"+testCaseClassName+".xml";
+                               String 
scxmlPath=wholePath.substring(wholePath.indexOf("/", 1));
+                               
content=content.replace("$SCXML_DOCUMENT_RESOURCE$", scxmlPath);
+                               monitor.worked(1);
+                               
debugClassFile.setContents(string2InputStream(content), 1, null);
+                               monitor.worked(7);
                                
                                // get target list by regular expression
                                /*ScxmlExportStreamHandlerAction shc = new 
ScxmlExportStreamHandlerAction(
@@ -235,6 +268,9 @@ public class ModelingNewDebugFileWizard 
                                monitor.done();
                        } catch (CoreException e) {
                                e.printStackTrace();
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
                        }
                }
        }


Reply via email to