View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.myfaces.config.annotation;
19  
20  import javax.annotation.PostConstruct;
21  import javax.annotation.PreDestroy;
22  
23  /**
24   * @author Leonardo Uribe
25   */
26  
27  public class AnnotatedManagedBean2 {
28  
29      private boolean postConstructCalled = false; // using a stub for a mock
30  
31      private boolean preDestroyCalled = false; // using a stob for a mock here
32  
33      boolean throwExcetion;
34  
35      private String managedProperty;
36  
37      public AnnotatedManagedBean2()
38      {
39      }
40  
41      public AnnotatedManagedBean2(boolean throwExcetion) {
42          this.throwExcetion = throwExcetion;
43      }
44  
45      @PostConstruct
46      public void postConstruct()  {
47          
48          if (managedProperty == null)
49          {
50              throw new RuntimeException("managedProperty must be initialized before call of postConstruct() method");
51          }
52          
53          postConstructCalled = true;
54  
55          if (throwExcetion) {
56              throw new RuntimeException();
57          }
58      }
59  
60      @PreDestroy
61      public void preDestroy() {
62          preDestroyCalled = true;
63  
64          if (throwExcetion) {
65              throw new RuntimeException();
66          }
67      }
68  
69      boolean isPostConstructCalled() {
70          return postConstructCalled;
71      }
72  
73      boolean isPreDestroyCalled() {
74          return preDestroyCalled;
75      }
76      
77      public String getManagedProperty() {
78          return managedProperty;
79      }
80  
81      public void setManagedProperty(String managedProperty) {
82          //Set throught injection
83          if (postConstructCalled)
84          {
85              throw new RuntimeException();
86          }
87              
88          this.managedProperty = managedProperty;
89      }
90  
91  }