View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.binding.method;
17  
18  import java.lang.reflect.Method;
19  
20  import org.eclipse.jface.viewers.StructuredViewer;
21  import org.seasar.uruma.annotation.AsyncMethod;
22  import org.seasar.uruma.binding.method.impl.OmissionArgumentsFilter;
23  import org.seasar.uruma.binding.method.impl.StructuredSelectionArgumentsFilter;
24  import org.seasar.uruma.binding.method.impl.TypedEventArgumentsFilter;
25  import org.seasar.uruma.context.WidgetHandle;
26  import org.seasar.uruma.rcp.core.UrumaBundleState;
27  import org.seasar.uruma.rcp.core.UrumaBundleState.BundleState;
28  
29  /**
30   * {@link MethodBinding} を生成するためのファクトリクラスです。<br />
31   * 
32   * @author y-komori
33   */
34  public class MethodBindingFactory {
35      private MethodBindingFactory() {
36  
37      }
38  
39      /**
40       * {@link MethodBinding} を生成します。<br />
41       * 
42       * @param target
43       *            ターゲットオブジェクト
44       * @param method
45       *            ターゲットメソッド
46       * @param handle
47       *            呼び出し元となるウィジットを保持する {@link WidgetHandle} オブジェクト
48       * @param asyncMethod
49       *            非同期実行を行う場合はそのアノテーション
50       * @return {@link MethodBinding} オブジェクト
51       */
52      public static MethodBinding createMethodBinding(final Object target,
53              final Method method, final WidgetHandle handle,
54              final AsyncMethod asyncMethod) {
55          MethodBinding binding;
56          if (asyncMethod == null
57                  || UrumaBundleState.getInstance().getUrumaBundleState() == BundleState.NOT_AVAILABLE) {
58              binding = new MethodBinding(target, method, null);
59          } else {
60              binding = new AsyncMethodBinding(target, method, null);
61              ((AsyncMethodBinding) binding).setTaskNameProperty(asyncMethod
62                      .nameProperty());
63              ((AsyncMethodBinding) binding).setCancelable(asyncMethod
64                      .cancelable());
65          }
66  
67          Class<?> widgetClass = handle.getWidgetClass();
68          if (StructuredViewer.class.isAssignableFrom(widgetClass)) {
69              binding.addArgumentsFilter(new StructuredSelectionArgumentsFilter(
70                      method));
71          } else {
72              binding.addArgumentsFilter(new OmissionArgumentsFilter(method));
73              binding.addArgumentsFilter(new TypedEventArgumentsFilter(method));
74          }
75  
76          return binding;
77      }
78  }