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.commons.resourcehandler.webapp.config.impl;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  /**
25   * <p>
26   * Package-private utility class for determining which specifications are available
27   * in the current process. 
28   * </p>
29   *
30   * @author Leonardo Uribe
31   */
32  final class _ExternalSpecifications
33  {
34  
35      private static final Log log = LogFactory.getLog(_ExternalSpecifications.class);
36  
37      private static volatile Boolean servlet30Available;
38  
39      /**
40       * This method determines if servlet 3.0 is present.
41       *
42       * @return true if servlet 3.0 is available, false otherwise.
43       */
44      public static boolean isServlet30Available()
45      {
46          if (servlet30Available == null)
47          {
48              try
49              {
50                  servlet30Available = (Class.forName("javax.servlet.ServletRegistration") != null);
51              }
52              catch(Throwable t)
53              {
54                  if (log.isTraceEnabled())
55                  {
56                      log.trace("Cannot load servlet 3.0 class (could be normal)", t);
57                  }
58                  servlet30Available = Boolean.FALSE;
59              }
60      
61              log.info("MyFaces commons ResourceHandler Servlet 3.0 container support " + (servlet30Available ? "enabled" : "disabled"));
62          }
63          return servlet30Available; 
64      }
65  
66      /**
67       * this class should not be instantiated.
68       */
69      private _ExternalSpecifications()
70      {
71      }
72  
73  }