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  package org.apache.myfaces.orchestra.conversation.spring;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
24  import org.springframework.beans.factory.BeanFactory;
25  import org.springframework.beans.factory.ObjectFactory;
26  
27  /**
28   * Used with a "scoping proxy" object as generated by _SpringUtils.newProxy.
29   * <p>
30   * When user code invokes any method on the proxy, it invokes getTarget on its
31   * source object to get the "real" object, then invokes the same method on the
32   * returned object. 
33   * <p>
34   * Here the getTarget method is implemented by using an AbstractSpringOrchestraScope
35   * object to look up the ConversationContext for the user, then a particular
36   * Conversation instance (by name), then a bean within that Conversation.
37   * <p>
38   * TODO: deal with serialization issues here. When an http session containing
39   * conversation-scoped beans is serialized, instances of this type will of course
40   * be serialized too. But the "scope" and "objectFactory" members here are not
41   * serializable. Somehow instances of this class need enough information to
42   * relocate the appropriate objects on deserialization.
43   * 
44   * @since 1.1
45   */
46  public class ScopedBeanTargetSource extends AbstractBeanFactoryBasedTargetSource {
47      private AbstractSpringOrchestraScope scope;
48      private String conversationName;
49      private String targetBeanName;
50      private ObjectFactory objectFactory;
51  
52      public ScopedBeanTargetSource(
53              AbstractSpringOrchestraScope scope, 
54              String conversationName,
55              String targetBeanName,
56              ObjectFactory objectFactory,
57              BeanFactory beanFactory) {
58  
59          this.scope = scope;
60          this.conversationName = conversationName;
61          this.targetBeanName = targetBeanName;
62          this.objectFactory = objectFactory;
63          
64          super.setTargetBeanName(targetBeanName);
65          super.setBeanFactory(beanFactory);
66      }
67  
68      public Object getTarget() throws Exception {
69          final Log log = LogFactory.getLog(ScopedBeanTargetSource.class);
70          log.debug("getRealBean for " + targetBeanName);
71          return scope.getRealBean(conversationName, targetBeanName, objectFactory);
72      }
73  }