001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.increment;
016    
017    import com.liferay.portal.kernel.concurrent.IncreasableEntry;
018    import com.liferay.portal.kernel.increment.Increment;
019    
020    import org.aopalliance.intercept.MethodInterceptor;
021    import org.aopalliance.intercept.MethodInvocation;
022    
023    /**
024     * @author Zsolt Berentey
025     */
026    public class BufferedIncreasableEntry<K, T>
027            extends IncreasableEntry<K, Increment<T>> {
028    
029            public BufferedIncreasableEntry(
030                    MethodInterceptor nextInterceptor, MethodInvocation methodInvocation,
031                    K key, Increment<T> value) {
032    
033                    super(key, value);
034    
035                    _methodInvocation = methodInvocation;
036                    _nextInterceptor = nextInterceptor;
037            }
038    
039            public Increment<T> doIncrease(
040                    Increment<T> originalValue, Increment<T> deltaValue) {
041    
042                    return originalValue.increaseForNew(deltaValue.getValue());
043            }
044    
045            public void proceed() throws Throwable {
046                    Object[] arguments = _methodInvocation.getArguments();
047    
048                    arguments[arguments.length - 1] = getValue().getValue();
049    
050                    _nextInterceptor.invoke(_methodInvocation);
051            }
052    
053            public String toString() {
054                    return _methodInvocation.toString();
055            }
056    
057            private MethodInvocation _methodInvocation;
058            private MethodInterceptor _nextInterceptor;
059    
060    }