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.dynaForm.metadata.impl.ejb;
20  
21  public class ClassHelperFactory
22  {
23      private static final String[] HELPER_CLASSES = new String[] {
24          "org.apache.myfaces.orchestra.dynaForm.metadata.impl.ejb.AsmHelper",
25          "org.apache.myfaces.orchestra.dynaForm.metadata.impl.ejb.BcelHelper"
26      };
27  
28      private static final ClassHelper CLASS_HELPER = newClassHelper();
29      
30      private ClassHelperFactory()
31      {
32      }
33  
34      public static ClassHelper get()
35      {
36          return CLASS_HELPER;
37      }
38  
39      public static ClassHelper newClassHelper()
40      {
41          ClassLoader cl = ClassHelperFactory.class.getClassLoader();
42          for(String helperClassName: HELPER_CLASSES)
43          {
44              try
45              {
46                  Class<ClassHelper> c = (Class<ClassHelper>) Class.forName(helperClassName, true, cl);
47                  return c.newInstance();
48              }
49              catch (ClassNotFoundException e)
50              {
51                  // not there
52              }
53              catch(IllegalAccessException e)
54              {
55                  // not available
56              }
57              catch(InstantiationException e)
58              {
59                  // not available
60              }
61              catch(ExceptionInInitializerError e)
62              {
63                  // not available
64              }
65          }
66  
67          // last exit
68          return new JavaHelper();
69      }
70  }