Fix for Bug 382530 - DBWS: infinite loop when package name is prepended to type name
Reviewed by:  matt.macivor@oracle.com
Tests:  (EclipseLink) PrependedPackageTestSuite
diff --git a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.java b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.java
index e6da868..39da470 100644
--- a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.java
+++ b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.java
@@ -18,6 +18,7 @@
 import java.util.List;

 import java.util.HashMap;

 import java.util.Map;

+import java.util.StringTokenizer;

 

 //metadata imports

 import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType;

@@ -2451,10 +2452,19 @@
       }

     }

       if (dataType == null && localTypes != null) {

+          // spec may need schema/catalog stripped off

+          String tName = spec;

+          StringTokenizer stok = new StringTokenizer(spec, ".");

+          while (stok.hasMoreTokens()) {

+              tName = stok.nextToken();

+          }

           for (String typeName : localTypes.keySet()) {

               if (typeName.equals(spec)) {

                   dataType = localTypes.get(spec);

                   break;

+              } else if (typeName.equals(tName)) {

+                  dataType = localTypes.get(tName);

+                  break;

               }

           }

       }

@@ -3085,15 +3095,15 @@
     dataType = typeSpec();

       ArgumentType returnType = new ArgumentType(null);

       returnType.setDirection(ArgumentTypeDirection.RETURN);

+      // may need to strip off schema/catalog name

       if (dataType.getTypeName().contains(".")) {

           String dataTypeName = dataType.getTypeName();

           int dotIdx = dataTypeName.indexOf(".");

           String namePart1 = dataTypeName.substring(0, dotIdx);

           String namePart2 = dataTypeName.substring(dotIdx+1, dataTypeName.length());

-          if (namePart1.equals(functionType.getSchema())) {

+          if (namePart1.equals(functionType.getCatalogName()) || namePart1.equals(functionType.getSchema())) {

               dataType.setTypeName(namePart2);

-          }

-          else if (schemaPatterns != null) {

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       dataType.setTypeName(namePart2);

@@ -3137,15 +3147,15 @@
     default:

       ;

     }

+      // may need to strip off schema/catalog name

       if (argumentDataType.getTypeName().contains(".")) {

           String argumentDataTypeName = argumentDataType.getTypeName();

           int dotIdx = argumentDataTypeName.indexOf(".");

           String namePart1 = argumentDataTypeName.substring(0, dotIdx);

           String namePart2 = argumentDataTypeName.substring(dotIdx+1, argumentDataTypeName.length());

-          if (namePart1.equals(procedureType.getSchema())) {

+          if (namePart1.equals(procedureType.getCatalogName()) || namePart1.equals(procedureType.getSchema())) {

               argumentDataType.setTypeName(namePart2);

-          }

-          else if (schemaPatterns != null) {

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       argumentDataType.setTypeName(namePart2);

@@ -3457,9 +3467,8 @@
     catch(LookaheadSuccess ls) { return true; }

   }

 

-  private boolean jj_3R_67() {

-    if (jj_scan_token(O_OPENPAREN)) return true;

-    if (jj_scan_token(S_NUMBER)) return true;

+  private boolean jj_3_11() {

+    if (jj_3R_15()) return true;

     return false;

   }

 

@@ -3484,13 +3493,13 @@
     return false;

   }

 

-  private boolean jj_3_11() {

-    if (jj_3R_15()) return true;

+  private boolean jj_3R_65() {

+    if (jj_3R_12()) return true;

     return false;

   }

 

-  private boolean jj_3R_65() {

-    if (jj_3R_12()) return true;

+  private boolean jj_3R_14() {

+    if (jj_scan_token(R_ANCHORED_ROWTYPE)) return true;

     return false;

   }

 

@@ -3505,6 +3514,11 @@
     return false;

   }

 

+  private boolean jj_3_12() {

+    if (jj_scan_token(K_NOCOPY)) return true;

+    return false;

+  }

+

   private boolean jj_3R_18() {

     Token xsp;

     xsp = jj_scanpos;

@@ -3515,8 +3529,14 @@
     return false;

   }

 

-  private boolean jj_3R_14() {

-    if (jj_scan_token(R_ANCHORED_ROWTYPE)) return true;

+  private boolean jj_3R_13() {

+    if (jj_scan_token(R_ANCHORED_TYPE)) return true;

+    return false;

+  }

+

+  private boolean jj_3R_60() {

+    if (jj_scan_token(K_VARYING)) return true;

+    if (jj_scan_token(K_ARRAY)) return true;

     return false;

   }

 

@@ -3530,38 +3550,6 @@
     return false;

   }

 

-  private boolean jj_3_12() {

-    if (jj_scan_token(K_NOCOPY)) return true;

-    return false;

-  }

-

-  private boolean jj_3R_54() {

-    if (jj_scan_token(K_NCHAR)) return true;

-    Token xsp;

-    xsp = jj_scanpos;

-    if (jj_scan_token(213)) jj_scanpos = xsp;

-    xsp = jj_scanpos;

-    if (jj_3R_82()) jj_scanpos = xsp;

-    return false;

-  }

-

-  private boolean jj_3R_13() {

-    if (jj_scan_token(R_ANCHORED_TYPE)) return true;

-    return false;

-  }

-

-  private boolean jj_3R_79() {

-    if (jj_scan_token(O_OPENPAREN)) return true;

-    if (jj_scan_token(S_NUMBER)) return true;

-    return false;

-  }

-

-  private boolean jj_3R_60() {

-    if (jj_scan_token(K_VARYING)) return true;

-    if (jj_scan_token(K_ARRAY)) return true;

-    return false;

-  }

-

   private boolean jj_3_10() {

     if (jj_3R_12()) return true;

     Token xsp;

@@ -3583,6 +3571,22 @@
     return false;

   }

 

+  private boolean jj_3R_54() {

+    if (jj_scan_token(K_NCHAR)) return true;

+    Token xsp;

+    xsp = jj_scanpos;

+    if (jj_scan_token(213)) jj_scanpos = xsp;

+    xsp = jj_scanpos;

+    if (jj_3R_82()) jj_scanpos = xsp;

+    return false;

+  }

+

+  private boolean jj_3R_79() {

+    if (jj_scan_token(O_OPENPAREN)) return true;

+    if (jj_scan_token(S_NUMBER)) return true;

+    return false;

+  }

+

   private boolean jj_3_7() {

     if (jj_3R_9()) return true;

     return false;

@@ -3594,12 +3598,6 @@
     return false;

   }

 

-  private boolean jj_3R_77() {

-    if (jj_scan_token(O_OPENPAREN)) return true;

-    if (jj_scan_token(S_NUMBER)) return true;

-    return false;

-  }

-

   private boolean jj_3R_10() {

     Token xsp;

     xsp = jj_scanpos;

@@ -3611,6 +3609,12 @@
     return false;

   }

 

+  private boolean jj_3R_77() {

+    if (jj_scan_token(O_OPENPAREN)) return true;

+    if (jj_scan_token(S_NUMBER)) return true;

+    return false;

+  }

+

   private boolean jj_3R_53() {

     if (jj_scan_token(K_CHARACTER)) return true;

     Token xsp;

@@ -3637,6 +3641,11 @@
     return false;

   }

 

+  private boolean jj_3R_61() {

+    if (jj_scan_token(O_DOT)) return true;

+    return false;

+  }

+

   private boolean jj_3R_52() {

     if (jj_scan_token(K_VARCHAR2)) return true;

     Token xsp;

@@ -3661,11 +3670,6 @@
     return false;

   }

 

-  private boolean jj_3R_61() {

-    if (jj_scan_token(O_DOT)) return true;

-    return false;

-  }

-

   private boolean jj_3R_78() {

     if (jj_scan_token(K_CHARACTER)) return true;

     if (jj_scan_token(K_SET)) return true;

@@ -3735,6 +3739,14 @@
     return false;

   }

 

+  private boolean jj_3R_12() {

+    if (jj_3R_17()) return true;

+    Token xsp;

+    xsp = jj_scanpos;

+    if (jj_3R_61()) jj_scanpos = xsp;

+    return false;

+  }

+

   private boolean jj_3R_21() {

     if (jj_scan_token(K_BINARY_DOUBLE)) return true;

     return false;

@@ -3745,6 +3757,11 @@
     return false;

   }

 

+  private boolean jj_3_13() {

+    if (jj_scan_token(K_OUT)) return true;

+    return false;

+  }

+

   private boolean jj_3R_19() {

     if (jj_scan_token(K_BINARY_INTEGER)) return true;

     return false;

@@ -3880,25 +3897,22 @@
     return false;

   }

 

-  private boolean jj_3R_12() {

-    if (jj_3R_17()) return true;

-    Token xsp;

-    xsp = jj_scanpos;

-    if (jj_3R_61()) jj_scanpos = xsp;

-    return false;

-  }

-

-  private boolean jj_3_13() {

-    if (jj_scan_token(K_OUT)) return true;

-    return false;

-  }

-

   private boolean jj_3R_74() {

     if (jj_scan_token(O_OPENPAREN)) return true;

     if (jj_scan_token(S_NUMBER)) return true;

     return false;

   }

 

+  private boolean jj_3R_64() {

+    if (jj_scan_token(S_QUOTED_IDENTIFIER)) return true;

+    return false;

+  }

+

+  private boolean jj_3R_63() {

+    if (jj_scan_token(S_IDENTIFIER)) return true;

+    return false;

+  }

+

   private boolean jj_3R_50() {

     if (jj_scan_token(K_CHAR)) return true;

     Token xsp;

@@ -3917,24 +3931,6 @@
     return false;

   }

 

-  private boolean jj_3R_64() {

-    if (jj_scan_token(S_QUOTED_IDENTIFIER)) return true;

-    return false;

-  }

-

-  private boolean jj_3R_63() {

-    if (jj_scan_token(S_IDENTIFIER)) return true;

-    return false;

-  }

-

-  private boolean jj_3R_48() {

-    if (jj_scan_token(K_UROWID)) return true;

-    Token xsp;

-    xsp = jj_scanpos;

-    if (jj_3R_74()) jj_scanpos = xsp;

-    return false;

-  }

-

   private boolean jj_3R_17() {

     Token xsp;

     xsp = jj_scanpos;

@@ -3953,11 +3949,32 @@
     return false;

   }

 

+  private boolean jj_3R_62() {

+    if (jj_scan_token(K_OUT)) return true;

+    return false;

+  }

+

+  private boolean jj_3R_48() {

+    if (jj_scan_token(K_UROWID)) return true;

+    Token xsp;

+    xsp = jj_scanpos;

+    if (jj_3R_74()) jj_scanpos = xsp;

+    return false;

+  }

+

   private boolean jj_3R_47() {

     if (jj_scan_token(K_ROWID)) return true;

     return false;

   }

 

+  private boolean jj_3_14() {

+    if (jj_scan_token(R_IN)) return true;

+    Token xsp;

+    xsp = jj_scanpos;

+    if (jj_3_13()) jj_scanpos = xsp;

+    return false;

+  }

+

   private boolean jj_3_4() {

     if (jj_scan_token(K_CONSTANT)) return true;

     return false;

@@ -4001,13 +4018,18 @@
     return false;

   }

 

-  private boolean jj_3R_41() {

-    if (jj_scan_token(K_SIMPLE_FLOAT)) return true;

+  private boolean jj_3R_15() {

+    Token xsp;

+    xsp = jj_scanpos;

+    if (jj_3_14()) {

+    jj_scanpos = xsp;

+    if (jj_3R_62()) return true;

+    }

     return false;

   }

 

-  private boolean jj_3R_62() {

-    if (jj_scan_token(K_OUT)) return true;

+  private boolean jj_3R_41() {

+    if (jj_scan_token(K_SIMPLE_FLOAT)) return true;

     return false;

   }

 

@@ -4037,14 +4059,6 @@
     return false;

   }

 

-  private boolean jj_3_14() {

-    if (jj_scan_token(R_IN)) return true;

-    Token xsp;

-    xsp = jj_scanpos;

-    if (jj_3_13()) jj_scanpos = xsp;

-    return false;

-  }

-

   private boolean jj_3R_37() {

     if (jj_scan_token(K_REAL)) return true;

     return false;

@@ -4061,16 +4075,6 @@
     return false;

   }

 

-  private boolean jj_3R_15() {

-    Token xsp;

-    xsp = jj_scanpos;

-    if (jj_3_14()) {

-    jj_scanpos = xsp;

-    if (jj_3R_62()) return true;

-    }

-    return false;

-  }

-

   private boolean jj_3_3() {

     if (jj_3R_8()) return true;

     return false;

@@ -4197,6 +4201,12 @@
     return false;

   }

 

+  private boolean jj_3R_9() {

+    if (jj_scan_token(K_RECORD)) return true;

+    if (jj_scan_token(O_OPENPAREN)) return true;

+    return false;

+  }

+

   private boolean jj_3R_57() {

     if (jj_scan_token(K_NATIONAL)) return true;

     Token xsp;

@@ -4507,12 +4517,6 @@
     return false;

   }

 

-  private boolean jj_3R_9() {

-    if (jj_scan_token(K_RECORD)) return true;

-    if (jj_scan_token(O_OPENPAREN)) return true;

-    return false;

-  }

-

   private boolean jj_3R_68() {

     if (jj_scan_token(O_OPENPAREN)) return true;

     if (jj_scan_token(S_NUMBER)) return true;

@@ -4533,6 +4537,12 @@
     return false;

   }

 

+  private boolean jj_3R_67() {

+    if (jj_scan_token(O_OPENPAREN)) return true;

+    if (jj_scan_token(S_NUMBER)) return true;

+    return false;

+  }

+

   /** Generated Token Manager. */

   public DDLParserTokenManager token_source;

   JavaCharStream jj_input_stream;

diff --git a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jj b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jj
index afc7975..6dd2682 100644
--- a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jj
+++ b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jj
@@ -43,6 +43,7 @@
 import java.util.List;

 import java.util.HashMap;

 import java.util.Map;

+import java.util.StringTokenizer;

 

 //metadata imports

 import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType;

@@ -1161,10 +1162,19 @@
     )

     {

       if (dataType == null && localTypes != null) {

+          // spec may need schema/catalog stripped off

+          String tName = spec;

+          StringTokenizer stok = new StringTokenizer(spec, ".");

+          while (stok.hasMoreTokens()) {

+              tName = stok.nextToken();

+          }

           for (String typeName : localTypes.keySet()) {

               if (typeName.equals(spec)) {

                   dataType = localTypes.get(spec);

                   break;

+              } else if (typeName.equals(tName)) {

+                  dataType = localTypes.get(tName);

+                  break;

               }

           }

       }

@@ -1581,15 +1591,15 @@
     {

       ArgumentType returnType = new ArgumentType(null);

       returnType.setDirection(ArgumentTypeDirection.RETURN);

+      // may need to strip off schema/catalog name

       if (dataType.getTypeName().contains(".")) {

           String dataTypeName = dataType.getTypeName();

           int dotIdx = dataTypeName.indexOf(".");

           String namePart1 = dataTypeName.substring(0, dotIdx);

           String namePart2 = dataTypeName.substring(dotIdx+1, dataTypeName.length());

-          if (namePart1.equals(functionType.getSchema())) {

+          if (namePart1.equals(functionType.getCatalogName()) || namePart1.equals(functionType.getSchema())) {

               dataType.setTypeName(namePart2);

-          }

-          else if (schemaPatterns != null) {

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       dataType.setTypeName(namePart2);

@@ -1617,14 +1627,15 @@
     s=OracleObjectName() [ LOOKAHEAD(2) (direction=direction()) ]

         [  LOOKAHEAD(2) <K_NOCOPY> ] argumentDataType=typeSpec() [ defaultAssignment=argumentDefaultAssignment() ]

     {

+      // may need to strip off schema/catalog name

       if (argumentDataType.getTypeName().contains(".")) {

           String argumentDataTypeName = argumentDataType.getTypeName();

           int dotIdx = argumentDataTypeName.indexOf(".");

           String namePart1 = argumentDataTypeName.substring(0, dotIdx);

           String namePart2 = argumentDataTypeName.substring(dotIdx+1, argumentDataTypeName.length());

-          if (namePart1.equals(procedureType.getSchema())) {

-              argumentDataType.setTypeName(namePart2);
          }

-          else if (schemaPatterns != null) {

+          if (namePart1.equals(procedureType.getCatalogName()) || namePart1.equals(procedureType.getSchema())) {

+              argumentDataType.setTypeName(namePart2);

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       argumentDataType.setTypeName(namePart2);

diff --git a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jjt b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jjt
index 00f0eea..afe3999 100644
--- a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jjt
+++ b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParser.jjt
@@ -42,6 +42,7 @@
 import java.util.List;

 import java.util.HashMap;

 import java.util.Map;

+import java.util.StringTokenizer;

 

 //metadata imports

 import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType;

@@ -1157,10 +1158,19 @@
     )

     {

       if (dataType == null && localTypes != null) {

+          // spec may need schema/catalog stripped off

+          String tName = spec;

+          StringTokenizer stok = new StringTokenizer(spec, ".");

+          while (stok.hasMoreTokens()) {

+              tName = stok.nextToken();

+          }

           for (String typeName : localTypes.keySet()) {

               if (typeName.equals(spec)) {

                   dataType = localTypes.get(spec);

                   break;

+              } else if (typeName.equals(tName)) {

+                  dataType = localTypes.get(tName);

+                  break;

               }

           }

       }

@@ -1577,15 +1587,15 @@
     {

       ArgumentType returnType = new ArgumentType(null);

       returnType.setDirection(ArgumentTypeDirection.RETURN);

+      // may need to strip off schema/catalog name

       if (dataType.getTypeName().contains(".")) {

           String dataTypeName = dataType.getTypeName();

           int dotIdx = dataTypeName.indexOf(".");

           String namePart1 = dataTypeName.substring(0, dotIdx);

           String namePart2 = dataTypeName.substring(dotIdx+1, dataTypeName.length());

-          if (namePart1.equals(functionType.getSchema())) {

+          if (namePart1.equals(functionType.getCatalogName()) || namePart1.equals(functionType.getSchema())) {

               dataType.setTypeName(namePart2);

-          }

-          else if (schemaPatterns != null) {

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       dataType.setTypeName(namePart2);

@@ -1613,14 +1623,15 @@
     s=OracleObjectName() [ LOOKAHEAD(2) (direction=direction()) ]

         [  LOOKAHEAD(2) <K_NOCOPY> ] argumentDataType=typeSpec() [ defaultAssignment=argumentDefaultAssignment() ]

     {

+      // may need to strip off schema/catalog name

       if (argumentDataType.getTypeName().contains(".")) {

           String argumentDataTypeName = argumentDataType.getTypeName();

           int dotIdx = argumentDataTypeName.indexOf(".");

           String namePart1 = argumentDataTypeName.substring(0, dotIdx);

           String namePart2 = argumentDataTypeName.substring(dotIdx+1, argumentDataTypeName.length());

-          if (namePart1.equals(procedureType.getSchema())) {

-              argumentDataType.setTypeName(namePart2);
          }

-          else if (schemaPatterns != null) {

+          if (namePart1.equals(procedureType.getCatalogName()) || namePart1.equals(procedureType.getSchema())) {

+              argumentDataType.setTypeName(namePart2);

+          } else if (schemaPatterns != null) {

               for (String possibleSchemaName : schemaPatterns) {

                   if (namePart1.equals(possibleSchemaName)) {

                       argumentDataType.setTypeName(namePart2);

diff --git a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParserTokenManager.java b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParserTokenManager.java
index d172194..81ad243 100644
--- a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParserTokenManager.java
+++ b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/parser/DDLParserTokenManager.java
@@ -17,6 +17,7 @@
 import java.util.List;

 import java.util.HashMap;

 import java.util.Map;

+import java.util.StringTokenizer;

 //metadata imports

 import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType;

 import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentTypeDirection;