Author: samindaw
Date: Mon Aug 19 01:51:46 2013
New Revision: 1515255

URL: http://svn.apache.org/r1515255
Log:
array split for foreach using delimeter and consideration of using quotes

Modified:
    
airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
    
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/InterpreterUtil.java

Modified: 
airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java?rev=1515255&r1=1515254&r2=1515255&view=diff
==============================================================================
--- 
airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
 (original)
+++ 
airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
 Mon Aug 19 01:51:46 2013
@@ -23,8 +23,41 @@ package org.apache.airavata.common.utils
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
 
 public class StringUtil {
+       
+       public static String[] getElementsFromString(String s) {
+               List<String> list=new ArrayList<String>();
+               String currentItem="";
+               String previousChar=null;
+               String delimeter=",";
+               String quote="\"";
+               boolean insideQuote=false;
+               for(int i=0;i<s.length();i++){
+                       String c=s.substring(i,i+1);
+                       if (c.equals(delimeter)){
+                               if (!insideQuote) {
+                                       list.add(currentItem);
+                                       currentItem = "";
+                               }else{
+                                       currentItem+=c;
+                               }
+                       }else if (c.equals(quote)){
+                               if (insideQuote){
+                                       insideQuote=false;
+                               }else{
+                                       insideQuote=true;
+                               }
+                       }else{
+                               currentItem+=c;
+                       }
+                       previousChar=c;
+               }
+               list.add(currentItem);
+               return list.toArray(new String[]{});
+       }
 
     /**
      * Converts object to String without worrying about null check.

Modified: 
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/InterpreterUtil.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/InterpreterUtil.java?rev=1515255&r1=1515254&r2=1515255&view=diff
==============================================================================
--- 
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/InterpreterUtil.java
 (original)
+++ 
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/InterpreterUtil.java
 Mon Aug 19 01:51:46 2013
@@ -28,6 +28,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.airavata.common.utils.StringUtil;
 import org.apache.airavata.workflow.model.exceptions.WorkflowException;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
 import org.apache.airavata.workflow.model.graph.DataPort;
@@ -81,14 +82,14 @@ public class InterpreterUtil {
             Node inputNode = inputPort.getFromNode();
             // if input node for for-each is WSNode
             if (inputNode instanceof InputNode) {
-                for (DataPort dataPort : forEachNode.getInputPorts()) {
-                    returnValForProvenance = 
InterpreterUtil.findInputFromPort(dataPort, invokerMap);
+//                for (DataPort dataPort : forEachNode.getInputPorts()) {
+                    returnValForProvenance = 
InterpreterUtil.findInputFromPort(inputPort, invokerMap);
                     if (null == returnValForProvenance) {
                         throw new WorkFlowInterpreterException("Unable to find 
input for the node:" + forEachNode.getID());
                     }
-                    String[] vals = 
returnValForProvenance.toString().split(",");
+                    String[] vals = 
StringUtil.getElementsFromString(returnValForProvenance.toString());
                     listOfValues.addAll(Arrays.asList(vals));
-                }
+//                }
             } else {
                 Invoker workflowInvoker = invokerMap.get(inputNode);
                 if (workflowInvoker != null) {
@@ -253,7 +254,7 @@ public class InterpreterUtil {
                 if (null == returnValForProvenance) {
                     throw new WorkFlowInterpreterException("Unable to find 
input for the node:" + forEachNode.getID());
                 }
-                String[] vals = returnValForProvenance.toString().split(",");
+                String[] vals = 
StringUtil.getElementsFromString(returnValForProvenance.toString());
                 inputNumbers[inputPorts.indexOf(forEachInputPort)] = 
vals.length;
             } else {
                 Invoker workflowInvoker = invokerMap.get(forEachInputNode);


Reply via email to