Source Code Cross Referenced for SiteExtension.java in  » Content-Management-System » TransferCM » com » methodhead » transfer » 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.transfer 
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.transfer;
022:
023:        import java.util.List;
024:        import com.methodhead.persistable.Persistable;
025:        import com.methodhead.persistable.PersistableException;
026:
027:        import org.apache.commons.beanutils.DynaClass;
028:        import org.apache.commons.beanutils.DynaProperty;
029:        import org.apache.commons.beanutils.BasicDynaClass;
030:        import org.apache.commons.lang.StringUtils;
031:        import org.apache.commons.lang.exception.ExceptionUtils;
032:
033:        import com.methodhead.sitecontext.SiteContext;
034:        import com.methodhead.property.Property;
035:
036:        /**
037:         * A SiteExtension.  The following fields are defined:
038:         * <ul>
039:         *   <li><tt>int sitecontext_id = 0</tt></li>
040:         *   <li><tt>String class_name = ""</tt></li>
041:         *   <li><tt>boolean enabled = true</tt></li>
042:         * </ul>
043:         */
044:        public class SiteExtension extends Persistable {
045:
046:            private static DynaClass dynaClass_ = null;
047:
048:            static {
049:                DynaProperty[] dynaProperties = new DynaProperty[] {
050:                        new DynaProperty("sitecontext_id", Integer.class),
051:                        new DynaProperty("class_name", String.class),
052:                        new DynaProperty("enabled", Boolean.class) };
053:
054:                dynaClass_ = new BasicDynaClass("transfer_siteextension",
055:                        SiteExtension.class, dynaProperties);
056:            }
057:
058:            // constructors /////////////////////////////////////////////////////////////
059:
060:            public SiteExtension() {
061:                super (dynaClass_);
062:                init();
063:            }
064:
065:            public SiteExtension(DynaClass dynaClass) {
066:                super (dynaClass);
067:                init();
068:            }
069:
070:            // constants ////////////////////////////////////////////////////////////////
071:
072:            /**
073:             * Property storing comma-separated list of extensions installed on the
074:             * system.
075:             */
076:            public static final String PROPERTY_EXTENSIONS = "com.methodhead.transfer.Extensions";
077:
078:            // classes //////////////////////////////////////////////////////////////////
079:
080:            // methods //////////////////////////////////////////////////////////////////
081:
082:            private void init() {
083:                setInt("sitecontext_id", 0);
084:                setString("class_name", "");
085:                setBoolean("enabled", true);
086:            }
087:
088:            /**
089:             * Loads the site extension for <tt>siteContext</tt> and <tt>className</tt>.
090:             */
091:            public void load(SiteContext siteContext, String className) {
092:
093:                load("sitecontext_id=" + siteContext.getInt("id")
094:                        + " AND class_name=" + getSqlLiteral(className));
095:            }
096:
097:            /**
098:             * Saves the site extension.  It should already be loaded or have its
099:             * <tt>sitecontext_id</tt> and <tt>class_name</tt> properties set.
100:             */
101:            public void save() {
102:
103:                if ((getInt("sitecontext_id") == 0)
104:                        || StringUtils.isBlank(getString("class_name"))) {
105:                    throw new RuntimeException(
106:                            "sitecontext_id or class_name has not been set.");
107:                }
108:
109:                save("sitecontext_id=" + getInt("sitecontext_id")
110:                        + " AND class_name="
111:                        + getSqlLiteral(getString("class_name")));
112:            }
113:
114:            /**
115:             * Deletes the site extension.  It should already be loaded or have its
116:             * <tt>sitecontext_id</tt> and <tt>class_name</tt> properties set.
117:             */
118:            public void delete() {
119:
120:                if ((getInt("sitecontext_id") == 0)
121:                        || StringUtils.isBlank(getString("class_name"))) {
122:                    throw new RuntimeException(
123:                            "sitecontext_id or class_name has not been set.");
124:                }
125:
126:                deleteAll("sitecontext_id=" + getInt("sitecontext_id")
127:                        + " AND class_name="
128:                        + getSqlLiteral(getString("class_name")));
129:            }
130:
131:            /**
132:             * Returns the extensions installed on the system.  These extensions are
133:             * defined by the comma-separated list of class names stored in the {@link
134:             * #PROPERTY_EXTENSIONS} property of the default site context.
135:             */
136:            public Extension[] getInstalledExtensions() {
137:
138:                //
139:                // get property from default context
140:                //
141:                String extensionsStr = Property.getProperty(SiteContext
142:                        .getDefaultContext(), PROPERTY_EXTENSIONS);
143:
144:                //
145:                // blank or null?
146:                //
147:                if (StringUtils.isBlank(extensionsStr))
148:                    return new Extension[] {};
149:
150:                //
151:                // split string
152:                //
153:                String[] extensionStrs = extensionsStr.split(",");
154:
155:                //
156:                // instantiate extensions
157:                //
158:                Extension[] extensions = new Extension[extensionStrs.length];
159:
160:                for (int i = 0; i < extensions.length; i++)
161:                    extensions[i] = instantiateExtension(StringUtils
162:                            .trim(extensionStrs[i]));
163:
164:                return extensions;
165:            }
166:
167:            /**
168:             * Loads all SiteExtensions for <tt>siteContext</tt> ordered by class_name.
169:             */
170:            public List loadAllForSiteContext(SiteContext siteContext) {
171:
172:                return loadAll(dynaClass, "sitecontext_id="
173:                        + siteContext.getInt("id"), "class_name");
174:            }
175:
176:            /**
177:             * Returns extensions for <tt>siteContext</tt>.
178:             */
179:            public Extension[] getExtensionsForSiteContext(
180:                    SiteContext siteContext) {
181:
182:                List siteExtensions = loadAllForSiteContext(siteContext);
183:
184:                //
185:                // instantiate extensions
186:                //
187:                Extension[] extensions = new Extension[siteExtensions.size()];
188:
189:                for (int i = 0; i < siteExtensions.size(); i++) {
190:                    SiteExtension siteExtension = (SiteExtension) siteExtensions
191:                            .get(i);
192:
193:                    Extension extension = instantiateExtension(siteExtension
194:                            .getString("class_name"));
195:
196:                    extensions[i] = extension;
197:                }
198:
199:                return extensions;
200:            }
201:
202:            /**
203:             * Instantiates <tt>className</tt>.
204:             */
205:            public static Extension instantiateExtension(String className) {
206:
207:                try {
208:                    return (Extension) Class.forName(className).newInstance();
209:                } catch (ClassNotFoundException e) {
210:                    throw new RuntimeException(
211:                            "Unexpected ClassNotFoundException."
212:                                    + ExceptionUtils.getStackTrace(e));
213:                } catch (InstantiationException e) {
214:                    throw new RuntimeException(
215:                            "Unexpected InstantiationException trying to instantiate."
216:                                    + ExceptionUtils.getStackTrace(e));
217:                } catch (IllegalAccessException e) {
218:                    throw new RuntimeException(
219:                            "Unexpected IllegalAccessException trying to instantiate."
220:                                    + ExceptionUtils.getStackTrace(e));
221:                }
222:            }
223:
224:            /**
225:             * Returns <code>true</code> if the extension provided by
226:             * <code>className</code> exists and is enabled for <code>siteContext</code>.
227:             */
228:            public boolean isExtensionActive(SiteContext siteContext,
229:                    String className) {
230:
231:                SiteExtension siteExtension = new SiteExtension();
232:
233:                try {
234:                    siteExtension.load(siteContext, className);
235:                } catch (PersistableException e) {
236:                    return false;
237:                }
238:
239:                return siteExtension.getBoolean("enabled");
240:            }
241:
242:            // properties ///////////////////////////////////////////////////////////////
243:
244:            // attributes ///////////////////////////////////////////////////////////////
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.