Source Code Cross Referenced for ComponentDefinitionsFactoryWrapper.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » tiles » definition » 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 » struts 1.3.8 » org.apache.struts.tiles.definition 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ComponentDefinitionsFactoryWrapper.java 471754 2006-11-06 14:55:09Z husted $
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:        package org.apache.struts.tiles.definition;
023:
024:        import java.util.HashMap;
025:        import java.util.Map;
026:
027:        import javax.servlet.ServletContext;
028:        import javax.servlet.ServletRequest;
029:
030:        import org.apache.struts.tiles.ComponentDefinition;
031:        import org.apache.struts.tiles.ComponentDefinitionsFactory;
032:        import org.apache.struts.tiles.DefinitionsFactory;
033:        import org.apache.struts.tiles.DefinitionsFactoryConfig;
034:        import org.apache.struts.tiles.DefinitionsFactoryException;
035:        import org.apache.struts.tiles.NoSuchDefinitionException;
036:        import org.apache.struts.util.RequestUtils;
037:
038:        /**
039:         * Wrapper from new definition factory interface to old interface.
040:         * This class provides mapping from the old interface's life cycle to the new life cycle.
041:         * @since 20020708
042:         */
043:        public class ComponentDefinitionsFactoryWrapper implements 
044:                DefinitionsFactory {
045:
046:            /**
047:             * The underlying factory.
048:             */
049:            private ComponentDefinitionsFactory factory = null;
050:
051:            /**
052:             * Factory configuration,
053:             */
054:            private DefinitionsFactoryConfig config = null;
055:
056:            /**
057:             * Constructor.
058:             * Create new wrapper for specified factory.
059:             * @param factory The factory to create a wrapper for.
060:             */
061:            public ComponentDefinitionsFactoryWrapper(
062:                    ComponentDefinitionsFactory factory) {
063:                this .factory = factory;
064:            }
065:
066:            /**
067:             * Constructor.
068:             * Create new wrapper.
069:             * The config object passed to init method should reference a factory implementing
070:             * {@link ComponentDefinitionsFactory}.
071:             */
072:            public ComponentDefinitionsFactoryWrapper() {
073:                super ();
074:            }
075:
076:            /**
077:             * Get requested definition.
078:             * @param name Name of the definition.
079:             * @param request The request we are processing.
080:             * @param servletContext Our servlet context.
081:             * @return ComponentDefition
082:             */
083:            public ComponentDefinition getDefinition(String name,
084:                    ServletRequest request, ServletContext servletContext)
085:                    throws NoSuchDefinitionException,
086:                    DefinitionsFactoryException {
087:
088:                return factory.getDefinition(name, request, servletContext);
089:            }
090:
091:            /**
092:             * Call underlying factory init method.
093:             * @param config DefinitionsFactoryConfig.
094:             * @param servletContext Our servlet context.
095:             */
096:            public void init(DefinitionsFactoryConfig config,
097:                    ServletContext servletContext)
098:                    throws DefinitionsFactoryException {
099:
100:                this .config = config;
101:
102:                // create factory and initialize it
103:                if (factory == null) {
104:                    factory = createFactoryInstance(config
105:                            .getFactoryClassname());
106:                }
107:
108:                factory.initFactory(servletContext, createConfigMap(config));
109:            }
110:
111:            /**
112:             * Do nothing because old life cycle has no equivalent.
113:             */
114:            public void destroy() {
115:                factory = null;
116:            }
117:
118:            /**
119:             * Set underlying factory configuration.
120:             * @param config DefinitionsFactoryConfig to use.
121:             * @param servletContext Our servlet context.
122:             *
123:             */
124:            public void setConfig(DefinitionsFactoryConfig config,
125:                    ServletContext servletContext)
126:                    throws DefinitionsFactoryException {
127:
128:                ComponentDefinitionsFactory newFactory = createFactoryInstance(config
129:                        .getFactoryClassname());
130:
131:                newFactory.initFactory(servletContext, createConfigMap(config));
132:                factory = newFactory;
133:            }
134:
135:            /**
136:             * Get underlying factory configuration.
137:             * @return DefinitionsFactoryConfig.
138:             */
139:            public DefinitionsFactoryConfig getConfig() {
140:                return config;
141:            }
142:
143:            /**
144:             * Get internal factory.
145:             * @return The internal ComponentDefitionsFactory.
146:             */
147:            public ComponentDefinitionsFactory getInternalFactory() {
148:                return factory;
149:            }
150:
151:            /**
152:             * Create Definition factory from provided classname which must implement {@link ComponentDefinitionsFactory}.
153:             * Factory class must extend {@link DefinitionsFactory}.
154:             * @param classname Class name of the factory to create.
155:             * @return newly created factory.
156:             * @throws DefinitionsFactoryException If an error occur while initializing factory
157:             */
158:            protected ComponentDefinitionsFactory createFactoryInstance(
159:                    String classname) throws DefinitionsFactoryException {
160:
161:                try {
162:                    Class factoryClass = RequestUtils
163:                            .applicationClass(classname);
164:                    Object factory = factoryClass.newInstance();
165:                    return (ComponentDefinitionsFactory) factory;
166:
167:                } catch (ClassCastException ex) { // Bad classname
168:                    throw new DefinitionsFactoryException(
169:                            "Error - createDefinitionsFactory : Factory class '"
170:                                    + classname
171:                                    + " must implement 'DefinitionsFactory'.",
172:                            ex);
173:
174:                } catch (ClassNotFoundException ex) { // Bad classname
175:                    throw new DefinitionsFactoryException(
176:                            "Error - createDefinitionsFactory : Bad class name '"
177:                                    + classname + "'.", ex);
178:
179:                } catch (InstantiationException ex) { // Bad constructor or error
180:                    throw new DefinitionsFactoryException(ex);
181:
182:                } catch (IllegalAccessException ex) {
183:                    throw new DefinitionsFactoryException(ex);
184:                }
185:
186:            }
187:
188:            /**
189:             * Return String representation.
190:             * Calls toString() on underlying factory.
191:             * @return String representation.
192:             */
193:            public String toString() {
194:                return getInternalFactory().toString();
195:            }
196:
197:            /**
198:             * Create map of configuration attributes from configuration object.
199:             * Mapping is done between old names and new names.
200:             * @param config The DefinitionsFactoryConfig to use.
201:             * @return Map Map of name/value pairs.
202:             */
203:            public static Map createConfigMap(DefinitionsFactoryConfig config) {
204:                Map map = new HashMap(config.getAttributes());
205:                // Add property attributes using old names
206:                map
207:                        .put(
208:                                DefinitionsFactoryConfig.DEFINITIONS_CONFIG_PARAMETER_NAME,
209:                                config.getDefinitionConfigFiles());
210:
211:                map
212:                        .put(
213:                                DefinitionsFactoryConfig.PARSER_VALIDATE_PARAMETER_NAME,
214:                                (config.getParserValidate() ? Boolean.TRUE
215:                                        .toString() : Boolean.FALSE.toString()));
216:
217:                if (!"org.apache.struts.tiles.xmlDefinition.I18nFactorySet"
218:                        .equals(config.getFactoryClassname())) {
219:
220:                    map
221:                            .put(
222:                                    DefinitionsFactoryConfig.FACTORY_CLASSNAME_PARAMETER_NAME,
223:                                    config.getFactoryClassname());
224:                }
225:
226:                return map;
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.