From ec37fa99ebce77d9296d02a84a773c287188520c Mon Sep 17 00:00:00 2001 From: wwang Date: Mon, 12 Mar 2012 03:46:39 +0000 Subject: [PATCH] fix Bug TDI-18966: Never change the original lookup information object state git-svn-id: http://talendforge.org/svn/tos/trunk@79598 f6f1c999-d317-4740-80b0-e6d1abc6f99e --- .../java/routines/system/Document.java | 8 +++- .../java/routines/system/DocumentToFlat.java | 41 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/org.talend.librariesmanager/resources/java/routines/system/Document.java b/org.talend.librariesmanager/resources/java/routines/system/Document.java index ccfbe563b1..dd6bfc9a3c 100644 --- a/org.talend.librariesmanager/resources/java/routines/system/Document.java +++ b/org.talend.librariesmanager/resources/java/routines/system/Document.java @@ -67,6 +67,12 @@ public class Document implements java.io.Serializable{ docToFlat.setOriginalLoop(loopXPath); docToFlat.setXmlNameSpaceMap(nsMapping); docToFlat.flatForLookup(); + if(docToFlat.isLoopChanged()) {//never change the original lookup information object state + lookupInfo = docToFlat.getLookupInfo(); + xpathOfResults = docToFlat.getXpathOfResults(); + xpathToTypeMap = docToFlat.getXpathToTypeMap(); + xpathToPatternMap = docToFlat.getXpathToPatternMap(); + } java.util.List nodes = docToFlat.getNodes(); for (org.dom4j.tree.AbstractNode node : nodes) { @@ -111,8 +117,6 @@ public class Document implements java.io.Serializable{ } } - //reset lookup info - lookupInfo.clear(); //set resultset int count = result.size(); if(count>0) { diff --git a/org.talend.librariesmanager/resources/java/routines/system/DocumentToFlat.java b/org.talend.librariesmanager/resources/java/routines/system/DocumentToFlat.java index 84fbe4c1b9..236cde9dd2 100644 --- a/org.talend.librariesmanager/resources/java/routines/system/DocumentToFlat.java +++ b/org.talend.librariesmanager/resources/java/routines/system/DocumentToFlat.java @@ -166,6 +166,8 @@ public class DocumentToFlat { private Map xpathOfResults; private Map xpathToTypeMap; private Map xpathToPatternMap; + + private boolean loopChanged = false; public DocumentToFlat(Map lookupInfo, Map xpathOfResults, @@ -186,41 +188,60 @@ public class DocumentToFlat { flatForLookup(); } else { if(currentLoop != originalLoop) {//not point to the same string + loopChanged = true; reset(); } } } private void reset() { - resetMapRelativeXpathKey(lookupInfo); - resetMapRelativeXpathKey(xpathToTypeMap); - resetMapRelativeXpathKey(xpathToPatternMap); - resetMapRelativeXpathValue(xpathOfResults); + lookupInfo = resetMapRelativeXpathKey(lookupInfo); + xpathToTypeMap = resetMapRelativeXpathKey(xpathToTypeMap); + xpathToPatternMap = resetMapRelativeXpathKey(xpathToPatternMap); + xpathOfResults = resetMapRelativeXpathValue(xpathOfResults); } - private void resetMapRelativeXpathKey(Map source) { + private Map resetMapRelativeXpathKey(Map source) { Map content = new HashMap(); for(String key : source.keySet()) { String newKey = resetRelativeXPath(key); content.put(newKey, source.get(key)); } - source.clear(); - source.putAll(content); + return content; } - private void resetMapRelativeXpathValue(Map source) { + private Map resetMapRelativeXpathValue(Map source) { Map content = new HashMap(); for(String key : source.keySet()) { String value = source.get(key); String newValue = resetRelativeXPath(value); content.put(key, newValue); } - source.clear(); - source.putAll(content); + return content; } public List getNodes() { return nodes; } + public Map getLookupInfo() { + return lookupInfo; + } + + public Map getXpathOfResults() { + return xpathOfResults; + } + + public Map getXpathToTypeMap() { + return xpathToTypeMap; + } + + public Map getXpathToPatternMap() { + return xpathToPatternMap; + } + + public boolean isLoopChanged() { + return loopChanged; + } + }