FBProcedureParam callParam = procedureCall.addParam(paramPosition, buffer.toString());  if (callParam.isParam()) { paramCount++; callParam.setIndex(paramCount);
if(null == procedureCall.getName() && !isNameProcessed) { procedureCall.setName(buffer.toString()); } else { FBProcedureParam callParam = procedureCall.addParam(paramPosition, buffer.toString());  if (callParam.isParam()) { paramCount++; callParam.setIndex(paramCount); }
    public FBProcedureCall parseCall(String sql) throws FBSQLException {            	sql = cleanUpCall(sql);                procedureCall = new FBProcedureCall();                isExecuteWordProcessed = false;        isProcedureWordProcessed = false;        isCallWordProcessed = false;        isNameProcessed = false;                isFirstOutParam = false;                paramCount = 0;        paramPosition = 0;                setState(NORMAL_STATE);                char[] sqlbuff = sql.toCharArray();        StringBuffer buffer = new StringBuffer();        StringBuffer escape = new StringBuffer();                 for(int i = 0; i < sqlbuff.length; i++) {             switchState(sqlbuff[i]);             if (isInState(NORMAL_STATE)) {                                  // if we have an equal sign, most likely {? = call ...}                 // syntax is used (there's hardly any place for this sign                 // in procedure parameters). but to be sure, we check if                  // no brace is open and if buffer contains only '?'                 if (sqlbuff[i] == '=') {                                          if (openBraceCount <= 0) {                                              String token = buffer.toString().trim();                             if ("?".equals(token) && !isFirstOutParam && !isNameProcessed) {                                                          FBProcedureParam param =                                  procedureCall.addParam(paramPosition, token);                                                          paramCount++;                             param.setIndex(paramCount);                                                          isFirstOutParam = true;                             paramPosition++;                                                          buffer = new StringBuffer();                             continue;                         }                     }                 }                                      buffer.append(sqlbuff[i]);                              } else             if (isInState(SPACE_STATE)) {                                  if (buffer.length() == 0) {                     setState(NORMAL_STATE);                     continue;                 }                                  if (openBraceCount > 0) {                     buffer.append(sqlbuff[i]);                     setState(NORMAL_STATE);                     continue;                 }                                  String token = buffer.toString().trim();                 // if procedure name was not yet processed, process                 // the token; we look for the sequence EXECUTE PROCEDURE <name>                 // otherwise go into normal state to enable next transitions.                 if (!isNameProcessed) {                     boolean tokenProcessed = processToken(token);                     if (tokenProcessed)                     	buffer = new StringBuffer();                 } else {                     buffer.append(sqlbuff[i]);                     setState(NORMAL_STATE);                 }                              } else             if (isInState(BRACE_STATE)) {                                  // if we have an opening brace and we already processed                 // EXECUTE PROCEDURE words, but still do not have procedure                 // name set, we can be sure that buffer contains procedure                  // name.                                  boolean isProcedureName =                      sqlbuff[i] == '(' &&                     isCallKeywordProcessed() &&                     !isNameProcessed;                                  if (isProcedureName) {                     String token = buffer.toString().trim();                                          if ("".equals(token))                         throw new FBSQLParseException(                             "Procedure name is empty.");                                          procedureCall.setName(token);                     isNameProcessed = true;                                          buffer = new StringBuffer();                                      } else {                     buffer.append(sqlbuff[i]);                                      if (sqlbuff[i] == '(')                         openBraceCount++;                     else                         openBraceCount--;                 }                                  setState(NORMAL_STATE);                              } else             if (isInState(CURLY_BRACE_STATE)) {                                buffer.append(sqlbuff[i]);                setState(NORMAL_STATE);                             } else             if (isInState(COMMA_STATE)) {                                  if (openBraceCount > 0) {                     buffer.append(sqlbuff[i]);                     continue;                 }                                  String param = processParam(buffer.toString());                 buffer = new StringBuffer();                                  FBProcedureParam callParam =                      procedureCall.addParam(paramPosition, param);                                  if (callParam.isParam()) {                     paramCount++;                     callParam.setIndex(paramCount);                 }                                  paramPosition++;                                  setState(NORMAL_STATE);                              } else             if (isInState(LITERAL_STATE))                 buffer.append(sqlbuff[i]);         }         // remove spaces at the end         while(Character.isSpaceChar(buffer.charAt(0)))             buffer.deleteCharAt(0);         // if buffer ends with ')', remove it         // it should match an opening brace right after the procedure         // name, and we assume that all syntax check was already done.         if (buffer.charAt(buffer.length() - 1) == ')')             buffer.deleteCharAt(buffer.length() - 1);                  // if there's something in the buffer, treat it as last param         if (buffer.length() > 0) {             FBProcedureParam callParam =                  procedureCall.addParam(paramPosition, buffer.toString());                          if (callParam.isParam()) {                 paramCount++;                 callParam.setIndex(paramCount);             }         }                 return procedureCall;    }