Source Code Cross Referenced for EnhProperties.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » util » 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 » Database DBMS » Ozone 1.1 » org.ozoneDB.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: EnhProperties.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
008:
009:        package org.ozoneDB.util;
010:
011:        import java.io.*;
012:        import java.util.*;
013:        import org.ozoneDB.DxLib.*;
014:        import org.ozoneDB.core.Env;
015:
016:        /**
017:         * EnhProperties has methods to store/update the value of a property to handle
018:         * such dynamic properties.
019:         * <p>
020:         * In addition the Properties EnhProperties can hold not only String properties
021:         * but most of other primitive types and raw objects. Non-string properties are
022:         * internaly stored as Strings.
023:         * <p>
024:         * Setup extends java.util.Properties. So the system properties can be used as
025:         * defaults.
026:         * 
027:         * 
028:         * @author <a href="http://www.softwarebuero.de/">SMB</a>
029:         * @version $Revision: 1.1 $Date: 2001/12/18 10:31:31 $
030:         */
031:        public class EnhProperties extends Properties {
032:
033:            /**
034:             * An Observable object that is responsible for this properties. Directly
035:             * extending the class is not possible because it already extends Properties.
036:             */
037:            protected EnhObservable observable;
038:
039:            public EnhProperties() {
040:                observable = new EnhObservable();
041:            }
042:
043:            public EnhProperties(Properties _defaults) {
044:                super (_defaults);
045:                observable = new EnhObservable();
046:            }
047:
048:            public void addObserver(Observer _observer) {
049:                observable.addObserver(_observer);
050:            }
051:
052:            public void removeObserver(Observer _observer) {
053:                observable.deleteObserver(_observer);
054:            }
055:
056:            public void notifyObservers() {
057:                observable.notifyObservers(this );
058:            }
059:
060:            public boolean hasChanged() {
061:                return observable.hasChanged();
062:            }
063:
064:            /**
065:             * @param properties
066:             * @param keyPrefix
067:             */
068:            public void addProperties(Properties properties, String keyPrefix) {
069:                observable.setChanged();
070:                for (Enumeration e = properties.keys(); e.hasMoreElements();) {
071:                    String key = (String) e.nextElement();
072:                    if (key.startsWith(keyPrefix)) {
073:                        // System.out.println (key);
074:                        String val = properties.getProperty(key, "");
075:                        setStringProperty(key, val);
076:                    }
077:                }
078:            }
079:
080:            /**
081:             * @param _val
082:             * @param _key
083:             */
084:            public synchronized void setStringProperty(String _key, String _val) {
085:                observable.setChanged();
086:                super .put(_key, _val);
087:            }
088:
089:            /**
090:             * @param _key
091:             * @param _default The default value to use if no property is found.
092:             */
093:            public String stringProperty(String _key, String _default) {
094:                return super .getProperty(_key, _default);
095:            }
096:
097:            /**
098:             * @param _key
099:             * @param _default The default value to use if no property is found.
100:             */
101:            public DxCollection stringsProperty(String _key, String _default) {
102:                String propList = stringProperty(_key, _default);
103:                DxArrayBag result = new DxArrayBag();
104:
105:                StringTokenizer st = new StringTokenizer(propList, " \t,",
106:                        false);
107:                while (st.hasMoreTokens()) {
108:                    String token = st.nextToken();
109:                    // System.out.println ("'" + token + "'");
110:                    result.add(token);
111:                }
112:                return result;
113:            }
114:
115:            /**
116:             * @param _val
117:             * @param _key
118:             */
119:            public void setProperty(String _key, Object _val) {
120:                observable.setChanged();
121:                try {
122:                    ByteArrayOutputStream buf = new ByteArrayOutputStream(1024);
123:                    ObjectOutputStream out = new ObjectOutputStream(buf);
124:                    out.writeObject(_val);
125:                    out.close();
126:
127:                    MimeBase64Encoder encoder = new MimeBase64Encoder();
128:                    encoder.translate(buf.toByteArray());
129:
130:                    setStringProperty(_key, new String(encoder.getCharArray()));
131:                } catch (Exception e) {
132:                    throw new RuntimeException(e.getMessage());
133:                }
134:            }
135:
136:            /**
137:             * @param _key
138:             * @param _default The default value to use if no property is found.
139:             */
140:            public Object property(String _key, Object _default) {
141:                try {
142:                    String result = stringProperty(_key, (String) _default);
143:                    if (result != null) {
144:                        MimeBase64Decoder decoder = new MimeBase64Decoder();
145:                        decoder.translate(result.toCharArray());
146:
147:                        ObjectInputStream in = new ObjectInputStream(
148:                                new ByteArrayInputStream(decoder.getByteArray()));
149:                        return in.readObject();
150:                    } else {
151:                        return null;
152:                    }
153:                } catch (Exception e) {
154:                    throw new RuntimeException(e.getMessage());
155:                }
156:            }
157:
158:            /**
159:             * @param _val
160:             * @param _key
161:             */
162:            public void setIntProperty(String _key, int _val) {
163:                setStringProperty(_key, String.valueOf(_val));
164:            }
165:
166:            /**
167:             * @param _key
168:             * @param _default The default value to use if no property is found.
169:             */
170:            public int intProperty(String _key, int _default) {
171:                String result = stringProperty(_key, String.valueOf(_default));
172:                return Integer.parseInt(result);
173:            }
174:
175:            /**
176:             * @param _key
177:             * @param _default The default value to use if no property is found.
178:             */
179:            public long longProperty(String _key, long _default) {
180:                String result = stringProperty(_key, String.valueOf(_default));
181:                return Long.valueOf(result).longValue();
182:            }
183:
184:            /**
185:             * @param _key
186:             * @param _default The default value to use if no property is found.
187:             */
188:            public boolean booleanProperty(String _key, boolean _default) {
189:                String result = stringProperty(_key, String.valueOf(_default));
190:                return Boolean.valueOf(result).booleanValue();
191:            }
192:
193:            /**
194:             * @param _val
195:             * @param _key
196:             */
197:            public void setLongProperty(String _key, long _val) {
198:                setStringProperty(_key, String.valueOf(_val));
199:            }
200:
201:            /**
202:             * @param _val
203:             * @param _key
204:             */
205:            public void setBooleanProperty(String _key, boolean _val) {
206:                setStringProperty(_key, String.valueOf(_val));
207:            }
208:
209:            /**
210:             * @param
211:             * @param keyPrefix
212:             * @param printPrefix
213:             */
214:            public void print(PrintStream out, String keyPrefix,
215:                    String printPrefix) {
216:                DxTreeSet sortedProps = new DxTreeSet(new DxStringComparator());
217:                for (Enumeration e = propertyNames(); e.hasMoreElements();) {
218:                    String key = (String) e.nextElement();
219:                    String val = stringProperty(key, "(not set)");
220:                    //avoid printing "object" properties
221:                    //currently not supported!!!
222:                    if (key.startsWith(keyPrefix)
223:                            && !val.startsWith("[object]")) {
224:                        sortedProps.add(printPrefix + key + " = " + val);
225:                    }
226:                }
227:                for (DxIterator it = sortedProps.iterator(); it.next() != null;) {
228:                    out.println(it.object().toString());
229:                }
230:            }
231:
232:        }
233:
234:        /**
235:         * @author <a href="http://www.softwarebuero.de/">SMB</a>
236:         * @version $Revision: 1.1 $Date: 2001/12/18 10:31:31 $
237:         */
238:        class EnhObservable extends Observable {
239:
240:            public EnhObservable() {
241:                super ();
242:            }
243:
244:            public void setChanged() {
245:                super.setChanged();
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.