Source Code Cross Referenced for ConfigData.java in  » Web-Server » Rimfaxe-Web-Server » seda » sandStorm » internal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Rimfaxe Web Server » seda.sandStorm.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (c) 2001 by Matt Welsh and The Regents of the University of 
003:         * California. All rights reserved.
004:         *
005:         * Permission to use, copy, modify, and distribute this software and its
006:         * documentation for any purpose, without fee, and without written agreement is
007:         * hereby granted, provided that the above copyright notice and the following
008:         * two paragraphs appear in all copies of this software.
009:         * 
010:         * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011:         * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012:         * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013:         * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014:         * 
015:         * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016:         * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017:         * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
018:         * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019:         * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020:         *
021:         * Author: Matt Welsh <mdw@cs.berkeley.edu>
022:         * 
023:         */
024:
025:        package seda.sandStorm.internal;
026:
027:        import seda.sandStorm.api.*;
028:        import seda.sandStorm.core.*;
029:        import seda.sandStorm.main.*;
030:        import java.io.IOException;
031:        import java.util.*;
032:
033:        /**
034:         * ConfigData is used to pass configuration arguments into various
035:         * components. 
036:         */
037:        public class ConfigData implements  ConfigDataIF {
038:            private static final boolean DEBUG = false;
039:
040:            private Hashtable vals;
041:            private ManagerIF mgr;
042:            private StageIF stage;
043:
044:            /**
045:             * Create a ConfigData with the given manager and no argument list.
046:             */
047:            public ConfigData(ManagerIF mgr) {
048:                this .mgr = mgr;
049:                this .vals = new Hashtable(1);
050:            }
051:
052:            /**
053:             * Create a ConfigData with the given manager and argument list.
054:             */
055:            public ConfigData(ManagerIF mgr, Hashtable args) {
056:                this .mgr = mgr;
057:                this .vals = args;
058:                if (vals == null)
059:                    vals = new Hashtable(1);
060:            }
061:
062:            /**
063:             * Create a ConfigData with the given manager and argument list,
064:             * specified as an array of strings of the form "key=value".
065:             *
066:             * @throws IOException If any of the strings to not match the 
067:             *   pattern "key=value".
068:             */
069:            public ConfigData(ManagerIF mgr, String args[]) throws IOException {
070:                this .mgr = mgr;
071:                this .vals = stringArrayToHT(args);
072:                if (vals == null)
073:                    vals = new Hashtable(1);
074:            }
075:
076:            /**
077:             * Returns true if the given key is set.
078:             */
079:            public boolean contains(String key) {
080:                if (vals.get(key) != null)
081:                    return true;
082:                else
083:                    return false;
084:            }
085:
086:            /**
087:             * Get the string value corresponding to the given key.
088:             * Returns null if not set.
089:             */
090:            public String getString(String key) {
091:                return (String) vals.get(key);
092:            }
093:
094:            /**
095:             * Get the integer value corresponding to the given key.
096:             * Returns -1 if not set or if the value is not an integer.
097:             */
098:            public int getInt(String key) {
099:                String val = (String) vals.get(key);
100:                if (val == null)
101:                    return -1;
102:                try {
103:                    return Integer.parseInt(val);
104:                } catch (NumberFormatException e) {
105:                    return -1;
106:                }
107:            }
108:
109:            /**
110:             * Get the double value corresponding to the given key.
111:             * Returns -1.0 if not set or if the value is not a double.
112:             */
113:            public double getDouble(String key) {
114:                String val = (String) vals.get(key);
115:                if (val == null)
116:                    return -1;
117:                try {
118:                    return new Double(val).doubleValue();
119:                } catch (NumberFormatException e) {
120:                    return -1.0;
121:                }
122:            }
123:
124:            /**
125:             * Get the boolean value corresponding to the given key.
126:             * Returns false if not set.
127:             */
128:            public boolean getBoolean(String key) {
129:                String val = (String) vals.get(key);
130:                if (val == null)
131:                    return false;
132:                else if (val.equals("true") || val.equals("TRUE"))
133:                    return true;
134:                else
135:                    return false;
136:            }
137:
138:            /**
139:             * Get the string list value corresponding to the given key.
140:             * Returns null if not set.
141:             */
142:            public String[] getStringList(String key) {
143:                String ret[];
144:                String val = (String) vals.get(key);
145:                if (val == null)
146:                    return null;
147:                StringTokenizer st = new StringTokenizer(val,
148:                        SandstormConfig.LIST_ELEMENT_DELIMITER);
149:                Vector v = new Vector(1);
150:                while (st.hasMoreElements()) {
151:                    v.addElement(st.nextElement());
152:                }
153:                ret = new String[v.size()];
154:                for (int i = 0; i < ret.length; i++) {
155:                    ret[i] = (String) v.elementAt(i);
156:                }
157:                return ret;
158:            }
159:
160:            /**
161:             * Set the given key to the given string value.
162:             */
163:            public void setString(String key, String val) {
164:                vals.put(key, val);
165:            }
166:
167:            /**
168:             * Set the given key to the given integer value.
169:             */
170:            public void setInt(String key, int val) {
171:                vals.put(key, Integer.toString(val));
172:            }
173:
174:            /**
175:             * Set the given key to the given double value.
176:             */
177:            public void setDouble(String key, double val) {
178:                vals.put(key, Double.toString(val));
179:            }
180:
181:            /**
182:             * Set the given key to the given boolean value.
183:             */
184:            public void setBoolean(String key, boolean val) {
185:                vals.put(key, (val == true) ? "true" : "false");
186:            }
187:
188:            /**
189:             * Set the given key to the given string list value.
190:             */
191:            public void setStringList(String key, String valarr[]) {
192:                String s = "";
193:                for (int i = 0; i < valarr.length; i++) {
194:                    s += valarr[i];
195:                    if (i != valarr.length - 1)
196:                        s += SandstormConfig.LIST_ELEMENT_DELIMITER;
197:                }
198:                vals.put(key, s);
199:            }
200:
201:            /**
202:             * Return the local manager.
203:             */
204:            public ManagerIF getManager() {
205:                return mgr;
206:            }
207:
208:            /**
209:             * Return the stage for this ConfigData.
210:             */
211:            public StageIF getStage() {
212:                return stage;
213:            }
214:
215:            // Used to set stage after creating wrapper
216:            public void setStage(StageIF stage) {
217:                this .stage = stage;
218:            }
219:
220:            // Used to reset manager after creating stage 
221:            // (for proxying the manager)
222:            void setManager(ManagerIF mgr) {
223:                this .mgr = mgr;
224:            }
225:
226:            // Convert an array of "key=value" strings to a Hashtable
227:            private Hashtable stringArrayToHT(String arr[]) throws IOException {
228:                if (arr == null)
229:                    return null;
230:                Hashtable ht = new Hashtable(1);
231:                for (int i = 0; i < arr.length; i++) {
232:                    StringTokenizer st = new StringTokenizer(arr[i], "=");
233:                    String key;
234:                    String val;
235:                    try {
236:                        key = st.nextToken();
237:                        val = st.nextToken();
238:                        while (st.hasMoreTokens())
239:                            val += "=" + st.nextToken();
240:                    } catch (NoSuchElementException e) {
241:                        throw new IOException("Could not convert string '"
242:                                + arr[i] + "' to key=value pair");
243:                    }
244:                    ht.put(key, val);
245:                }
246:                return ht;
247:            }
248:
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.