Source Code Cross Referenced for ReportInvalidReferences.java in  » Template-Engine » Velocity » org » apache » velocity » app » event » implement » 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 » Template Engine » Velocity » org.apache.velocity.app.event.implement 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.app.event.implement;
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.ArrayList;
023:        import java.util.List;
024:
025:        import org.apache.velocity.app.event.InvalidReferenceEventHandler;
026:        import org.apache.velocity.context.Context;
027:        import org.apache.velocity.exception.ParseErrorException;
028:        import org.apache.velocity.runtime.RuntimeServices;
029:        import org.apache.velocity.util.RuntimeServicesAware;
030:        import org.apache.velocity.util.introspection.Info;
031:
032:        /**
033:         * Use this event handler to flag invalid references.  Since this 
034:         * is intended to be used for a specific request, this should be
035:         * used as a local event handler attached to a specific context
036:         * instead of being globally defined in the Velocity properties file.
037:         * 
038:         * <p>
039:         * Note that InvalidReferenceHandler can be used
040:         * in two modes.  If the Velocity properties file contains the following:
041:         * <pre>
042:         * eventhandler.invalidreference.exception = true
043:         * </pre>
044:         * then the event handler will throw a ParseErrorRuntimeException upon 
045:         * hitting the first invalid reference.  This stops processing and is 
046:         * passed through to the application code.  The ParseErrorRuntimeException
047:         * contain information about the template name, line number, column number,
048:         * and invalid reference.
049:         * 
050:         * <p>
051:         * If this configuration setting is false or omitted then the page 
052:         * will be processed as normal, but all invalid references will be collected
053:         * in a List of InvalidReferenceInfo objects.
054:         * 
055:         * <p>This feature should be regarded as experimental.
056:         * 
057:         * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
058:         * @version $Id: ReportInvalidReferences.java 470265 2006-11-02 07:45:02Z wglass $
059:         */
060:        public class ReportInvalidReferences implements 
061:                InvalidReferenceEventHandler, RuntimeServicesAware {
062:
063:            public static final String EVENTHANDLER_INVALIDREFERENCE_EXCEPTION = "eventhandler.invalidreference.exception";
064:
065:            /** 
066:             * List of InvalidReferenceInfo objects
067:             */
068:            List invalidReferences = new ArrayList();
069:
070:            /**
071:             * If true, stop at the first invalid reference and throw an exception.
072:             */
073:            private boolean stopOnFirstInvalidReference = false;
074:
075:            /**
076:             * Collect the error and/or throw an exception, depending on configuration.
077:             *
078:             * @param context the context when the reference was found invalid
079:             * @param reference string with complete invalid reference
080:             * @param object the object referred to, or null if not found
081:             * @param property the property name from the reference
082:             * @param info contains template, line, column details
083:             * @return always returns null
084:             * @throws ParseErrorException
085:             */
086:            public Object invalidGetMethod(Context context, String reference,
087:                    Object object, String property, Info info) {
088:                reportInvalidReference(reference, info);
089:                return null;
090:            }
091:
092:            /**
093:             * Collect the error and/or throw an exception, depending on configuration.
094:             *
095:             * @param context the context when the reference was found invalid
096:             * @param reference complete invalid reference
097:             * @param object the object referred to, or null if not found
098:             * @param method the property name from the reference
099:             * @param info contains template, line, column details
100:             * @return always returns null
101:             * @throws ParseErrorException
102:             */
103:            public Object invalidMethod(Context context, String reference,
104:                    Object object, String method, Info info) {
105:                if (reference == null) {
106:                    reportInvalidReference(object.getClass().getName() + "."
107:                            + method, info);
108:                } else {
109:                    reportInvalidReference(reference, info);
110:                }
111:                return null;
112:            }
113:
114:            /**
115:             * Collect the error and/or throw an exception, depending on configuration.
116:             *
117:             * @param context the context when the reference was found invalid
118:             * @param leftreference left reference being assigned to
119:             * @param rightreference invalid reference on the right
120:             * @param info contains info on template, line, col
121:             * @return loop to end -- always returns false
122:             */
123:            public boolean invalidSetMethod(Context context,
124:                    String leftreference, String rightreference, Info info) {
125:                reportInvalidReference(leftreference, info);
126:                return false;
127:            }
128:
129:            /**
130:             * Check for an invalid reference and collect the error or throw an exception 
131:             * (depending on configuration).
132:             * 
133:             * @param reference the invalid reference
134:             * @param info line, column, template name
135:             */
136:            private void reportInvalidReference(String reference, Info info) {
137:                InvalidReferenceInfo invalidReferenceInfo = new InvalidReferenceInfo(
138:                        reference, info);
139:                invalidReferences.add(invalidReferenceInfo);
140:
141:                if (stopOnFirstInvalidReference) {
142:                    throw new ParseErrorException(
143:                            "Error in page - invalid reference.  ", info,
144:                            invalidReferenceInfo.getInvalidReference());
145:                }
146:            }
147:
148:            /**
149:             * All invalid references during the processing of this page.
150:             * @return a List of InvalidReferenceInfo objects
151:             */
152:            public List getInvalidReferences() {
153:                return invalidReferences;
154:            }
155:
156:            /**
157:             * Called automatically when event cartridge is initialized.
158:             * @param rs RuntimeServices object assigned during initialization
159:             */
160:            public void setRuntimeServices(RuntimeServices rs) {
161:                stopOnFirstInvalidReference = rs.getConfiguration().getBoolean(
162:                        EVENTHANDLER_INVALIDREFERENCE_EXCEPTION, false);
163:            }
164:
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.