Source Code Cross Referenced for ScreenLoader.java in  » Web-Framework » TURBINE » org » apache » turbine » modules » 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 Framework » TURBINE » org.apache.turbine.modules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.modules;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.List;
023:
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:
027:        import org.apache.ecs.ConcreteElement;
028:
029:        import org.apache.turbine.Turbine;
030:        import org.apache.turbine.TurbineConstants;
031:        import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
032:        import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
033:        import org.apache.turbine.util.ObjectUtils;
034:        import org.apache.turbine.util.RunData;
035:
036:        /**
037:         * The purpose of this class is to allow one to load and execute
038:         * Screen modules.
039:         *
040:         * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
041:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
042:         * @version $Id: ScreenLoader.java 534527 2007-05-02 16:10:59Z tv $
043:         */
044:        public class ScreenLoader extends GenericLoader implements  Loader {
045:            /** Serial Version UID */
046:            private static final long serialVersionUID = -4825216334500657398L;
047:
048:            /** Logging */
049:            private static Log log = LogFactory.getLog(ScreenLoader.class);
050:
051:            /** The single instance of this class. */
052:            private static ScreenLoader instance = new ScreenLoader(Turbine
053:                    .getConfiguration().getInt(
054:                            TurbineConstants.SCREEN_CACHE_SIZE_KEY,
055:                            TurbineConstants.SCREEN_CACHE_SIZE_DEFAULT));
056:
057:            /** The Assembler Broker Service */
058:            private static AssemblerBrokerService ab = TurbineAssemblerBroker
059:                    .getService();
060:
061:            /**
062:             * These ctor's are private to force clients to use getInstance()
063:             * to access this class.
064:             */
065:            private ScreenLoader() {
066:                super ();
067:            }
068:
069:            /**
070:             * These ctor's are private to force clients to use getInstance()
071:             * to access this class.
072:             */
073:            private ScreenLoader(int i) {
074:                super (i);
075:            }
076:
077:            /**
078:             * Adds an instance of an object into the hashtable.
079:             *
080:             * @param name Name of object.
081:             * @param screen Screen to be associated with name.
082:             */
083:            private void addInstance(String name, Screen screen) {
084:                if (cache()) {
085:                    this .put(name, (Screen) screen);
086:                }
087:            }
088:
089:            /**
090:             * Attempts to load and execute the external Screen. This is used
091:             * when you want to execute a Screen which returns its output via
092:             * a MultiPartElement instead of out the data.getPage() value.
093:             * This allows you to easily chain the execution of Screen modules
094:             * together.
095:             *
096:             * @param data Turbine information.
097:             * @param name Name of object that will execute the screen.
098:             * @exception Exception a generic exception.
099:             */
100:            public ConcreteElement eval(RunData data, String name)
101:                    throws Exception {
102:                // Execute screen
103:                return getInstance(name).build(data);
104:            }
105:
106:            /**
107:             * Attempts to load and execute the Screen. This is used when you
108:             * want to execute a Screen which returns its output via the
109:             * data.getPage() object.
110:             *
111:             * @param data Turbine information.
112:             * @param name Name of object that will execute the screen.
113:             * @exception Exception a generic exception.
114:             */
115:            public void exec(RunData data, String name) throws Exception {
116:                this .eval(data, name);
117:            }
118:
119:            /**
120:             * Pulls out an instance of the object by name.  Name is just the
121:             * single name of the object. This is equal to getInstance but
122:             * returns an Assembler object and is needed to fulfil the Loader
123:             * interface.
124:             *
125:             * @param name Name of object instance.
126:             * @return A Screen with the specified name, or null.
127:             * @exception Exception a generic exception.
128:             */
129:            public Assembler getAssembler(String name) throws Exception {
130:                return getInstance(name);
131:            }
132:
133:            /**
134:             * Pulls out an instance of the Screen by name.  Name is just the
135:             * single name of the Screen.
136:             *
137:             * @param name Name of requested Screen.
138:             * @return A Screen with the specified name, or null.
139:             * @exception Exception a generic exception.
140:             */
141:            public Screen getInstance(String name) throws Exception {
142:                Screen screen = null;
143:
144:                // Check if the screen is already in the cache
145:                if (cache() && this .containsKey(name)) {
146:                    screen = (Screen) this .get(name);
147:                    log.debug("Found Screen " + name + " in the cache!");
148:                } else {
149:                    log.debug("Loading Screen " + name
150:                            + " from the Assembler Broker");
151:
152:                    try {
153:                        if (ab != null) {
154:                            // Attempt to load the screen
155:                            screen = (Screen) ab.getAssembler(
156:                                    AssemblerBrokerService.SCREEN_TYPE, name);
157:                        }
158:                    } catch (ClassCastException cce) {
159:                        // This can alternatively let this exception be thrown
160:                        // So that the ClassCastException is shown in the
161:                        // browser window.  Like this it shows "Screen not Found"
162:                        screen = null;
163:                    }
164:
165:                    if (screen == null) {
166:                        // If we did not find a screen we should try and give
167:                        // the user a reason for that...
168:                        // FIX ME: The AssemblerFactories should each add it's
169:                        // own string here...
170:                        List packages = Turbine.getConfiguration().getList(
171:                                TurbineConstants.MODULE_PACKAGES);
172:
173:                        ObjectUtils.addOnce(packages, GenericLoader
174:                                .getBasePackage());
175:
176:                        throw new ClassNotFoundException(
177:                                "\n\n\tRequested Screen not found: "
178:                                        + name
179:                                        + "\n\tTurbine looked in the following "
180:                                        + "modules.packages path: \n\t"
181:                                        + packages.toString() + "\n");
182:                    } else if (cache()) {
183:                        // The new instance is added to the cache
184:                        addInstance(name, screen);
185:                    }
186:                }
187:                return screen;
188:            }
189:
190:            /**
191:             * The method through which this class is accessed.
192:             *
193:             * @return The single instance of this class.
194:             */
195:            public static ScreenLoader getInstance() {
196:                return instance;
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.