View Javadoc

1   /*
2    * Copyright 2004-2007 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.cubby.customizer;
17  
18  import org.seasar.framework.aop.Pointcut;
19  import org.seasar.framework.container.customizer.AspectCustomizer;
20  import org.seasar.framework.util.StringUtil;
21  
22  /**
23   * {@link org.seasar.framework.container.ComponentDef コンポーネント定義}に
24   * {@link org.seasar.framework.container.AspectDef アスペクト定義}を
25   * 登録するコンポーネントカスタマイザです。
26   * <p>
27   * カスタマイザには、ポイントカットとインターセプタを設定します。 インターセプタはコンポーネント名で指定し、複数のインターセプタ名を設定することができます。
28   * インターセプタ名が複数設定された場合は、設定された順にアスペクト定義をコンポーネント定義に登録します。
29   * 最初に設定された名前を持つインターセプタが、後に設定された名前を持つインターセプタよりも先に呼び出されることになります。
30   * </p>
31   * <p>
32   * コンポーネントに適用するインターセプタのインスタンス属性が<code>singleton</code>以外の場合は、
33   * {@link #setUseLookupAdapter(boolean) useLookupAdapter}プロパティを<code>true</code>に設定します。
34   * これにより、コンポーネントのメソッドが呼び出される度に、コンテナからインターセプタのインスタンスをルックアップするようになります。
35   * </p>
36   * 
37   * @author baba
38   */
39  public class ActionMethodCustomizer extends AspectCustomizer {
40  
41      private String pointcut;
42  
43      /**
44       * コンポーネント定義に登録するアスペクト定義のポイントカットを設定します。
45       * 
46       * @param pointcut
47       *            ポイントカット
48       */
49      public void setPointcut(final String pointcut) {
50      	super.setPointcut(pointcut);
51          this.pointcut = pointcut;
52      }
53  
54      /**
55       * ポイントカットを作成して返します。
56       * <p>
57       * <code>pointcut</code>プロパティが指定されている場合は、その文字列からポイントカットを作成します。
58       * <code>targetInterface</code>プロパティが指定されている場合は、そのインターフェースからポイントカットを作成します。
59       * それ以外の場合は<code>null</code>を返します。
60       * </p>
61       * 
62       * @return ポイントカット
63       */
64      protected Pointcut createPointcut() {
65          if (!StringUtil.isEmpty(pointcut)) {
66              return PointcutFactory.createPointcut(pointcut);
67          }
68          if (targetInterface != null) {
69              return PointcutFactory.createPointcut(targetInterface);
70          }
71          return null;
72      }
73  
74  }