expr);
}
newExpr.append(expr.substring(start0,start));
Transform trans = new Transform();
trans.initTokenizer(expr, start, end);
boolean isAtStart=true, hasValidLHS=false;
Token t;
while((t=trans.nextToken(isAtStart,hasValidLHS))!=null){
int id=t.getId();
if(id==Transform.t_End)break;
if(id==Transform.t_Unknown){
return null;
}
if(id==Transform.t_DE){
//String oldDeName=t.getStr();
// if oldDeName does not contains instance tag
String oldDe0=t.getStr(),newDe0=mapTable.get(oldDe0);
if(newDe0!=null){
newExpr.append(newDe0);
} else {
StringTokenizer tk=new StringTokenizer(oldDe0,"#.",true);
String str="";
StringBuilder oldDe=new StringBuilder();
String newDe=""; // oldDe0, newDe0 have '#', but oldDe, newDe don't
boolean bPrompt=false;
while(tk.hasMoreTokens()){
String token=tk.nextToken();
if(token.charAt(0)=='#'){
StringBuilder tag=new StringBuilder("#"); // tag is the substring between '#' and '.' including '#' and '.'
while(tk.hasMoreTokens()){
token=tk.nextToken();
tag.append(token);
if(token.charAt(0)=='.')break;
}
oldDe.append('.');
int last_len=newDe.length();
String newDe_tmp=mapTable.get("["+oldDe+"]");
if(newDe_tmp==null){
bPrompt=true;
continue;
} else if(newDe_tmp.charAt(0)=='['){
newDe=newDe_tmp.substring(1,newDe_tmp.length()-1);
}
int len=newDe.length();
if(newDe.charAt(len-1)=='.'){ // this subnode terminate with '.'
str+=newDe.substring(last_len,len-1)+tag;
}
else {// subnode terminate with '$'
str+=newDe.substring(last_len,len);
}
}
else {
oldDe.append(token);
}
}
int last_len=newDe.length();
newDe=mapTable.get(oldDe.toString());
if(newDe!=null){
if(last_len<newDe.length()){
str+=newDe.substring(last_len,newDe.length());
}
if(bPrompt){
String title = "Target: "+targetDE;
str=migration.manualConversion(title, oldDe0, str);
}
if(str!=null)newExpr.append(str);
}
if(str==null||newDe==null) {
String title = "Target: "+targetDE;
String err_message =
"Failed to translate node: "+oldDe0+
"\nin the following expression:";
String question = "Do you want to skip the migration for this mapping?";
if(migration.checkToContinue(title,err_message,expr,question)){
return null;
}
else {
throw new ScriptException(
"Error in migrating the mapping\n"+
"\nThe target node: "+ targetDE +
"\nFailed to translate the node:\n"+oldDe0+
"\nin the expression\n" + expr);
}
}
}
} else {
newExpr.append(t.getStr());
}
if(id!=Transform.t_Space && id!=Transform.t_Comment){
hasValidLHS=(id==Transform.t_Set||id==Transform.t_GlobalDE||id==Transform.t_LocalDE);
isAtStart=(id==Transform.t_Set||id==Transform.t_LP||id==Transform.t_Fcn||
id==Transform.t_And||id==Transform.t_Or||id==Transform.t_NE||id==Transform.t_EQ||
id==Transform.t_GT||id==Transform.t_GE||id==Transform.t_LT||id==Transform.t_LE||id==Transform.t_Comma||id==Transform.t_Semicolon);
trans.setLastId(id);
}
}
newExpr.append(ScriptConstants.END_TRANS);
start0=end+ScriptConstants.END_TRANS_LENGTH;
}