KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > FailedProperties40


1 /*
2  
3    Derby - Class org.apache.derby.client.am.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.client.am;
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
33      * <code>java.sql.SQLClientInfoException</code>. It provides
34      * convenient access to data that is needed when constructing
35      * those exceptions. Should be kept in sync with its embedded
36      * counter part.
37      * @see java.sql.SQLClientInfoException
38      * @see org.apache.derby.iapi.jdbc.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
44     private final String JavaDoc firstKey_;
45     private final String JavaDoc firstValue_;
46
47     /**
48      * Helper method that creates a Propery object with the name-value
49      * pair given as arguments.
50      * @param name property key
51      * @param value property value
52      * @return the created <code>Properties</code> object
53      */

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

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

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

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

113     public String JavaDoc getFirstValue() { return firstValue_; }
114 }
115
Popular Tags