001: /*
002:
003: Derby - Class org.apache.derby.impl.tools.ij.AttributeHolder
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.tools.ij;
023:
024: import org.apache.derby.iapi.reference.Attribute;
025: import org.apache.derby.iapi.tools.i18n.LocalizedResource;
026: import org.apache.derby.tools.URLCheck;
027: import java.util.Locale;
028: import java.util.Vector;
029: import java.util.Properties;
030: import java.util.Enumeration;
031: import java.util.StringTokenizer;
032: import java.lang.reflect.Field;
033: import java.sql.SQLException;
034:
035: public class AttributeHolder {
036:
037: //This is an inner class. This class hold the details about each
038: //specific attribute which includes what the attribute is and
039: //any error found.
040: String name;
041: String value;
042: String token;
043: Vector errors = new Vector();
044:
045: public String getName() {
046: return name;
047: }
048:
049: public void setName(String aString) {
050: name = aString;
051: }
052:
053: String getValue() {
054: return value;
055: }
056:
057: public void setValue(String aString) {
058: value = aString;
059: }
060:
061: String getToken() {
062: return token;
063: }
064:
065: public void setToken(String aString) {
066: token = aString;
067: }
068:
069: public void addError(String aString) {
070: //Keep track of error message for later display.
071: if (!errors.contains(aString))
072: errors.addElement(aString);
073: }
074:
075: public void check(Vector validProps) {
076: checkName(validProps);
077: //checkValue();
078: displayErrors();
079: }
080:
081: void displayErrors() {
082: //If no error are found then nothing is displayed.
083: Enumeration e = errors.elements();
084: //In the first line, show the exact token that was parsed from
085: //the URL.
086: if (e.hasMoreElements())
087: display(LocalizedResource.getMessage("TL_urlLabel1", "[",
088: getToken(), "]"));
089: //Show all errors. More than one error can be found for an attribute.
090: while (e.hasMoreElements()) {
091: String aString = (String) e.nextElement();
092: displayIndented(aString);
093: }
094: }
095:
096: void checkName(Vector validProps) {
097: if (validProps == null)
098: return; // valid properties are unknown
099: String anAtt = getName();
100: try {
101: //Check the found name against valid names.
102: if (!validProps.contains(anAtt)) {
103: //Check for case spelling of the name.
104: if (validProps.contains(anAtt
105: .toLowerCase(java.util.Locale.ENGLISH))) {
106: errors.addElement(LocalizedResource
107: .getMessage("TL_incorCase"));
108: }
109: //Check if this is even a valid attribute name.
110: else {
111: errors.addElement(LocalizedResource
112: .getMessage("TL_unknownAtt"));
113: }
114: } else {
115: //This Is a valid attribute.
116: }
117: } catch (Exception ex) {
118: ex.printStackTrace();
119: }
120: }
121:
122: void checkValue() {
123: String anAtt = getName();
124: String aValue = getValue();
125: try {
126: //Check all attribute that require a boolean.
127: if (URLCheck.getBooleanAttributes().contains(anAtt)) {
128: if (!checkBoolean(aValue)) {
129: errors.addElement(LocalizedResource
130: .getMessage("TL_trueFalse"));
131: }
132: }
133: } catch (Exception ex) {
134: ex.printStackTrace();
135: }
136: }
137:
138: boolean checkBoolean(String aValue) {
139: if (aValue == null)
140: return false;
141: return aValue.toLowerCase(Locale.ENGLISH).equals("true")
142: || aValue.toLowerCase(Locale.ENGLISH).equals("false");
143: }
144:
145: void display(String aString) {
146: LocalizedResource.OutputWriter().println(aString);
147: }
148:
149: void displayIndented(String aString) {
150: LocalizedResource.OutputWriter().println(" " + aString);
151: }
152: }
|