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