KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > tools > ij > AttributeHolder


1 /*
2
3    Derby - Class org.apache.derby.impl.tools.ij.AttributeHolder
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22
23 package org.apache.derby.impl.tools.ij;
24
25 import org.apache.derby.iapi.reference.Attribute;
26 import org.apache.derby.iapi.tools.i18n.LocalizedResource;
27 import org.apache.derby.tools.URLCheck;
28 import java.util.Locale JavaDoc;
29 import java.util.Vector JavaDoc;
30 import java.util.Properties JavaDoc;
31 import java.util.Enumeration JavaDoc;
32 import java.util.StringTokenizer JavaDoc;
33 import java.lang.reflect.Field JavaDoc;
34 import java.sql.SQLException JavaDoc;
35
36 public class AttributeHolder {
37
38     //This is an inner class. This class hold the details about each
39
//specific attribute which includes what the attribute is and
40
//any error found.
41
String JavaDoc name;
42     String JavaDoc value;
43     String JavaDoc token;
44     Vector JavaDoc errors = new Vector JavaDoc();
45
46     public String JavaDoc getName(){
47       return name;
48     }
49     public void setName(String JavaDoc aString){
50       name = aString;
51     }
52     String JavaDoc getValue(){
53       return value;
54     }
55     public void setValue(String JavaDoc aString){
56       value = aString;
57     }
58     String JavaDoc getToken(){
59       return token;
60     }
61     public void setToken(String JavaDoc aString){
62       token = aString;
63     }
64     public void addError(String JavaDoc aString) {
65       //Keep track of error message for later display.
66
if (!errors.contains(aString))
67         errors.addElement(aString);
68     }
69    public void check( Vector JavaDoc validProps){
70       checkName( validProps);
71       //checkValue();
72
displayErrors();
73     }
74     void displayErrors(){
75       //If no error are found then nothing is displayed.
76
Enumeration JavaDoc e = errors.elements();
77       //In the first line, show the exact token that was parsed from
78
//the URL.
79
if (e.hasMoreElements())
80         display(LocalizedResource.getMessage("TL_urlLabel1", "[", getToken(), "]"));
81       //Show all errors. More than one error can be found for an attribute.
82
while (e.hasMoreElements()){
83         String JavaDoc aString = (String JavaDoc)e.nextElement();
84         displayIndented(aString);
85       }
86     }
87     void checkName( Vector JavaDoc validProps){
88       if( validProps == null)
89           return; // valid properties are unknown
90
String JavaDoc anAtt = getName();
91       try {
92         //Check the found name against valid names.
93
if (!validProps.contains(anAtt)) {
94           //Check for case spelling of the name.
95
if (validProps.contains(anAtt.toLowerCase(java.util.Locale.ENGLISH))) {
96             errors.addElement(LocalizedResource.getMessage("TL_incorCase"));
97           }
98           //Check if this is even a valid attribute name.
99
else {
100             errors.addElement(LocalizedResource.getMessage("TL_unknownAtt"));
101           }
102         }
103         else {
104           //This Is a valid attribute.
105
}
106       }
107       catch (Exception JavaDoc ex) {
108         ex.printStackTrace();
109       }
110     }
111     void checkValue(){
112       String JavaDoc anAtt = getName();
113       String JavaDoc aValue = getValue();
114       try {
115         //Check all attribute that require a boolean.
116
if (URLCheck.getBooleanAttributes().contains(anAtt)) {
117           if (!checkBoolean(aValue)) {
118             errors.addElement(LocalizedResource.getMessage("TL_trueFalse"));
119           }
120         }
121       }
122       catch (Exception JavaDoc ex) {
123         ex.printStackTrace();
124       }
125     }
126       boolean checkBoolean(String JavaDoc aValue) {
127           if (aValue == null)
128               return false;
129           return aValue.toLowerCase(Locale.ENGLISH).equals("true") ||
130               aValue.toLowerCase(Locale.ENGLISH).equals("false");
131       }
132     void display(String JavaDoc aString) {
133         LocalizedResource.OutputWriter().println(aString);
134     }
135     void displayIndented(String JavaDoc aString) {
136         LocalizedResource.OutputWriter().println(" " + aString);
137     }
138   }
139
Popular Tags