001// Copyright 2014 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007// http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014package org.apache.tapestry5.jcache.internal;
015
016import org.apache.tapestry5.plastic.MethodInvocation;
017import org.jsr107.ri.annotations.AbstractInternalCacheKeyInvocationContext;
018import org.jsr107.ri.annotations.StaticCacheKeyInvocationContext;
019
020import java.lang.annotation.Annotation;
021import java.lang.reflect.Method;
022
023/**
024 * Tapestry-IoC specific cache key invocation context using {@link MethodInvocation}
025 * 
026 * @param <A>
027 *            The type of annotation this context information is for. One of
028 *            {@link javax.cache.annotation.CacheResult}, {@link javax.cache.annotation.CachePut},
029 *            {@link javax.cache.annotation.CacheRemove}, or
030 *            {@link javax.cache.annotation.CacheRemoveAll}.
031 */
032public class TapestryIoCInternalCacheKeyInvocationContext<A extends Annotation> extends
033        AbstractInternalCacheKeyInvocationContext<MethodInvocation, A>
034{
035
036    /**
037     * Create new cache key invocation context for the static context and
038     * invocation
039     * 
040     * @param staticCacheKeyInvocationContext
041     *            Static information about the invoked method
042     * @param invocation
043     *            The AOP Alliance invocation context
044     */
045    public TapestryIoCInternalCacheKeyInvocationContext(
046            StaticCacheKeyInvocationContext<A> staticCacheKeyInvocationContext,
047            MethodInvocation invocation)
048    {
049        super(staticCacheKeyInvocationContext, invocation);
050    }
051
052    @Override
053    protected Object[] getParameters(MethodInvocation invocation)
054    {
055        Object[] parameters = new Object[invocation.getMethod().getParameterTypes().length];
056        for (int i = 0; i < parameters.length; i++)
057        {
058            parameters[i] = invocation.getParameter(i);
059        }
060        return parameters;
061    }
062
063    @Override
064    protected Method getMethod(MethodInvocation invocation)
065    {
066        return invocation.getMethod();
067    }
068
069    @Override
070    protected Object getTarget(MethodInvocation invocation)
071    {
072        return invocation.getInstance();
073    }
074
075}