KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Method JavaDoc;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.ProjectComponent;
23 import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
24 import org.apache.tools.ant.types.Commandline;
25
26 /**
27  * Adapter to sun.tools.native2ascii.Main.
28  *
29  * @since Ant 1.6.3
30  */

31 public final class SunNative2Ascii extends DefaultNative2Ascii {
32
33     /**
34      * Identifies this adapter.
35      */

36     public static final String JavaDoc IMPLEMENTATION_NAME = "sun";
37
38     /** {@inheritDoc} */
39     protected void setup(Commandline cmd, Native2Ascii args)
40         throws BuildException {
41         if (args.getReverse()) {
42             cmd.createArgument().setValue("-reverse");
43         }
44         super.setup(cmd, args);
45     }
46
47     /** {@inheritDoc} */
48     protected boolean run(Commandline cmd, ProjectComponent log)
49         throws BuildException {
50         try {
51             Class JavaDoc n2aMain = Class.forName("sun.tools.native2ascii.Main");
52             Class JavaDoc[] param = new Class JavaDoc[] {String JavaDoc[].class};
53             Method JavaDoc convert = n2aMain.getMethod("convert", param);
54             if (convert == null) {
55                 throw new BuildException("Could not find convert() method in "
56                                          + "sun.tools.native2ascii.Main");
57             }
58             Object JavaDoc o = n2aMain.newInstance();
59             return ((Boolean JavaDoc) convert.invoke(o,
60                                              new Object JavaDoc[] {cmd.getArguments()})
61                     ).booleanValue();
62         } catch (BuildException ex) {
63             //rethrow
64
throw ex;
65         } catch (Exception JavaDoc ex) {
66             //wrap
67
throw new BuildException("Error starting Sun's native2ascii: ", ex);
68         }
69     }
70 }
71
Popular Tags