Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / tools / org / apache / derby / impl / tools / ij / AttributeHolder.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/tools/org/apache/derby/impl/tools/ij/AttributeHolder.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/tools/org/apache/derby/impl/tools/ij/AttributeHolder.java
new file mode 100644 (file)
index 0000000..5ab97c4
--- /dev/null
@@ -0,0 +1,137 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.tools.ij.AttributeHolder\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+\r
+package org.apache.derby.impl.tools.ij;\r
+\r
+import org.apache.derby.iapi.reference.Attribute;\r
+import org.apache.derby.iapi.tools.i18n.LocalizedResource;\r
+import java.util.Locale;\r
+import java.util.Vector;\r
+import java.util.Properties;\r
+import java.util.Enumeration;\r
+import java.util.StringTokenizer;\r
+import java.lang.reflect.Field;\r
+import java.sql.SQLException;\r
+\r
+public class AttributeHolder {\r
+\r
+    //This is an inner class.  This class hold the details about each\r
+    //specific attribute which includes what the attribute is and\r
+    //any error found.\r
+    String name;\r
+    String value;\r
+    String token;\r
+    Vector errors = new Vector();\r
+\r
+    public String getName(){\r
+      return name;\r
+    }\r
+    public void setName(String aString){\r
+      name = aString;\r
+    }\r
+    String getValue(){\r
+      return value;\r
+    }\r
+    public void setValue(String aString){\r
+      value = aString;\r
+    }\r
+    String getToken(){\r
+      return token;\r
+    }\r
+    public void setToken(String aString){\r
+      token = aString;\r
+    }\r
+    public void addError(String aString) {\r
+      //Keep track of error message for later display.\r
+      if (!errors.contains(aString))\r
+        errors.addElement(aString);\r
+    }\r
+   public void check( Vector validProps){\r
+      checkName( validProps);\r
+      //checkValue();\r
+      displayErrors();\r
+    }\r
+    void displayErrors(){\r
+      //If no error are found then nothing is displayed.\r
+      Enumeration e = errors.elements();\r
+      //In the first line, show the exact token that was parsed from\r
+      //the URL.\r
+      if (e.hasMoreElements())\r
+        display(LocalizedResource.getMessage("TL_urlLabel1", "[", getToken(), "]"));\r
+      //Show all errors.  More than one error can be found for an attribute.\r
+      while (e.hasMoreElements()){\r
+        String aString = (String)e.nextElement();\r
+        displayIndented(aString);\r
+      }\r
+    }\r
+    void checkName( Vector validProps){\r
+      if( validProps == null)\r
+          return; // valid properties are unknown\r
+      String anAtt = getName();\r
+      try {\r
+        //Check the found name against valid names.\r
+        if (!validProps.contains(anAtt)) {\r
+          //Check for case spelling of the name.\r
+          if (validProps.contains(anAtt.toLowerCase(java.util.Locale.ENGLISH))) {\r
+            errors.addElement(LocalizedResource.getMessage("TL_incorCase"));\r
+          }\r
+          //Check if this is even a valid attribute name.\r
+          else {\r
+            errors.addElement(LocalizedResource.getMessage("TL_unknownAtt"));\r
+          }\r
+        }\r
+        else {\r
+          //This Is a valid attribute.\r
+        }\r
+      }\r
+      catch (Exception ex) {\r
+        ex.printStackTrace();\r
+      }\r
+    }\r
+    void checkValue(){\r
+      String anAtt = getName(); \r
+      String aValue = getValue();\r
+      try {\r
+        //Check all attribute that require a boolean.\r
+        if (URLCheck.getBooleanAttributes().contains(anAtt)) {\r
+          if (!checkBoolean(aValue)) {\r
+            errors.addElement(LocalizedResource.getMessage("TL_trueFalse"));\r
+          }\r
+        }\r
+      }\r
+      catch (Exception ex) {\r
+        ex.printStackTrace();\r
+      }\r
+    }\r
+         boolean checkBoolean(String aValue) {\r
+                 if (aValue == null)\r
+                         return false;\r
+                 return aValue.toLowerCase(Locale.ENGLISH).equals("true") || \r
+                         aValue.toLowerCase(Locale.ENGLISH).equals("false");\r
+         }\r
+    void display(String aString) {\r
+               LocalizedResource.OutputWriter().println(aString);\r
+    }\r
+    void displayIndented(String aString) {\r
+               LocalizedResource.OutputWriter().println("   " + aString);\r
+    }\r
+  }\r