• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.apache.velocity.app.event;
2 
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21 
22 import org.apache.velocity.context.Context;
23 import org.apache.velocity.util.introspection.Info;
24 
25 /**
26  * Event handler called when an invalid reference is encountered.  Allows
27  * the application to report errors or substitute return values. May be chained
28  * in sequence; the behavior will differ per method.
29  *
30  * <p>This feature should be regarded as experimental.
31  *
32  * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
33  * @version $Id$
34  * @since 1.5
35  */
36 public interface InvalidReferenceEventHandler extends EventHandler
37 {
38 
39     /**
40      * Called when object is null or there is no getter for the given
41      * property.  Also called for invalid references without properties.
42      * invalidGetMethod() will be called in sequence for
43      * each link in the chain until the first non-null value is
44      * returned.
45      *
46      * @param context the context when the reference was found invalid
47      * @param reference string with complete invalid reference
48      * @param object the object referred to, or null if not found
49      * @param property the property name from the reference
50      * @param info contains template, line, column details
51      * @return substitute return value for missing reference, or null if no substitute
52      */
invalidGetMethod(Context context, String reference, Object object, String property, Info info)53     Object invalidGetMethod(Context context, String reference,
54                             Object object, String property, Info info);
55 
56     /**
57      * Called when object is null or there is no setter for the given
58      * property.  invalidSetMethod() will be called in sequence for
59      * each link in the chain until a true value is returned.  It's
60      * recommended that false be returned as a default to allow
61      * for easy chaining.
62      *
63      * @param context the context when the reference was found invalid
64      * @param leftreference left reference being assigned to
65      * @param rightreference invalid reference on the right
66      * @param info contains info on template, line, col
67      *
68      * @return if true then stop calling invalidSetMethod along the
69      * chain.
70      */
invalidSetMethod(Context context, String leftreference, String rightreference, Info info)71     boolean invalidSetMethod(Context context, String leftreference,
72                              String rightreference, Info info);
73 
74     /**
75      * Called when object is null or the given method does not exist.
76      * invalidMethod() will be called in sequence for each link in
77      * the chain until the first non-null value is returned.
78      *
79      * @param context the context when the reference was found invalid
80      * @param reference string with complete invalid reference
81      * @param object the object referred to, or null if not found
82      * @param method the name of the (non-existent) method
83      * @param info contains template, line, column details
84      * @return substitute return value for missing reference, or null if no substitute
85      */
invalidMethod(Context context, String reference, Object object, String method, Info info)86     Object invalidMethod(Context context, String reference,
87                          Object object, String method, Info info);
88 }
89