1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.increment;
16  
17  import com.liferay.portal.kernel.concurrent.IncreasableEntry;
18  import com.liferay.portal.kernel.increment.Increment;
19  
20  import org.aopalliance.intercept.MethodInterceptor;
21  import org.aopalliance.intercept.MethodInvocation;
22  
23  /**
24   * <a href="BufferedIncreasableEntry.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Zsolt Berentey
27   */
28  public class BufferedIncreasableEntry<K, T>
29      extends IncreasableEntry<K, Increment<T>> {
30  
31      public BufferedIncreasableEntry(
32          MethodInterceptor nextInterceptor, MethodInvocation methodInvocation,
33          K key, Increment<T> value) {
34  
35          super(key, value);
36  
37          _methodInvocation = methodInvocation;
38          _nextInterceptor = nextInterceptor;
39      }
40  
41      public Increment<T> doIncrease(
42          Increment<T> originalValue, Increment<T> deltaValue) {
43  
44          return originalValue.increaseForNew(deltaValue.getValue());
45      }
46  
47      public void proceed() throws Throwable {
48          Object[] arguments = _methodInvocation.getArguments();
49  
50          arguments[arguments.length - 1] = getValue().getValue();
51  
52          _nextInterceptor.invoke(_methodInvocation);
53      }
54  
55      public String toString() {
56          return _methodInvocation.toString();
57      }
58  
59      private MethodInvocation _methodInvocation;
60      private MethodInterceptor _nextInterceptor;
61  
62  }