1 19 package org.netbeans.lib.jmi.mapping; 20 21 import java.io.File ; 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import org.netbeans.api.mdr.JMIStreamFactory; 28 29 33 public class FileStreamFactory extends JMIStreamFactory { 34 private final File targetDir; 35 private final long modelLastModified; 36 37 45 public FileStreamFactory(File targetDir) { 46 this(targetDir, null); 47 } 48 49 65 public FileStreamFactory(File targetDir, java.util.Date modelLastModified) { 66 if (targetDir == null) 67 throw new IllegalArgumentException ("ERROR: targetDir is null"); 68 else if (!targetDir.exists()) 69 throw new IllegalArgumentException ("ERROR: targetDir does not exist"); 70 else if (!targetDir.isDirectory()) { 71 throw new IllegalArgumentException ("ERROR: targetDir has to be a directory"); 72 } 73 this.targetDir = targetDir; 74 this.modelLastModified = modelLastModified != null ? modelLastModified.getTime() : 0L; 75 } 76 77 public OutputStream createStream(List pkg, String className, String extension) throws IOException { 78 File current = targetDir; 79 for (Iterator it = pkg.iterator(); it.hasNext();) { 80 current = new File (current, (String ) it.next()); 81 if (!current.exists()) { 82 current.mkdir(); 83 } 84 } 85 return createStream(new File (current, className + "." + extension)); 86 } 87 88 95 protected OutputStream createStream(java.io.File file) throws IOException { 96 return modelLastModified == 0 || modelLastModified > file.lastModified() 97 ? new FileOutputStream (file) : null; 98 } 99 100 } 101 | Popular Tags |