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  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.apache.myfaces.tobago.util.FacesVersion;
23  
24  import javax.enterprise.context.ApplicationScoped;
25  import javax.inject.Named;
26  
27  @Named
28  @ApplicationScoped
29  public class Version {
30  
31    private static final boolean CDI10 = hasClass("javax.enterprise.context.Conversation");
32    private static final boolean CDI1112 = hasClass("javax.enterprise.context.Destroyed");
33    private static final boolean CDI20 = hasClass("javax.enterprise.context.BeforeDestroyed");
34  
35    private static boolean hasClass(String clazz) {
36      try {
37        Class.forName(clazz);
38        return true;
39      } catch (ClassNotFoundException e) {
40        return false;
41      }
42    }
43  
44    public boolean isVersion20() {
45      return FacesVersion.supports20() && !FacesVersion.supports21();
46    }
47  
48    public boolean isVersion21() {
49      return FacesVersion.supports21() && !FacesVersion.supports22();
50    }
51  
52    public boolean isVersion22() {
53      return FacesVersion.supports22() && !FacesVersion.supports23();
54    }
55  
56    public boolean isVersion23() {
57      return FacesVersion.supports23();
58    }
59  
60    public boolean isMojarra() {
61      return FacesVersion.isMojarra();
62    }
63  
64    public boolean isMyfaces() {
65      return FacesVersion.isMyfaces();
66    }
67  
68    public boolean isCdiVersion10() {
69      return CDI10 && !CDI1112;
70    }
71  
72    public boolean isCdiVersion1112() {
73      return CDI1112 && !CDI20;
74    }
75  
76    public boolean isCdiVersion20() {
77      return CDI20;
78    }
79  }