Source Code Cross Referenced for EnhProperties.java in  » Database-DBMS » Ozone-1.1 » org » infozone » tools » 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.infozone.tools 
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 Infozone Software License version 2 published by the Infozone Group
003:        // (http://www.infozone-group.org).
004:        //
005:        // Copyright (C) @year@ by The Infozone Group. All rights reserved.
006:        //
007:        // $Id: EnhProperties.java,v 1.1 2002/05/10 08:59:11 per_nyfelt Exp $
008:
009:        package org.infozone.tools;
010:
011:        import java.io.*;
012:        import java.util.*;
013:
014:        /**
015:         EnhProperties has methods to store/update the value of a property to handle
016:         such dynamic properties.
017:         <p>
018:         In addition the Properties EnhProperties can hold not only String properties
019:         but most of other primitive types and raw objects. Non-string properties are
020:         internaly stored as Strings.
021:         <p>
022:         Setup extends java.util.Properties. So the system properties can be used as
023:         defaults.
024:
025:         @author <a href="http://www.softwarebuero.de/">SMB</a>
026:         @version $Revision: 1.1 $Date: 2002/05/10 08:59:11 $
027:         */
028:        public class EnhProperties extends Properties {
029:
030:            /**
031:            An Observable object that is responsible for this properties. Directly
032:            extending the class is not possible because it already extends Properties.
033:             */
034:            protected EnhObservable observable;
035:
036:            public EnhProperties() {
037:                observable = new EnhObservable();
038:            }
039:
040:            public EnhProperties(Properties _defaults) {
041:                super (_defaults);
042:                observable = new EnhObservable();
043:            }
044:
045:            public void addObserver(Observer _observer) {
046:                observable.addObserver(_observer);
047:            }
048:
049:            public void removeObserver(Observer _observer) {
050:                observable.deleteObserver(_observer);
051:            }
052:
053:            public void notifyObservers() {
054:                observable.notifyObservers(this );
055:            }
056:
057:            public boolean hasChanged() {
058:                return observable.hasChanged();
059:            }
060:
061:            /**
062:            @param properties
063:            @param keyPrefix
064:             */
065:            public void addProperties(Properties properties, String keyPrefix) {
066:                observable.setChanged();
067:                for (Enumeration e = properties.keys(); e.hasMoreElements();) {
068:                    String key = (String) e.nextElement();
069:                    if (key.startsWith(keyPrefix)) {
070:                        // System.out.println (key);
071:                        String val = properties.getProperty(key, "");
072:                        setStringProperty(key, val);
073:                    }
074:                }
075:            }
076:
077:            /** 
078:            @param _val
079:            @param _key
080:             */
081:            public synchronized void setStringProperty(String _key, String _val) {
082:                observable.setChanged();
083:                super .put(_key, _val);
084:            }
085:
086:            /** 
087:            @param _key
088:            @param _default The default value to use if no property is found.
089:             */
090:            public String stringProperty(String _key, String _default) {
091:                return super .getProperty(_key, _default);
092:            }
093:
094:            /** 
095:            @param _key
096:            @param _default The default value to use if no property is found.
097:             */
098:            public String[] stringsProperty(String _key, String _default) {
099:                String propList = stringProperty(_key, _default);
100:                Vector v = new Vector();
101:
102:                StringTokenizer st = new StringTokenizer(propList, " \t,",
103:                        false);
104:                while (st.hasMoreTokens()) {
105:                    String token = st.nextToken();
106:                    // System.out.println ("'" + token + "'");
107:                    v.addElement(token);
108:                }
109:
110:                String[] result = new String[v.size()];
111:                v.copyInto(result);
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:                } catch (Exception e) {
153:                    throw new RuntimeException(e.getMessage());
154:                }
155:            }
156:
157:            /**
158:            @param _val
159:            @param _key
160:             */
161:            public void setIntProperty(String _key, int _val) {
162:                setStringProperty(_key, String.valueOf(_val));
163:            }
164:
165:            /** 
166:            @param _key
167:            @param _default The default value to use if no property is found.
168:             */
169:            public int intProperty(String _key, int _default) {
170:                String result = stringProperty(_key, String.valueOf(_default));
171:                return Integer.parseInt(result);
172:            }
173:
174:            /** 
175:            @param _key
176:            @param _default The default value to use if no property is found.
177:             */
178:            public long longProperty(String _key, long _default) {
179:                String result = stringProperty(_key, String.valueOf(_default));
180:                return Long.valueOf(result).longValue();
181:            }
182:
183:            /** 
184:            @param _key
185:            @param _default The default value to use if no property is found.
186:             */
187:            public boolean booleanProperty(String _key, boolean _default) {
188:                String result = stringProperty(_key, String.valueOf(_default));
189:                return Boolean.valueOf(result).booleanValue();
190:            }
191:
192:            /**
193:            @param _val
194:            @param _key
195:             */
196:            public void setLongProperty(String _key, long _val) {
197:                setStringProperty(_key, String.valueOf(_val));
198:            }
199:
200:            /**
201:            @param _val
202:            @param _key
203:             */
204:            public void setBooleanProperty(String _key, boolean _val) {
205:                setStringProperty(_key, String.valueOf(_val));
206:            }
207:
208:            /**
209:            @param
210:            @param keyPrefix
211:            @param printPrefix
212:             */
213:            //    public void print (PrintStream out, String keyPrefix, String printPrefix) {
214:            //        DxTreeSet sortedProps = new DxTreeSet (new DxStringComparator());
215:            //        for (Enumeration e=propertyNames(); e.hasMoreElements();) {
216:            //            String key = (String)e.nextElement();
217:            //            String val = stringProperty (key, "(not set)");
218:            //            //avoid printing "object" properties
219:            //            //currently not supported!!!
220:            //            if (key.startsWith (keyPrefix) && !val.startsWith("[object]")) {
221:            //                sortedProps.add (printPrefix + key + " = " + val);
222:            //                }
223:            //            }
224:            //        for (DxIterator it=sortedProps.iterator(); it.next()!=null;)
225:            //            out.println (it.object().toString());
226:            //        }
227:        }
228:
229:        /**
230:         @author <a href="http://www.softwarebuero.de/">SMB</a>
231:         @version $Revision: 1.1 $Date: 2002/05/10 08:59:11 $
232:         */
233:        class EnhObservable extends Observable {
234:
235:            public EnhObservable() {
236:                super ();
237:            }
238:
239:            public void setChanged() {
240:                super.setChanged();
241:            }
242:
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.