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 * <p>
26 * When the runtime.introspection.uberspect configuration property contains several
27 * uberspector class names, it means those uberspectors will be chained. When an
28 * uberspector in the list other than the leftmost does not implement ChainableUberspector,
29 * then this utility class is used to provide a basic default chaining where the
30 * first non-null result is kept for each introspection call.
31 * </p>
32 *
33 * @since 1.6
34 * @see ChainableUberspector
35 * @version $Id: LinkingUberspector.java 10959 2008-07-01 00:12:29Z sdumitriu $
36 */
37 public class LinkingUberspector extends AbstractChainableUberspector
38 {
39 private Uberspect leftUberspect;
40 private Uberspect rightUberspect;
41
42 /**
43 * Constructor that takes the two uberspectors to link
44 */
45 public LinkingUberspector(Uberspect left,Uberspect right) {
46 leftUberspect = left;
47 rightUberspect = right;
48 }
49
50 /**
51 * {@inheritDoc}
52 * <p>
53 * Init both wrapped uberspectors
54 * </p>
55 *
56 * @see org.apache.velocity.util.introspection.Uberspect#init()
57 */
58 //@Override
59 public void init()
60 {
61 leftUberspect.init();
62 rightUberspect.init();
63 }
64
65 /**
66 * {@inheritDoc}
67 *
68 * @see org.apache.velocity.util.introspection.Uberspect#getIterator(java.lang.Object,
69 * org.apache.velocity.util.introspection.Info)
70 */
71 //@SuppressWarnings("unchecked")
72 //@Override
73 public Iterator getIterator(Object obj, Info i) throws Exception
74 {
75 Iterator it = leftUberspect.getIterator(obj,i);
76 return it != null ? it : rightUberspect.getIterator(obj,i);
77 }
78
79 /**
80 * {@inheritDoc}
81 *
82 * @see org.apache.velocity.util.introspection.Uberspect#getMethod(java.lang.Object, java.lang.String,
83 * java.lang.Object[], org.apache.velocity.util.introspection.Info)
84 */
85 //@Override
86 public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i)
87 throws Exception
88 {
89 VelMethod method = leftUberspect.getMethod(obj,methodName,args,i);
90 return method != null ? method : rightUberspect.getMethod(obj,methodName,args,i);
91 }
92
93 /**
94 * {@inheritDoc}
95 *
96 * @see org.apache.velocity.util.introspection.Uberspect#getPropertyGet(java.lang.Object, java.lang.String,
97 * org.apache.velocity.util.introspection.Info)
98 */
99 //@Override
100 public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i)
101 throws Exception
102 {
103 VelPropertyGet getter = leftUberspect.getPropertyGet(obj,identifier,i);
104 return getter != null ? getter : rightUberspect.getPropertyGet(obj,identifier,i);
105 }
106
107 /**
108 * {@inheritDoc}
109 *
110 * @see org.apache.velocity.util.introspection.Uberspect#getPropertySet(java.lang.Object, java.lang.String,
111 * java.lang.Object, org.apache.velocity.util.introspection.Info)
112 */
113 //@Override
114 public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i)
115 throws Exception
116 {
117 VelPropertySet setter = leftUberspect.getPropertySet(obj,identifier,arg,i);
118 return setter != null ? setter : rightUberspect.getPropertySet(obj,identifier,arg,i);
119 }
120 }