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  {
48      private AbstractSpringOrchestraScope scope;
49      private String conversationName;
50      private String targetBeanName;
51      private ObjectFactory objectFactory;
52  
53      public ScopedBeanTargetSource(
54              AbstractSpringOrchestraScope scope, 
55              String conversationName,
56              String targetBeanName,
57              ObjectFactory objectFactory,
58              BeanFactory beanFactory)
59      {
60          this.scope = scope;
61          this.conversationName = conversationName;
62          this.targetBeanName = targetBeanName;
63          this.objectFactory = objectFactory;
64          
65          super.setTargetBeanName(targetBeanName);
66          super.setBeanFactory(beanFactory);
67      }
68  
69      public Object getTarget() throws Exception
70      {
71          final Log log = LogFactory.getLog(ScopedBeanTargetSource.class);
72          if (log.isDebugEnabled())
73          {
74              log.debug("getRealBean for " + targetBeanName);
75          }
76          return scope.getRealBean(conversationName, targetBeanName, objectFactory);
77      }
78  }