01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.core;
18:
19: import java.lang.reflect.Constructor;
20: import java.lang.reflect.Method;
21: import java.util.Iterator;
22: import java.util.LinkedList;
23: import java.util.List;
24:
25: /**
26: * ParameterNameDiscoverer implementation that tries several ParameterNameDiscoverers
27: * in succession. Those added first in the <code>addDiscoverer</code> method have
28: * highest priority. If one returns <code>null</code>, the next will be tried.
29: *
30: * <p>The default behavior is always to return <code>null</code>
31: * if no discoverer matches.
32: *
33: * @author Rod Johnson
34: * @author Juergen Hoeller
35: * @since 2.0
36: */
37: public class PrioritizedParameterNameDiscoverer implements
38: ParameterNameDiscoverer {
39:
40: private final List parameterNameDiscoverers = new LinkedList();
41:
42: /**
43: * Add a further ParameterNameDiscoverer to the list of discoverers
44: * that this PrioritizedParameterNameDiscoverer checks.
45: */
46: public void addDiscoverer(ParameterNameDiscoverer pnd) {
47: this .parameterNameDiscoverers.add(pnd);
48: }
49:
50: public String[] getParameterNames(Method method) {
51: for (Iterator it = this .parameterNameDiscoverers.iterator(); it
52: .hasNext();) {
53: ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it
54: .next();
55: String[] result = pnd.getParameterNames(method);
56: if (result != null) {
57: return result;
58: }
59: }
60: return null;
61: }
62:
63: public String[] getParameterNames(Constructor ctor) {
64: for (Iterator it = this .parameterNameDiscoverers.iterator(); it
65: .hasNext();) {
66: ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it
67: .next();
68: String[] result = pnd.getParameterNames(ctor);
69: if (result != null) {
70: return result;
71: }
72: }
73: return null;
74: }
75:
76: }
|