KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > jdbc > FailedProperties40


1 /*
2  
3    Derby - Class org.apache.derby.impl.jdbc.FailedProperties40
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 package org.apache.derby.iapi.jdbc;
23
24 import java.util.Properties JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.sql.SQLClientInfoException JavaDoc;
29 import java.sql.ClientInfoStatus JavaDoc;
30
31     /**
32      * Class <code>FailedProperties40</code> is a helper class for the
33      * SQLClientInfoException. It provides convenient access to data
34      * that is needed when constructing SQLClientInfoExceptions. Should
35      * be kept in sync with its client side counter part
36      * (org.apache.derby.client.am.FailedProperties40).
37      * @see java.sql.SQLClientInfoException
38      * @see org.apache.derby.client.am.FailedProperties40
39      */

40 public class FailedProperties40 {
41     private final HashMap JavaDoc<String JavaDoc,ClientInfoStatus JavaDoc> failedProps_ =
42     new HashMap JavaDoc<String JavaDoc,ClientInfoStatus JavaDoc>();
43     private final String JavaDoc firstKey_;
44     private final String JavaDoc firstValue_;
45
46     /**
47      * Helper method that creates a Propery object from the name-value
48      * pair given as arguments.
49      * @param name property key
50      * @param value property value
51      * @return the created <code>Properties</code> object
52      */

53     public static Properties JavaDoc makeProperties(String JavaDoc name, String JavaDoc value) {
54     Properties JavaDoc p = new Properties JavaDoc();
55     if (name != null || value != null)
56         p.setProperty(name, value);
57     return p;
58     }
59     /**
60      * Creates a new <code>FailedProperties40</code> instance. Since
61      * Derby doesn't support any properties, all the keys from the
62      * <code>props</code> parameter are added to the
63      * <code>failedProps_</code> member with value
64      * REASON_UNKNOWN_PROPERTY.
65      *
66      * @param props a <code>Properties</code> value. Can be null or empty
67      */

68     public FailedProperties40(Properties JavaDoc props) {
69         if (props == null || props.isEmpty()) {
70             firstKey_ = null;
71             firstValue_ = null;
72             return;
73         }
74         Enumeration JavaDoc e = props.keys();
75         firstKey_ = (String JavaDoc)e.nextElement();
76         firstValue_ = props.getProperty(firstKey_);
77         failedProps_.put(firstKey_, ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
78         while (e.hasMoreElements()) {
79             failedProps_.put((String JavaDoc)e.nextElement(),
80                  ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
81         }
82     }
83
84     /**
85      * <code>getProperties</code> provides a
86      * <code>Map<String,ClientInfoStatus></code> object describing the
87      * failed properties (as specified in the javadoc for
88      * java.sql.SQLClientInfoException).
89      *
90      * @return a <code>Map<String,ClientInfoStatus></code> object with
91      * the failed property keys and the reason why each failed
92      */

93     public Map JavaDoc<String JavaDoc,ClientInfoStatus JavaDoc> getProperties() { return failedProps_; }
94
95     /**
96      * <code>getFirstKey</code> returns the first property key. Used
97      * when SQLClientInfoException is thrown with a parameterized error
98      * message.
99      *
100      * @return a <code>String</code> value
101      */

102     public String JavaDoc getFirstKey() { return firstKey_; }
103
104     /**
105      * <code>getFirstValue</code> returns the first property value. Used
106      * when SQLClientInfoException is thrown with a parameterized error
107      * message.
108      *
109      * @return a <code>String</code> value
110      */

111     public String JavaDoc getFirstValue() { return firstValue_; }
112 }
113
Popular Tags