1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.tools.ij.AttributeHolder |
4 | |
5 | Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | |
22 | package org.apache.derby.impl.tools.ij; |
23 | |
24 | import org.apache.derby.iapi.reference.Attribute; |
25 | import org.apache.derby.iapi.tools.i18n.LocalizedResource; |
26 | import org.apache.derby.tools.URLCheck; |
27 | import java.util.Locale; |
28 | import java.util.Vector; |
29 | import java.util.Properties; |
30 | import java.util.Enumeration; |
31 | import java.util.StringTokenizer; |
32 | import java.lang.reflect.Field; |
33 | import java.sql.SQLException; |
34 | |
35 | public class AttributeHolder { |
36 | |
37 | //This is an inner class. This class hold the details about each |
38 | //specific attribute which includes what the attribute is and |
39 | //any error found. |
40 | String name; |
41 | String value; |
42 | String token; |
43 | Vector errors = new Vector(); |
44 | |
45 | public String getName(){ |
46 | return name; |
47 | } |
48 | public void setName(String aString){ |
49 | name = aString; |
50 | } |
51 | public String getValue(){ |
52 | return value; |
53 | } |
54 | public void setValue(String aString){ |
55 | value = aString; |
56 | } |
57 | public String getToken(){ |
58 | return token; |
59 | } |
60 | public void setToken(String aString){ |
61 | token = aString; |
62 | } |
63 | public void addError(String aString) { |
64 | //Keep track of error message for later display. |
65 | if (!errors.contains(aString)) |
66 | errors.addElement(aString); |
67 | } |
68 | public void check( Vector validProps){ |
69 | checkName( validProps); |
70 | //checkValue(); |
71 | displayErrors(); |
72 | } |
73 | public void displayErrors(){ |
74 | //If no error are found then nothing is displayed. |
75 | Enumeration e = errors.elements(); |
76 | //In the first line, show the exact token that was parsed from |
77 | //the URL. |
78 | if (e.hasMoreElements()) |
79 | display(LocalizedResource.getMessage("TL_urlLabel1", "[", getToken(), "]")); |
80 | //Show all errors. More than one error can be found for an attribute. |
81 | while (e.hasMoreElements()){ |
82 | String aString = (String)e.nextElement(); |
83 | displayIndented(aString); |
84 | } |
85 | } |
86 | public void checkName( Vector validProps){ |
87 | if( validProps == null) |
88 | return; // valid properties are unknown |
89 | String anAtt = getName(); |
90 | try { |
91 | //Check the found name against valid names. |
92 | if (!validProps.contains(anAtt)) { |
93 | //Check for case spelling of the name. |
94 | if (validProps.contains(anAtt.toLowerCase(java.util.Locale.ENGLISH))) { |
95 | errors.addElement(LocalizedResource.getMessage("TL_incorCase")); |
96 | } |
97 | //Check if this is even a valid attribute name. |
98 | else { |
99 | errors.addElement(LocalizedResource.getMessage("TL_unknownAtt")); |
100 | } |
101 | } |
102 | else { |
103 | //This Is a valid attribute. |
104 | } |
105 | } |
106 | catch (Exception ex) { |
107 | ex.printStackTrace(); |
108 | } |
109 | } |
110 | public void checkValue(){ |
111 | String anAtt = getName(); |
112 | String aValue = getValue(); |
113 | try { |
114 | //Check all attribute that require a boolean. |
115 | if (URLCheck.getBooleanAttributes().contains(anAtt)) { |
116 | if (!checkBoolean(aValue)) { |
117 | errors.addElement(LocalizedResource.getMessage("TL_trueFalse")); |
118 | } |
119 | } |
120 | } |
121 | catch (Exception ex) { |
122 | ex.printStackTrace(); |
123 | } |
124 | } |
125 | public boolean checkBoolean(String aValue) { |
126 | if (aValue == null) |
127 | return false; |
128 | return aValue.toLowerCase(Locale.ENGLISH).equals("true") || |
129 | aValue.toLowerCase(Locale.ENGLISH).equals("false"); |
130 | } |
131 | public void display(String aString) { |
132 | LocalizedResource.OutputWriter().println(aString); |
133 | } |
134 | public void displayIndented(String aString) { |
135 | LocalizedResource.OutputWriter().println(" " + aString); |
136 | } |
137 | } |