}
@Override
public Node expandTreeAndLookForNode(String path) throws TreeMapperException {
if(path==null||path.length()==0)return null;
Node node=m_deHashtable.get(path);
if(node!=null)return node;
if(path.charAt(0)=='$'){// jms properties
return findNode(path);
}
boolean isLeaf=path.charAt(0)!='[';
int k1=isLeaf?0:1, k2=path.length();
if(m_flat){
node=m_deHashtable.get(path);
if(node==null){
throw new TreeMapperException("Find source data element failed, path="+path);
}
return node;
}
char c;
for(;k2>k1;k2--)if((c=path.charAt(k2-1))=='.'||c=='$')break;
if(k2<k1)return null;
StringTokenizer tk=new StringTokenizer(path.substring(k1,k2),"$.",false);
Node parent=m_root;
if(parent.getName().length()>0){
if(tk.hasMoreTokens()){
if(!tk.nextToken().equals(parent.getName()))
throw new TreeMapperException(
"Find source data element failed, the root name is inconsistent with the path. root name="+parent.getName()+", path="+path);
} else {
return null;
}
}
while(tk.hasMoreTokens()){
String token=tk.nextToken();
parent.expandNode();
int k=token.indexOf('#');
if(k>0)token=token.substring(0,k);
node=parent.findChildFolder(token);
// this is the case if the element node are omitted
if(node !=null && node.isValueLeaf())return node;
if(node==null){
if(parent.isDerivedTypeHolder()||parent.isSubstitutionGroupHeader()){
// this could be a derived type or a substitution group
parent.expandHoldersTypeNode(token, token);
}
else {
parent.expandNode();
}
node=parent.findChildFolder(token);
}
if(node==null){
throw new TreeMapperException("The source data element path="+path+" is invalid.");
}
parent=node;
}
parent.expandNode();
String path0=ScriptUtils.stripInstanceTag(path);
if(!isLeaf&&path0.charAt(0)!='[')path0="["+path0+"]";
return findNode(path0);
}