Source Code Cross Referenced for Property.java in  » Content-Management-System » TransferCM » com » methodhead » property » 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 » Content Management System » TransferCM » com.methodhead.property 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
003:         * 
004:         * This file is part of TransferCM.
005:         * 
006:         * TransferCM is free software; you can redistribute it and/or modify it under the
007:         * terms of the GNU General Public License as published by the Free Software
008:         * Foundation; either version 2 of the License, or (at your option) any later
009:         * version.
010:         * 
011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
014:         * details.
015:         * 
016:         * You should have received a copy of the GNU General Public License along with
017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018:         * Fifth Floor, Boston, MA  02110-1301  USA
019:         */
020:
021:        package com.methodhead.property;
022:
023:        import java.util.HashMap;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        import com.methodhead.persistable.Persistable;
028:        import com.methodhead.persistable.PersistableException;
029:
030:        import org.apache.commons.beanutils.DynaClass;
031:        import org.apache.commons.beanutils.DynaProperty;
032:        import org.apache.commons.beanutils.BasicDynaClass;
033:
034:        import com.methodhead.sitecontext.SiteContextCapable;
035:        import com.methodhead.sitecontext.SiteContext;
036:
037:        /**
038:         * A name/value pair with convenient methods to get and set them.
039:         * <ul>
040:         *   <li><tt>int sitecontext_id = 0</tt></li>
041:         *   <li><tt>String name = ""</tt></li>
042:         *   <li><tt>String value = ""</tt></li>
043:         *   <li><tt>String description = ""</tt></li>
044:         *   <li><tt>boolean system_property = false</tt> A flag indicating the property is a
045:         *   system property; what that actually means is up to the application</li>
046:         * </ul>
047:         */
048:        public class Property extends Persistable implements  SiteContextCapable {
049:
050:            private static DynaClass dynaClass_ = null;
051:
052:            static {
053:                DynaProperty[] dynaProperties = new DynaProperty[] {
054:                        new DynaProperty("sitecontext_id", Integer.class),
055:                        new DynaProperty("name", String.class),
056:                        new DynaProperty("value", String.class),
057:                        new DynaProperty("description", String.class),
058:                        new DynaProperty("system_property", Boolean.class) };
059:
060:                dynaClass_ = new BasicDynaClass("mh_property", Property.class,
061:                        dynaProperties);
062:            }
063:
064:            // constructors /////////////////////////////////////////////////////////////
065:
066:            public Property() {
067:                super (dynaClass_);
068:                setInt("sitecontext_id", 0);
069:                setString("name", "");
070:                setString("value", "");
071:                setString("description", "");
072:                setBoolean("system_property", false);
073:            }
074:
075:            public Property(DynaClass dynaClass) {
076:                super (dynaClass);
077:                setInt("sitecontext_id", 0);
078:                setString("name", "");
079:                setString("value", "");
080:                setString("description", "");
081:                setBoolean("system_property", false);
082:            }
083:
084:            // constants ////////////////////////////////////////////////////////////////
085:
086:            // classes //////////////////////////////////////////////////////////////////
087:
088:            // methods //////////////////////////////////////////////////////////////////
089:
090:            public void setSiteContext(SiteContext siteContext) {
091:
092:                siteContext_ = siteContext;
093:            }
094:
095:            public SiteContext getSiteContext() {
096:
097:                if (siteContext_ == null)
098:                    siteContext_ = SiteContext.getDefaultContext();
099:
100:                return siteContext_;
101:            }
102:
103:            /**
104:             * Updates the property <tt>name</tt> with <tt>value</tt>,
105:             * <tt>description</tt>, and <tt>system</tt>, overwriting any values there
106:             * already.  If the property exists, each attribute is only updated if its
107:             * corresponding method argument is not <tt>null</tt>.  If the property
108:             * doesn't exist and a method argument is <tt>null</tt>, its corresponding
109:             * attribute is set to an empty string (or <tt>false</tt> in
110:             * <tt>system</tt>'s case).  already.  
111:             */
112:            public void setProperty(String name, String value,
113:                    String description, Boolean system) {
114:
115:                try {
116:                    load("sitecontext_id=" + getSiteContext().getInt("id")
117:                            + " AND name=" + getSqlLiteral(name));
118:                } catch (PersistableException e) {
119:                    //
120:                    // property didn't exist; create it new
121:                    //
122:                    setString("name", name);
123:
124:                    setInt("sitecontext_id", getSiteContext().getInt("id"));
125:
126:                    if (value != null)
127:                        setString("value", value);
128:                    if (description != null)
129:                        setString("description", description);
130:                    if (system != null)
131:                        setBoolean("system_property", system.booleanValue());
132:
133:                    saveNew();
134:
135:                    return;
136:                }
137:
138:                setInt("sitecontext_id", getSiteContext().getInt("id"));
139:
140:                if (value != null)
141:                    setString("value", value);
142:                if (description != null)
143:                    setString("description", description);
144:                if (system != null)
145:                    setBoolean("system_property", system.booleanValue());
146:
147:                save("sitecontext_id=" + getSiteContext().getInt("id")
148:                        + " AND name=" + getSqlLiteral(name));
149:            }
150:
151:            public static void setProperty(SiteContext siteContext,
152:                    String name, String value, String description,
153:                    Boolean system) {
154:
155:                Property p = new Property();
156:                p.setSiteContext(siteContext);
157:                p.setProperty(name, value, description, system);
158:            }
159:
160:            /**
161:             * Updates the property <tt>name</tt> with <tt>value</tt>
162:             */
163:            public static void setProperty(SiteContext siteContext,
164:                    String name, String value) {
165:
166:                setProperty(siteContext, name, value, null, null);
167:            }
168:
169:            /**
170:             * Returns the value of property named <tt>name</tt> or <tt>null</tt> if the
171:             * property is not defined.
172:             */
173:            public static String getProperty(SiteContext siteContext,
174:                    String name) {
175:
176:                Property p = new Property();
177:                p.setSiteContext(siteContext);
178:                return p.getProperty(name);
179:            }
180:
181:            /**
182:             * Returns the value of property named <tt>name</tt> or <tt>null</tt> if the
183:             * property is not defined.
184:             */
185:            public String getProperty(String name) {
186:
187:                try {
188:                    Property p = new Property();
189:                    p.load("sitecontext_id=" + getSiteContext().getInt("id")
190:                            + " AND name=" + getSqlLiteral(name));
191:                    return p.getString("value");
192:                } catch (PersistableException e) {
193:                    return null;
194:                }
195:            }
196:
197:            /**
198:             * Returns the value of property named <tt>name</tt> or <tt>defaultVal</tt> if
199:             * the property is not defined.
200:             */
201:            public static String getProperty(SiteContext siteContext,
202:                    String name, String defaultVal) {
203:
204:                String val = getProperty(siteContext, name);
205:
206:                if (val == null)
207:                    return defaultVal;
208:
209:                return val;
210:            }
211:
212:            /**
213:             * Returns the property named <tt>name</tt> split on commas (e.g.,
214:             * <tt>"one,two,three"</tt>) or <tt>null</tt> if the property is not defined.
215:             * Values are trimmed before being returned.
216:             */
217:            public static String[] getPropertyArray(SiteContext siteContext,
218:                    String name) {
219:
220:                String val = getProperty(siteContext, name);
221:
222:                if (val == null)
223:                    return null;
224:
225:                String[] vals = val.split(",");
226:
227:                String[] trimmedVals = new String[vals.length];
228:                for (int i = 0; i < vals.length; i++)
229:                    trimmedVals[i] = vals[i].trim();
230:
231:                return trimmedVals;
232:            }
233:
234:            /**
235:             * Loads the property named <tt>name</tt>.
236:             */
237:            public void loadForName(String name) {
238:
239:                load("sitecontext_id=" + getSiteContext().getInt("id")
240:                        + " AND name=" + getSqlLiteral(name));
241:            }
242:
243:            /**
244:             * Returns a list containing all defined properties in alphabetic order.
245:             */
246:            public static List loadAll(SiteContext siteContext) {
247:
248:                Property p = new Property();
249:                p.setSiteContext(siteContext);
250:                return p.loadAll();
251:            }
252:
253:            /**
254:             * Returns a list containing all defined properties in alphabetic order.
255:             */
256:            public List loadAll() {
257:
258:                return loadAll(dynaClass_, "sitecontext_id="
259:                        + getSiteContext().getInt("id"), "name");
260:            }
261:
262:            // properties ///////////////////////////////////////////////////////////////
263:
264:            // attributes ///////////////////////////////////////////////////////////////
265:
266:            private SiteContext siteContext_ = null;
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.