KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > native2ascii > Native2AsciiAdapterFactory


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.native2ascii;
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 Native2AsciiAdapter based on the user choice and
27  * potentially the VM vendor.
28  *
29  * @since Ant 1.6.3
30  */

31 public class Native2AsciiAdapterFactory {
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 KaffeNative2Ascii.IMPLEMENTATION_NAME;
43         }
44         return SunNative2Ascii.IMPLEMENTATION_NAME;
45     }
46
47     /**
48      * Creates the Native2AsciiAdapter 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 was a problem.
56      */

57     public static Native2AsciiAdapter getAdapter(String JavaDoc choice,
58                                                  ProjectComponent log)
59         throws BuildException {
60         if ((JavaEnvUtils.isKaffe() && choice == null)
61             || KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
62             return new KaffeNative2Ascii();
63         } else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
64             return new SunNative2Ascii();
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 SunNative2Ascii();
72     }
73
74     /**
75      * Tries to resolve the given classname into a native2ascii 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 Native2AsciiAdapter.
81      */

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