1 18 package org.apache.tools.ant.taskdefs.optional.native2ascii; 19 20 import java.lang.reflect.Method ; 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 31 public final class SunNative2Ascii extends DefaultNative2Ascii { 32 33 36 public static final String IMPLEMENTATION_NAME = "sun"; 37 38 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 48 protected boolean run(Commandline cmd, ProjectComponent log) 49 throws BuildException { 50 try { 51 Class n2aMain = Class.forName("sun.tools.native2ascii.Main"); 52 Class [] param = new Class [] {String [].class}; 53 Method 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 o = n2aMain.newInstance(); 59 return ((Boolean ) convert.invoke(o, 60 new Object [] {cmd.getArguments()}) 61 ).booleanValue(); 62 } catch (BuildException ex) { 63 throw ex; 65 } catch (Exception ex) { 66 throw new BuildException("Error starting Sun's native2ascii: ", ex); 68 } 69 } 70 } 71 | Popular Tags |