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


001:        package org.apache.turbine.om;
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.HashMap;
023:        import java.util.Map;
024:
025:        import org.apache.turbine.services.pull.ApplicationTool;
026:        import org.apache.turbine.util.pool.Recyclable;
027:
028:        /**
029:         * A Pull tool to make om objects available to a template
030:         *
031:         * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
032:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033:         * @version $Id: OMTool.java 534527 2007-05-02 16:10:59Z tv $
034:         */
035:        public class OMTool implements  ApplicationTool, Recyclable {
036:            // private RunData data;
037:            private HashMap omMap;
038:
039:            // note the following could be a static attribute to reduce memory
040:            // footprint. Might require a service to front load the
041:            // PullHelpers to avoid MT issues. A multiple write is not so bad
042:            // though
043:
044:            /** The cache of PullHelpers. **/
045:            private static Map pullMap = new HashMap();
046:
047:            /**
048:             *  The Factory responsible for retrieving the
049:             *  objects from storage
050:             */
051:            private RetrieverFactory omFactory;
052:
053:            public OMTool() throws Exception {
054:                omMap = new HashMap();
055:                // String className = Turbine.getConfiguration()
056:                //         .getString("tool.om.factory");
057:                //         RetrieverFactory omFactory =
058:                //             (RetrieverFactory)Class.forName(className).newInstance();
059:            }
060:
061:            /**
062:             * Prepares tool for a single request
063:             */
064:            public void init(Object runData) {
065:                // data = (RunData)runData;
066:            }
067:
068:            /**
069:             * Implementation of ApplicationTool interface is not needed for this
070:             * method as the tool is request scoped
071:             */
072:            public void refresh() {
073:                // empty
074:            }
075:
076:            /**
077:             * Inner class to present a nice interface to the template designer
078:             */
079:            private class PullHelper {
080:                String omName;
081:
082:                private PullHelper(String omName) {
083:                    this .omName = omName;
084:                }
085:
086:                public Object setKey(String key) throws Exception {
087:                    Object om = null;
088:
089:                    String inputKey = omName + key;
090:                    if (omMap.containsKey(inputKey)) {
091:                        om = omMap.get(inputKey);
092:                    } else {
093:                        om = omFactory.getInstance(omName).retrieve(key);
094:                        omMap.put(inputKey, om);
095:                    }
096:
097:                    return om;
098:                }
099:            }
100:
101:            public Object get(String omName) throws Exception {
102:                if (!pullMap.containsKey(omName)) {
103:                    // MT could overwrite a PullHelper, but that is not a problem
104:                    // should still synchronize to avoid two threads adding at
105:                    // same time
106:                    synchronized (this .getClass()) {
107:                        pullMap.put(omName, new OMTool.PullHelper(omName));
108:                    }
109:                }
110:
111:                return pullMap.get(omName);
112:            }
113:
114:            public Object get(String omName, String key) throws Exception {
115:                return ((OMTool.PullHelper) get(omName)).setKey(key);
116:            }
117:
118:            public String getName() {
119:                return "om";
120:            }
121:
122:            // ****************** Recyclable implementation ************************
123:
124:            private boolean disposed;
125:
126:            /**
127:             * Recycles the object for a new client. Recycle methods with
128:             * parameters must be added to implementing object and they will be
129:             * automatically called by pool implementations when the object is
130:             * taken from the pool for a new client. The parameters must
131:             * correspond to the parameters of the constructors of the object.
132:             * For new objects, constructors can call their corresponding recycle
133:             * methods whenever applicable.
134:             * The recycle methods must call their super.
135:             */
136:            public void recycle() {
137:                disposed = false;
138:            }
139:
140:            /**
141:             * Disposes the object after use. The method is called
142:             * when the object is returned to its pool.
143:             * The dispose method must call its super.
144:             */
145:            public void dispose() {
146:                omMap.clear();
147:                // data = null;
148:                disposed = true;
149:            }
150:
151:            /**
152:             * Checks whether the recyclable has been disposed.
153:             * @return true, if the recyclable is disposed.
154:             */
155:            public boolean isDisposed() {
156:                return disposed;
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.