KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > PrioritizedParameterNameDiscoverer


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
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 ParameterNameDiscoverer {
38     
39     private final List JavaDoc parameterNameDiscoverers = new LinkedList JavaDoc();
40
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
51     public String JavaDoc[] getParameterNames(Method JavaDoc method) {
52         for (Iterator JavaDoc it = this.parameterNameDiscoverers.iterator(); it.hasNext(); ) {
53             ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it.next();
54             String JavaDoc[] result = pnd.getParameterNames(method);
55             if (result != null) {
56                 return result;
57             }
58         }
59         return null;
60     }
61
62     public String JavaDoc[] getParameterNames(Constructor JavaDoc ctor) {
63         for (Iterator JavaDoc it = this.parameterNameDiscoverers.iterator(); it.hasNext(); ) {
64             ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it.next();
65             String JavaDoc[] result = pnd.getParameterNames(ctor);
66             if (result != null) {
67                 return result;
68             }
69         }
70         return null;
71     }
72
73 }
74
Popular Tags