View Javadoc

1   package org.apache.onami.cache;
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.lang.annotation.Annotation;
23  import java.lang.reflect.Method;
24  import java.util.Set;
25  
26  import javax.cache.annotation.CacheInvocationParameter;
27  import javax.cache.annotation.CacheKeyInvocationContext;
28  
29  import com.google.inject.Injector;
30  
31  final class DefaultCacheKeyInvocationContext<A extends Annotation>
32      implements CacheKeyInvocationContext<A>
33  {
34  
35      private final Injector injector;
36  
37      private final String cacheName;
38  
39      private final Object target;
40  
41      protected final Method method;
42  
43      private final CacheInvocationParameter[] allParameters;
44  
45      private final CacheInvocationParameter[] keyParameters;
46  
47      private final CacheInvocationParameter valueParameter;
48  
49      private final Set<Annotation> methodAnnotations;
50  
51      private final A interceptedAnnotation;
52  
53      public DefaultCacheKeyInvocationContext( Injector injector,
54                                               String cacheName,
55                                               Object target,
56                                               Method method,
57                                               CacheInvocationParameter[] allParameters,
58                                               CacheInvocationParameter[] keyParameters,
59                                               CacheInvocationParameter valueParameter,
60                                               Set<Annotation> methodAnnotations,
61                                               A interceptedAnnotation )
62      {
63          this.injector = injector;
64          this.cacheName = cacheName;
65          this.target = target;
66          this.method = method;
67          this.allParameters = allParameters;
68          this.keyParameters = keyParameters;
69          this.valueParameter = valueParameter;
70          this.methodAnnotations = methodAnnotations;
71          this.interceptedAnnotation = interceptedAnnotation;
72      }
73  
74      public final Method getMethod()
75      {
76          return method;
77      }
78  
79      public final Set<Annotation> getAnnotations()
80      {
81          return methodAnnotations;
82      }
83  
84      public final A getCacheAnnotation()
85      {
86          return interceptedAnnotation;
87      }
88  
89      public final String getCacheName()
90      {
91          return cacheName;
92      }
93  
94      public final Object getTarget()
95      {
96          return target;
97      }
98  
99      public final CacheInvocationParameter[] getAllParameters()
100     {
101         return allParameters;
102     }
103 
104     public final <T> T unwrap( Class<T> cls )
105     {
106         return injector.getInstance( cls );
107     }
108 
109     public CacheInvocationParameter[] getKeyParameters()
110     {
111         return keyParameters;
112     }
113 
114     public CacheInvocationParameter getValueParameter()
115     {
116         return valueParameter;
117     }
118 
119 }