KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > javah > JavahAdapterFactory


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.tools.ant.taskdefs.optional.javah;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.ProjectComponent;
22 import org.apache.tools.ant.util.ClasspathUtils;
23 import org.apache.tools.ant.util.JavaEnvUtils;
24
25 /**
26  * Creates the JavahAdapter based on the user choice and
27  * potentially the VM vendor.
28  *
29  * @since Ant 1.6.3
30  */

31 public class JavahAdapterFactory {
32
33     /**
34      * Determines the default choice of adapter based on the VM
35      * vendor.
36      *
37      * @return the default choice of adapter based on the VM
38      * vendor
39      */

40     public static String JavaDoc getDefault() {
41         if (JavaEnvUtils.isKaffe()) {
42             return Kaffeh.IMPLEMENTATION_NAME;
43         }
44         return SunJavah.IMPLEMENTATION_NAME;
45     }
46
47     /**
48      * Creates the JavahAdapter based on the user choice and
49      * potentially the VM vendor.
50      *
51      * @param choice the user choice (if any).
52      * @param log a ProjectComponent instance used to access Ant's
53      * logging system.
54      * @return The adapter to use.
55      * @throws BuildException if there is an error.
56      */

57     public static JavahAdapter getAdapter(String JavaDoc choice,
58                                           ProjectComponent log)
59         throws BuildException {
60         if ((JavaEnvUtils.isKaffe() && choice == null)
61             || Kaffeh.IMPLEMENTATION_NAME.equals(choice)) {
62             return new Kaffeh();
63         } else if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) {
64             return new SunJavah();
65         } else if (choice != null) {
66             return resolveClassName(choice);
67         }
68
69         // This default has been good enough until Ant 1.6.3, so stick
70
// with it
71
return new SunJavah();
72     }
73
74     /**
75      * Tries to resolve the given classname into a javah adapter.
76      * Throws a fit if it can't.
77      *
78      * @param className The fully qualified classname to be created.
79      * @throws BuildException This is the fit that is thrown if className
80      * isn't an instance of JavahAdapter.
81      */

82     private static JavahAdapter resolveClassName(String JavaDoc className)
83             throws BuildException {
84         return (JavahAdapter) ClasspathUtils.newInstance(className,
85                 JavahAdapterFactory.class.getClassLoader(), JavahAdapter.class);
86     }
87 }
88
Popular Tags