001: /*
002:
003: Derby - Class org.apache.derby.client.am.FailedProperties40
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.client.am;
023:
024: import java.util.Properties;
025: import java.util.Enumeration;
026: import java.util.Map;
027: import java.util.HashMap;
028: import java.sql.SQLClientInfoException;
029: import java.sql.ClientInfoStatus;
030:
031: /**
032: * Class <code>FailedProperties40</code> is a helper class for
033: * <code>java.sql.SQLClientInfoException</code>. It provides
034: * convenient access to data that is needed when constructing
035: * those exceptions. Should be kept in sync with its embedded
036: * counter part.
037: * @see java.sql.SQLClientInfoException
038: * @see org.apache.derby.iapi.jdbc.FailedProperties40
039: */
040: public class FailedProperties40 {
041: private final HashMap<String, ClientInfoStatus> failedProps_ = new HashMap<String, ClientInfoStatus>();
042:
043: private final String firstKey_;
044: private final String firstValue_;
045:
046: /**
047: * Helper method that creates a Propery object with the name-value
048: * pair given as arguments.
049: * @param name property key
050: * @param value property value
051: * @return the created <code>Properties</code> object
052: */
053: public static Properties makeProperties(String name, String value) {
054: Properties p = new Properties();
055: if (name != null || value != null)
056: p.setProperty(name, value);
057: return p;
058: }
059:
060: /**
061: * Creates a new <code>FailedProperties40</code> instance. Since
062: * Derby doesn't support any properties, all the keys from the
063: * <code>props</code> parameter are added to the
064: * <code>failedProps_</code> member with value
065: * REASON_UNKNOWN_PROPERTY.
066: *
067: * @param props a <code>Properties</code> value. Can be null or empty
068: */
069: public FailedProperties40(Properties props) {
070: if (props == null || props.isEmpty()) {
071: firstKey_ = null;
072: firstValue_ = null;
073: return;
074: }
075: Enumeration e = props.keys();
076: firstKey_ = (String) e.nextElement();
077: firstValue_ = props.getProperty(firstKey_);
078: failedProps_.put(firstKey_,
079: ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
080: while (e.hasMoreElements()) {
081: failedProps_.put((String) e.nextElement(),
082: ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
083: }
084: }
085:
086: /**
087: * <code>getProperties</code> provides a
088: * <code>Map<String,ClientInfoStatus></code> object describing the
089: * failed properties (as specified in the javadoc for
090: * java.sql.SQLClientInfoException).
091: *
092: * @return a <code>Map<String,ClientInfoStatus></code> object with
093: * the failed property keys and the reason why each failed
094: */
095: public Map<String, ClientInfoStatus> getProperties() {
096: return failedProps_;
097: }
098:
099: /**
100: * <code>getFirstKey</code> returns the first property key. Used
101: * when SQLClientInfoException is thrown with a parameterized error
102: * message.
103: *
104: * @return a <code>String</code> value
105: */
106: public String getFirstKey() {
107: return firstKey_;
108: }
109:
110: /**
111: * <code>getFirstValue</code> returns the first property value. Used
112: * when SQLClientInfoException is thrown with a parameterized error
113: * message.
114: *
115: * @return a <code>String</code> value
116: */
117: public String getFirstValue() {
118: return firstValue_;
119: }
120: }
|