KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > config > DataSourceConfig


1 /*
2  * $Id: DataSourceConfig.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.config;
21
22
23 import java.io.Serializable JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27 import org.apache.struts.Globals;
28
29
30 /**
31  * <p>A JavaBean representing the configuration information of a
32  * <code>&lt;data-source&gt;</code> element from a Struts
33  * configuration file.</p>
34  *
35  * <p><strong>WARNING</strong> - The properties of this configuration bean
36  * are recognized by the default data source implementation, but some or all
37  * of them may be ignored by custom data source implementations.</p>
38  *
39  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
40  * @since Struts 1.1
41  */

42
43 public class DataSourceConfig implements Serializable JavaDoc {
44
45
46
47     // ----------------------------------------------------- Instance Variables
48

49
50     /**
51      * Has this component been completely configured?
52      */

53     protected boolean configured = false;
54
55
56     // ------------------------------------------------------------- Properties
57

58
59     /**
60      * The servlet context attribute key under which this data source
61      * is stored and made available.
62      */

63     protected String JavaDoc key = Globals.DATA_SOURCE_KEY;
64
65     public String JavaDoc getKey() {
66         return (this.key);
67     }
68
69     public void setKey(String JavaDoc key) {
70         if (configured) {
71             throw new IllegalStateException JavaDoc("Configuration is frozen");
72         }
73         this.key = key;
74     }
75
76
77     /**
78      * The custom configuration properties for this data source implementation.
79      */

80     protected HashMap JavaDoc properties = new HashMap JavaDoc();
81
82     public Map JavaDoc getProperties() {
83         return (this.properties);
84     }
85
86
87     /**
88      * The fully qualified class name of the <code>javax.sql.DataSource</code>
89      * implementation class.
90      */

91     protected String JavaDoc type;
92
93     public String JavaDoc getType() {
94         return (this.type);
95     }
96
97     public void setType(String JavaDoc type) {
98         if (configured) {
99             throw new IllegalStateException JavaDoc("Configuration is frozen");
100         }
101         this.type = type;
102     }
103
104
105     // --------------------------------------------------------- Public Methods
106

107
108     /**
109      * Add a new custom configuration property.
110      *
111      * @param name Custom property name
112      * @param value Custom property value
113      */

114     public void addProperty(String JavaDoc name, String JavaDoc value) {
115
116         if (configured) {
117             throw new IllegalStateException JavaDoc("Configuration is frozen");
118         }
119         properties.put(name, value);
120
121     }
122
123
124     /**
125      * Freeze the configuration of this data source.
126      */

127     public void freeze() {
128
129         configured = true;
130
131     }
132
133
134     /**
135      * Return a String representation of this object.
136      */

137     public String JavaDoc toString() {
138
139         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("DataSourceConfig[");
140         sb.append("key=");
141         sb.append(key);
142         sb.append(",type=");
143         sb.append(type);
144         Iterator JavaDoc names = properties.keySet().iterator();
145         while (names.hasNext()) {
146             String JavaDoc name = (String JavaDoc) names.next();
147             String JavaDoc value = (String JavaDoc) properties.get(name);
148             sb.append(',');
149             sb.append(name);
150             sb.append('=');
151             sb.append(value);
152         }
153         sb.append("]");
154         return (sb.toString());
155
156     }
157
158
159 }
160
Popular Tags