Source Code Cross Referenced for AbstractElementProcessorFactory.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » elementprocessor » impl » 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 » apache lenya 2.0 » org.apache.cocoon.components.elementprocessor.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.components.elementprocessor.impl;
018:
019:        import java.lang.reflect.Constructor;
020:        import java.lang.reflect.InvocationTargetException;
021:        import java.util.HashMap;
022:        import java.util.Map;
023:
024:        import org.apache.avalon.framework.component.Component;
025:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
026:
027:        import org.apache.cocoon.components.elementprocessor.CannotCreateElementProcessorException;
028:        import org.apache.cocoon.components.elementprocessor.ElementProcessor;
029:        import org.apache.cocoon.components.elementprocessor.ElementProcessorFactory;
030:
031:        /**
032:         * Create instances of specific ElementProcessor implementations to
033:         * handle specific XML elements and their content.
034:         *
035:         * @author Marc Johnson (marc_johnson27591@hotmail.com)
036:         * @version CVS $Id: AbstractElementProcessorFactory.java 433543 2006-08-22 06:22:54Z crossley $
037:         */
038:        public abstract class AbstractElementProcessorFactory extends
039:                AbstractLogEnabled implements  ElementProcessorFactory,
040:                Component {
041:
042:            // uses XML element names as keys and ElementProcessor progenitors
043:            // as values. An ElementProcessor progenitor is an Object that can
044:            // be used to create a new ElementProcessor instance that is
045:            // specific to a particular XML element. A progenitor may be a
046:            // Constructor or Class that can construct a new instance of an
047:            // appropriate ElementProcessor implementation, or any other
048:            // Object that an extension of AbstractElementProcessorFactory finds
049:            // useful to create new ElementProcessor instances.
050:            private Map _element_processor_map;
051:
052:            /**
053:             * Protected default constructor
054:             */
055:
056:            protected AbstractElementProcessorFactory() {
057:                _element_processor_map = new HashMap();
058:            }
059:
060:            /**
061:             * Given an XML element name, create and return an appropriate
062:             * ElementProcessor.
063:             *
064:             * @param name element name
065:             *
066:             * @return the specified ElementProcessor
067:             *
068:             * @exception CannotCreateElementProcessorException if there is no
069:             *            ElementProcessor available for the specified name
070:             */
071:
072:            public ElementProcessor createElementProcessor(final String name)
073:                    throws CannotCreateElementProcessorException {
074:                Object progenitor = lookupElementProcessorProgenitor(name);
075:
076:                if (progenitor == null) {
077:                    CannotCreateElementProcessorException exception = new CannotCreateElementProcessorException(
078:                            "Cannot find progenitor for that name");
079:                    exception.setElementName(name);
080:                    throw exception;
081:                }
082:                ElementProcessor processor = null;
083:
084:                try {
085:                    processor = doCreateElementProcessor(progenitor);
086:                } catch (CannotCreateElementProcessorException e) {
087:                    e.setElementName(name);
088:                    throw e;
089:                }
090:                return processor;
091:            }
092:
093:            /**
094:             * A method for extending classes to populate the map.
095:             *
096:             * @param name the element name for this progenitor; cannot be
097:             *             null ot empty
098:             * @param progenitor an object that can be used to generate an
099:             *                   appropriate ElementProcessor; cannot be nukk
100:             *
101:             * @exception IllegalArgumentException if name is already in the
102:             *            map or progenitor is null.
103:             */
104:
105:            protected void addElementProcessorProgenitor(final String name,
106:                    final Object progenitor) {
107:                if (name == null || name.length() == 0) {
108:                    throw new IllegalArgumentException(
109:                            "Cannot use null or empty name as a key");
110:                }
111:                if (progenitor == null) {
112:                    throw new IllegalArgumentException(
113:                            "Cannot add null progenitor to the map");
114:                }
115:                if (_element_processor_map.put(name, progenitor) != null) {
116:                    throw new IllegalArgumentException(name
117:                            + " is already in use in the map");
118:                }
119:            }
120:
121:            /**
122:             * A method to get the progenitor value associated with a
123:             * specified element name.
124:             *
125:             * @param name the element name
126:             *
127:             * @return the associated ElementProcessor progenitor; will be
128:             *         null if the element name has not yet been associated
129:             *         with a progenitor.
130:             */
131:
132:            protected Object lookupElementProcessorProgenitor(final String name) {
133:                Object obj = _element_processor_map.get(name);
134:                if (obj == null && !name.equals("*")) {
135:                    obj = lookupElementProcessorProgenitor("*");
136:                }
137:                return obj;
138:            }
139:
140:            /**
141:             * The method that a concrete extension of AbstractElementProcessorFactory
142:             * must implement. When this method is called, the element name
143:             * has already been looked up in the map and a progenitor Object
144:             * has been acquired. The progenitor is guaranteed not to be null.
145:             *
146:             * @param progenitor the object from which to create an
147:             *                   ElementProcessor
148:             *
149:             * @return freshly created ElementProcessor
150:             *
151:             * @exception CannotCreateElementProcessorException if the
152:             *            specified ElementProcessor cannot be created.
153:             */
154:
155:            protected abstract ElementProcessor doCreateElementProcessor(
156:                    final Object progenitor)
157:                    throws CannotCreateElementProcessorException;
158:
159:            /**
160:             * A reference implementation of doCreateElementProcessor that can
161:             * be used by an extending class whose progenitors are Class
162:             * objects for ElementProcessor implementations.
163:             *
164:             * @param progenitor a Class representing an ElementProcessor
165:             *
166:             * @return the new ElementProcessor instance
167:             *
168:             * @exception CannotCreateElementProcessorException if the
169:             *            ElementProcessor cannot be created.
170:             */
171:
172:            protected ElementProcessor createNewElementProcessorInstance(
173:                    final Class progenitor)
174:                    throws CannotCreateElementProcessorException {
175:                ElementProcessor rval = null;
176:
177:                try {
178:                    rval = (ElementProcessor) progenitor.newInstance();
179:                    if (rval instanceof  AbstractLogEnabled) {
180:                        ((AbstractLogEnabled) rval).enableLogging(getLogger());
181:                    }
182:                } catch (ExceptionInInitializerError e) {
183:                    throw new CannotCreateElementProcessorException(
184:                            "an exception ("
185:                                    + e
186:                                    + ") occurred in initializing the associated ElementProcessor class");
187:                } catch (SecurityException e) {
188:                    throw new CannotCreateElementProcessorException(
189:                            "a security exception was caught while creating the associated ElementProcessor");
190:                } catch (InstantiationException e) {
191:                    throw new CannotCreateElementProcessorException(
192:                            "associated ElementProcessor is an interface or abstract class or has no zero-parameter constructor");
193:                } catch (IllegalAccessException e) {
194:                    throw new CannotCreateElementProcessorException(
195:                            "cannot access ElementProcessor class or its zero-parameter constructor");
196:                } catch (ClassCastException e) {
197:                    throw new CannotCreateElementProcessorException(
198:                            "object created does not implement ElementProcessor");
199:                } catch (Exception e) {
200:                    throw new CannotCreateElementProcessorException(
201:                            "exception ("
202:                                    + e
203:                                    + ") occured while creating new instance of ElementProcessor");
204:                }
205:                if (rval == null) {
206:                    throw new CannotCreateElementProcessorException(
207:                            "somehow generated a null ElementProcessor");
208:                }
209:                return rval;
210:            }
211:
212:            /**
213:             * A reference implementation of doCreateElementProcessor that can
214:             * be used by an extending class whose progenitors are Constructor
215:             * objects that can create new instances of ElementProcessor
216:             * implementations.
217:             *
218:             * @param progenitor a Constructor of an ElementProcessor
219:             *
220:             * @return the newly created ElementProcessor
221:             *
222:             * @exception CannotCreateElementProcessorException if the
223:             *            ElementProcessor cannot be created.
224:             */
225:
226:            protected ElementProcessor constructElementProcessor(
227:                    final Constructor progenitor)
228:                    throws CannotCreateElementProcessorException {
229:                ElementProcessor rval = null;
230:
231:                try {
232:                    rval = (ElementProcessor) progenitor
233:                            .newInstance(new Object[0]);
234:                    if (rval instanceof  AbstractLogEnabled) {
235:                        ((AbstractLogEnabled) rval).enableLogging(getLogger());
236:                    }
237:                } catch (ExceptionInInitializerError e) {
238:                    throw new CannotCreateElementProcessorException(
239:                            "an exception ("
240:                                    + e
241:                                    + ")occurred in initializing the associated ElementProcessor class");
242:                } catch (IllegalArgumentException e) {
243:                    throw new CannotCreateElementProcessorException(
244:                            "the ElementProcessor constructor apparently needs parameters");
245:                } catch (InstantiationException e) {
246:                    throw new CannotCreateElementProcessorException(
247:                            "associated ElementProcessor is an interface or abstract class");
248:                } catch (IllegalAccessException e) {
249:                    throw new CannotCreateElementProcessorException(
250:                            "cannot access ElementProcessor class or its zero-parameter constructor");
251:                } catch (InvocationTargetException e) {
252:                    throw new CannotCreateElementProcessorException(
253:                            "ElementProcessor constructor threw an exception ["
254:                                    + e.toString() + "]");
255:                } catch (ClassCastException e) {
256:                    throw new CannotCreateElementProcessorException(
257:                            "object created does not implement ElementProcessor");
258:                }
259:                if (rval == null) {
260:                    throw new CannotCreateElementProcessorException(
261:                            "somehow generated a null ElementProcessor");
262:                }
263:                return rval;
264:            }
265:
266:        } // end public abstract class AbstractElementProcessorFactory
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.