KickJava   Java API By Example, From Geeks To Geeks.

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


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.taskdefs.ExecuteJava;
23 import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
24 import org.apache.tools.ant.types.Commandline;
25
26 /**
27  * Adapter to kaffe.tools.native2ascii.Native2Ascii.
28  *
29  * @since Ant 1.6.3
30  */

31 public final class KaffeNative2Ascii extends DefaultNative2Ascii {
32
33     // sorted by newest Kaffe version first
34
private static final String JavaDoc[] N2A_CLASSNAMES = new String JavaDoc[] {
35         "gnu.classpath.tools.native2ascii.Native2Ascii",
36         // pre Kaffe 1.1.5
37
"kaffe.tools.native2ascii.Native2Ascii",
38     };
39
40     /**
41      * Identifies this adapter.
42      */

43     public static final String JavaDoc IMPLEMENTATION_NAME = "kaffe";
44
45     /** {@inheritDoc} */
46     protected void setup(Commandline cmd, Native2Ascii args)
47         throws BuildException {
48         if (args.getReverse()) {
49             throw new BuildException("-reverse is not supported by Kaffe");
50         }
51         super.setup(cmd, args);
52     }
53
54     /** {@inheritDoc} */
55     protected boolean run(Commandline cmd, ProjectComponent log)
56         throws BuildException {
57         ExecuteJava ej = new ExecuteJava();
58         Class JavaDoc c = getN2aClass();
59         if (c == null) {
60             throw new BuildException("Couldn't load Kaffe's Native2Ascii"
61                                      + " class");
62         }
63
64         cmd.setExecutable(c.getName());
65         ej.setJavaCommand(cmd);
66         ej.execute(log.getProject());
67         // otherwise ExecuteJava has thrown an exception
68
return true;
69     }
70
71     /**
72      * tries to load Kaffe Native2Ascii and falls back to the older
73      * class name if necessary.
74      *
75      * @return null if neither class can get loaded.
76      */

77     private static Class JavaDoc getN2aClass() {
78         for (int i = 0; i < N2A_CLASSNAMES.length; i++) {
79             try {
80                 return Class.forName(N2A_CLASSNAMES[i]);
81             } catch (ClassNotFoundException JavaDoc cnfe) {
82                 // Ignore
83
}
84         }
85         return null;
86     }
87
88 }
89
Popular Tags