1710 Rebase - Second Attempt
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / XQueryScriptTask.java
index e42806e..31da737 100644 (file)
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;\r
 import java.math.BigDecimal;\r
 import java.net.URI;\r
+import java.util.Iterator;\r
 \r
 import javax.xml.transform.stream.StreamSource;\r
 \r
@@ -32,6 +33,7 @@ import org.camunda.bpm.engine.ProcessEngineException;
 import org.camunda.bpm.engine.delegate.DelegateExecution;\r
 //import java.util.logging.Logger;\r
 import org.camunda.bpm.engine.delegate.Expression;\r
+\r
 import org.openecomp.mso.logger.MessageEnum;\r
 import org.openecomp.mso.logger.MsoLogger;\r
 \r
@@ -95,9 +97,11 @@ public class XQueryScriptTask extends BaseTask {
                String[] atomicInputVariableArray = (theAtomicInputVariables == null)\r
                        ? new String[0] : theAtomicInputVariables.split(",[ ]*");\r
 \r
-        if (shouldFail(execution)) {\r
-            throw new ProcessEngineException(getTaskName() + " Failed");\r
-        }\r
+               Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");\r
+\r
+               if (shouldFail != null && shouldFail) {\r
+                       throw new ProcessEngineException(getClass().getSimpleName() + " Failed");\r
+               }\r
 \r
                // The script could be compiled once and reused, but we are reading it\r
                // and compiling it every time.\r
@@ -186,7 +190,9 @@ public class XQueryScriptTask extends BaseTask {
 \r
                // Evaluate the query and collect the output.\r
                StringBuilder output = new StringBuilder();\r
-               for(XdmItem item : evaluator) {\r
+               Iterator<XdmItem> xdmItems = evaluator.iterator();\r
+               while (xdmItems.hasNext()) {\r
+                       XdmItem item = xdmItems.next();\r
                        \r
                        if (msoLogger.isDebugEnabled()) {\r
                                msoLogger.debug("XQuery result item = " + item);\r
@@ -212,13 +218,26 @@ public class XQueryScriptTask extends BaseTask {
         */\r
        private XQueryExecutable compile(XQueryCompiler compiler, String resource)\r
                        throws Exception {\r
-               try(InputStream xqStream = getClass().getResourceAsStream(resource)) {\r
+               InputStream xqStream = null;\r
+               try {\r
+                       xqStream = getClass().getResourceAsStream(resource);\r
 \r
                        if (xqStream == null) {\r
                                throw new IOException("Resource not found: " + resource);\r
                        }\r
 \r
-                       return compiler.compile(xqStream);\r
+                       XQueryExecutable executable = compiler.compile(xqStream);\r
+                       xqStream.close();\r
+                       xqStream = null;\r
+                       return executable;\r
+               } finally {\r
+                       if (xqStream != null) {\r
+                               try {\r
+                                       xqStream.close();\r
+                               } catch (Exception e) {\r
+                                       // Do nothing\r
+                               }\r
+                       }\r
                }\r
        }\r
 }
\ No newline at end of file