View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.orchestra.conversation.spring;
21  
22  import java.io.Serializable;
23  
24  import org.aopalliance.aop.Advice;
25  import org.springframework.aop.Pointcut;
26  import org.springframework.aop.PointcutAdvisor;
27  
28  /**
29   * Define a trivial Advisor object that always applies to the class passed to it.
30   * <p>
31   * Spring requires Advisor objects to be returned rather than Advices. Advisors can implement various interfaces to
32   * control which classes or methods they get applied to, but here the OrchestraAdvisorBeanPostProcessor only returns an
33   * instance of this for classes that it really *should* apply to, and the advices always apply to all methods, so there
34   * is really nothing for this Advisor to do.
35   * <p>
36   * TODO: maybe it would be nice to allow an orchestra scope object to hold Advisors as well as just Advices, so that
37   * users can configure specific code to run only for specific methods of orchestra beans.
38   * <p>
39   * NB: In Spring2.5, this class can simply implement Advisor, and it will be applied to all methods. However in
40   * Spring2.0, class DefaultAdvisorChainFactory only accepts PointcutAdvisor or IntroductionAdvisor, and silently ignores
41   * Advisor classes that are not of those types. So here for Spring2.x compatibility we need to make this class a
42   * PointcutAdvisor with a dummy pointcut that matches all methods...
43   */
44  class SimpleAdvisor implements PointcutAdvisor, Serializable
45  {
46      private Advice advice;
47  
48      public SimpleAdvisor(Advice advice)
49      {
50          this.advice = advice;
51      }
52  
53      public Advice getAdvice()
54      {
55          return advice;
56      }
57  
58      public boolean isPerInstance()
59      {
60          return false;
61      }
62  
63      public Pointcut getPointcut()
64      {
65          return Pointcut.TRUE;
66      }
67  }