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.shiro.config;
20  
21  import org.apache.shiro.config.event.BeanEvent;
22  import org.apache.shiro.config.event.ConfiguredBeanEvent;
23  import org.apache.shiro.config.event.DestroyedBeanEvent;
24  import org.apache.shiro.config.event.InitializedBeanEvent;
25  import org.apache.shiro.config.event.InstantiatedBeanEvent;
26  import org.apache.shiro.event.Subscribe;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /**
32   * @since 1.3
33   */
34  public class RecordingBeanListener {
35  
36      private List<InstantiatedBeanEvent> instantiateEvents = new ArrayList<InstantiatedBeanEvent>();
37      private List<ConfiguredBeanEvent> configuredEvents = new ArrayList<ConfiguredBeanEvent>();
38      private List<InitializedBeanEvent> initializedEvents = new ArrayList<InitializedBeanEvent>();
39      private List<DestroyedBeanEvent> destroyedEvents = new ArrayList<DestroyedBeanEvent>();
40      private List<BeanEvent> unhandledEvents = new ArrayList<BeanEvent>();
41  
42      @SuppressWarnings("UnusedDeclaration") //used via reflection
43      @Subscribe
44      public void onUnhandledBeanEvent(BeanEvent beanEvent) {
45          this.unhandledEvents.add(beanEvent);
46      }
47  
48      @SuppressWarnings("UnusedDeclaration") //used via reflection
49      @Subscribe
50      public void onInstantiatedBeanEvent(InstantiatedBeanEvent beanEvent) {
51          this.instantiateEvents.add(beanEvent);
52      }
53  
54      @SuppressWarnings("UnusedDeclaration") //used via reflection
55      @Subscribe
56      public void onConfiguredBeanEvent(ConfiguredBeanEvent beanEvent) {
57          this.configuredEvents.add(beanEvent);
58      }
59  
60      @SuppressWarnings("UnusedDeclaration") //used via reflection
61      @Subscribe
62      public void onInitializedBeanEvent(InitializedBeanEvent beanEvent) {
63          this.initializedEvents.add(beanEvent);
64      }
65  
66      @SuppressWarnings("UnusedDeclaration") //used via reflection
67      @Subscribe
68      public void onDestroyedBeanEvent(DestroyedBeanEvent beanEvent) {
69          this.destroyedEvents.add(beanEvent);
70      }
71  
72      public List<InstantiatedBeanEvent> getInstantiatedEvents() {
73          return instantiateEvents;
74      }
75  
76      public List<ConfiguredBeanEvent> getConfiguredEvents() {
77          return configuredEvents;
78      }
79  
80      public List<InitializedBeanEvent> getInitializedEvents() {
81          return initializedEvents;
82      }
83  
84      public List<DestroyedBeanEvent> getDestroyedEvents() {
85          return destroyedEvents;
86      }
87  
88      public List<BeanEvent> getUnhandledEvents() {
89          return unhandledEvents;
90      }
91  }