1 17 package org.apache.geronimo.system.configuration; 18 19 import java.io.BufferedReader ; 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.OutputStream ; 27 import java.io.PrintWriter ; 28 import java.io.Writer ; 29 30 import org.apache.geronimo.kernel.config.ConfigurationData; 31 32 35 class InPlaceConfigurationUtil { 36 private static final String IN_PLACE_LOCATION_FILE = "inPlaceLocation.config"; 37 38 InPlaceConfigurationUtil() { 39 } 40 41 public boolean isInPlaceConfiguration(File source) { 42 File inPlaceLocation = getInPlaceLocation(source); 43 return inPlaceLocation.exists(); 44 } 45 46 public void writeInPlaceLocation(ConfigurationData configurationData, File source) throws IOException { 47 if (null == configurationData.getInPlaceConfigurationDir()) { 48 return; 49 } 50 51 File inPlaceLocation = getInPlaceLocation(source); 52 Writer writer = null; 53 try { 54 OutputStream os = new FileOutputStream (inPlaceLocation); 55 writer = new PrintWriter (os); 56 File inPlaceConfigurationDir = configurationData.getInPlaceConfigurationDir(); 57 String absolutePath = inPlaceConfigurationDir.getAbsolutePath(); 58 writer.write(absolutePath); 59 writer.close(); writer = null; 61 } finally { 62 if (null != writer) { 63 try { 64 writer.close(); 65 } catch (IOException ignored) { 66 } 68 } 69 } 70 } 71 72 public File readInPlaceLocation(File source) throws IOException { 73 File inPlaceLocation = getInPlaceLocation(source); 74 75 if (!inPlaceLocation.exists()) { 76 return null; 77 } 78 79 BufferedReader reader = null; 80 try { 81 InputStream is = new FileInputStream (inPlaceLocation); 82 reader = new BufferedReader (new InputStreamReader (is)); 83 String path = reader.readLine(); 84 return new File (path); 85 } finally { 86 if (null != reader) { 87 try { 88 reader.close(); 89 } catch (IOException e) { 90 } 91 } 92 } 93 } 94 95 private File getInPlaceLocation(File source) { 96 File inPlaceLocation = new File (source, "META-INF"); 97 inPlaceLocation.mkdirs(); 98 return new File (inPlaceLocation, IN_PLACE_LOCATION_FILE); 99 } 100 } 101 | Popular Tags |