Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ClassCacheHandler |
|
| 5.5;5.5 |
1 | package org.apache.commons.ognl.internal; | |
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 | /* | |
23 | * $Id: ClassCacheHandler.java 1203584 2011-11-18 10:54:19Z mcucchiara $ | |
24 | */ | |
25 | public class ClassCacheHandler | |
26 | { | |
27 | ||
28 | private ClassCacheHandler() | |
29 | 0 | { |
30 | 0 | } |
31 | ||
32 | public static <T> T getHandler( Class<?> forClass, ClassCache<T> handlers ) | |
33 | throws CacheException | |
34 | { | |
35 | T answer; | |
36 | ||
37 | 2902 | synchronized ( handlers ) |
38 | { | |
39 | 2902 | answer = handlers.get( forClass ); |
40 | 2902 | if ( answer == null ) |
41 | { | |
42 | Class<?> keyFound; | |
43 | ||
44 | 209 | if ( forClass.isArray() ) |
45 | { | |
46 | 5 | answer = handlers.get( Object[].class ); |
47 | 5 | keyFound = null; |
48 | } | |
49 | else | |
50 | { | |
51 | 204 | keyFound = forClass; |
52 | outer: | |
53 | 439 | for ( Class<?> clazz = forClass; clazz != null; clazz = clazz.getSuperclass() ) |
54 | { | |
55 | 337 | answer = handlers.get( clazz ); |
56 | 337 | if ( answer == null ) |
57 | { | |
58 | 246 | Class<?>[] interfaces = clazz.getInterfaces(); |
59 | 348 | for ( Class<?> iface : interfaces ) |
60 | { | |
61 | 113 | answer = handlers.get( iface ); |
62 | 113 | if ( answer == null ) |
63 | { | |
64 | /* Try super-interfaces */ | |
65 | 104 | answer = getHandler( iface, handlers ); |
66 | } | |
67 | 113 | if ( answer != null ) |
68 | { | |
69 | 11 | keyFound = iface; |
70 | 11 | break outer; |
71 | } | |
72 | } | |
73 | 235 | } |
74 | else | |
75 | { | |
76 | 91 | keyFound = clazz; |
77 | 91 | break; |
78 | } | |
79 | } | |
80 | } | |
81 | 209 | if ( answer != null ) |
82 | { | |
83 | 107 | if ( keyFound != forClass ) |
84 | { | |
85 | 107 | handlers.put( forClass, answer ); |
86 | } | |
87 | } | |
88 | } | |
89 | 2902 | } |
90 | 2902 | return answer; |
91 | ||
92 | } | |
93 | } |