• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.apache.velocity.util.introspection;
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 java.util.Iterator;
23 
24 /**
25  * Default implementation of a {@link ChainableUberspector chainable uberspector} that forwards all calls to the wrapped
26  * uberspector (when that is possible). It should be used as the base class for all chainable uberspectors.
27  *
28  * @version $Id: $
29  * @since 1.6
30  * @see ChainableUberspector
31  */
32 public abstract class AbstractChainableUberspector extends UberspectImpl implements ChainableUberspector
33 {
34     /** The wrapped (decorated) uberspector. */
35     protected Uberspect inner;
36 
37     /**
38      * {@inheritDoc}
39      *
40      * @see ChainableUberspector#wrap(org.apache.velocity.util.introspection.Uberspect)
41      * @see #inner
42      */
43     @Override
wrap(Uberspect inner)44     public void wrap(Uberspect inner)
45     {
46         this.inner = inner;
47     }
48 
49     /**
50      * init - the chainable uberspector is responsible for the initialization of the wrapped uberspector
51      *
52      * @see org.apache.velocity.util.introspection.Uberspect#init()
53      */
54     //@Override
55     @Override
init()56     public void init()
57     {
58         if (this.inner != null) {
59             try {
60                 this.inner.init();
61             } catch (Exception e) {
62                 log.error(e.getMessage(), e);
63                 this.inner = null;
64             }
65         }
66     }
67 
68     /**
69      * {@inheritDoc}
70      *
71      * @see org.apache.velocity.util.introspection.Uberspect#getIterator(java.lang.Object,
72      *      org.apache.velocity.util.introspection.Info)
73      */
74     //@SuppressWarnings("unchecked")
75     //@Override
76     @Override
getIterator(Object obj, Info i)77     public Iterator getIterator(Object obj, Info i)
78     {
79         return (this.inner != null) ? this.inner.getIterator(obj, i) : null;
80     }
81 
82     /**
83      * {@inheritDoc}
84      *
85      * @see org.apache.velocity.util.introspection.Uberspect#getMethod(java.lang.Object, java.lang.String,
86      *      java.lang.Object[], org.apache.velocity.util.introspection.Info)
87      */
88     //@Override
89     @Override
getMethod(Object obj, String methodName, Object[] args, Info i)90     public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i)
91     {
92         return (this.inner != null) ? this.inner.getMethod(obj, methodName, args, i) : null;
93     }
94 
95     /**
96      * {@inheritDoc}
97      *
98      * @see org.apache.velocity.util.introspection.Uberspect#getPropertyGet(java.lang.Object, java.lang.String,
99      *      org.apache.velocity.util.introspection.Info)
100      */
101     //@Override
102     @Override
getPropertyGet(Object obj, String identifier, Info i)103     public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i)
104     {
105         return (this.inner != null) ? this.inner.getPropertyGet(obj, identifier, i) : null;
106     }
107 
108     /**
109      * {@inheritDoc}
110      *
111      * @see org.apache.velocity.util.introspection.Uberspect#getPropertySet(java.lang.Object, java.lang.String,
112      *      java.lang.Object, org.apache.velocity.util.introspection.Info)
113      */
114     //@Override
115     @Override
getPropertySet(Object obj, String identifier, Object arg, Info i)116     public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i)
117     {
118         return (this.inner != null) ? this.inner.getPropertySet(obj, identifier, arg, i) : null;
119     }
120 }
121