1 19 20 package org.netbeans.mdrant; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileOutputStream ; 25 import java.io.FileReader ; 26 import java.io.IOException ; 27 import java.io.StringWriter ; 28 29 import javax.jmi.reflect.*; 30 31 import org.apache.tools.ant.BuildException; 32 33 import org.netbeans.api.mdr.*; 34 import org.netbeans.lib.jmi.mapping.FileStreamFactory; 35 import org.netbeans.lib.jmi.mapping.JMIMapperImpl; 36 37 41 public class MapJava extends MdrTask.Sub { 42 43 private File dir; 44 private File headerFile; 45 private String extent; 46 47 48 public MapJava() { 49 } 50 51 public void execute() throws Exception { 52 53 if ( dir == null ) { 54 throw new BuildException( "Destination directory has to be sppecified. Use the \"dir\" attribute" ); 55 } 56 57 if ( extent == null ) { 58 throw new BuildException( "Extent to map has to be sppecified. Use the \"extent\" attribute" ); 59 } 60 61 JMIStreamFactory streamFactory = new FileStreamFactory( dir ); 62 63 getMapper().generate( streamFactory, getRepository().getExtent( extent ) ); 64 65 } 66 67 69 public void setDir( File dir ) { 70 this.dir = dir; 71 } 72 73 public void setExtent( String extent ) { 74 this.extent = extent; 75 } 76 77 public void setHeaderFile(File headerFile) { 78 this.headerFile = headerFile; 79 } 80 81 83 protected JMIMapper getMapper() throws IOException { 84 JMIMapperImpl result = new JMIMapperImpl(); 85 if (headerFile != null) { 86 BufferedReader reader = new BufferedReader (new FileReader (headerFile)); 87 StringWriter header = new StringWriter (); 88 int ch; 89 while ((ch = reader.read()) != -1) { 90 header.write(ch); 91 } 92 reader.close(); 93 header.close(); 94 result.setHeader(header.toString()); 95 } 96 return result; 97 } 98 99 100 } 101 | Popular Tags |