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;
    20
    21  // Note that if this bean does NOT implement any interfaces, then CGLIB is used to
    22  // generate proxies for it. If it implements one or more interfaces, then the
    23  // java.util.proxy module is used to generate proxies for it instead, unless
    24  // CGLIB is explicitly forced to be used.
    25  //
    26  // Presumably Spring is assuming that the interface it implements is a
    27  // "business interface" that users of the bean are coded to.
    28  //
    29  // However the type of proxy has interesting side-effects: a CGLIB proxy can
    30  // itself be proxied by CGLIB. However a JDK proxy cannot; that generates a
    31  // <i>final</i> class which CGLIB simply cannot generate a subclass of.
    32  public class SimpleBean implements SimpleInterface, ConversationAware
    33  {
    34      private String data;
    35
    36      SimpleBean[] thisRefHolder;
    37      SimpleBean thisRef;
    38
    39      int conversationAwareCount = 0;
    40
    41      public SimpleBean()
    42      {
    43      }
    44
    45      public SimpleBean getThis()
    46      {
    47          thisRefHolder = new SimpleBean[1];
    48          thisRefHolder[0] = this;
    49          thisRef = this;
    50          return this;
    51      }
    52
    53      public SimpleBean getThisRef()
    54      {
    55          return thisRef;
    56      }
    57
    58      public SimpleBean[] getThisRefHolder()
    59      {
    60          return thisRefHolder;
    61      }
    62
    63      public String getData()
    64      {
    65          return data;
    66      }
    67
    68      public void setData(String data)
    69      {
    70          this.data = data;
    71      }
    72
    73      public void transactionalMethod()
    74      {
    75      }
    76
    77      public void setConversation(Conversation conversation)
    78      {
    79          ++conversationAwareCount;
    80      }
    81
    82      public int getConversationAwareCount()
    83      {
    84          return conversationAwareCount;
    85      }
    86
    87      public void doSomething()
    88      {
    89      }
    90
    91      public void callback(Runnable callback)
    92      {
    93          callback.run();
    94      }
    95
    96      public Object bindToCurrentConversation(Object target)
    97      {
    98          Conversation conv = Conversation.getCurrentInstance();
    99          Object oProxy = conv.bind(target);
    100         return oProxy;
    101     }
    102 }