Coverage Report - ca.uhn.hl7v2.util.Home
 
Classes in this File Line Coverage Branch Coverage Complexity
Home
60%
9/15
75%
3/4
1.5
 
 1  
 package ca.uhn.hl7v2.util;
 2  
 
 3  
 import java.io.File;
 4  
 
 5  
 import org.slf4j.Logger;
 6  
 import org.slf4j.LoggerFactory;
 7  
 
 8  
 /**
 9  
  * Used to access the hapi.home system property.  Note that the property 
 10  
  * is only checked (at most) once per session.  
 11  
  * @author Bryan Tripp
 12  
  */
 13  
 public class Home {
 14  
     
 15  
     private static File home;
 16  5
     private static Logger log = LoggerFactory.getLogger(Home.class);
 17  
     
 18  
     /** Creates a new instance of Home */
 19  0
     public Home() {
 20  0
     }
 21  
     
 22  
     /**
 23  
      * Returns a File object corresponding to the directory specified in 
 24  
      * the system property hapi.home.  The property is only checked the 
 25  
      * first time this method is called, so changes will not take place 
 26  
      * until a new VM is started.  
 27  
      * This method is guaranteed to return a directory.  If hapi.home is 
 28  
      * not set, or is set to a non-directory path, the current working directory will 
 29  
      * be used.  
 30  
      */
 31  
     public static File getHomeDirectory() {
 32  5565
         if (home == null) 
 33  5
             setHomeDirectory();
 34  
         
 35  5565
         return home;
 36  
     }
 37  
     
 38  
     private synchronized static void setHomeDirectory() {
 39  5
         String dir = System.getProperty("hapi.home", ".");
 40  5
         home = new File(dir);
 41  
         
 42  5
         if (!home.isDirectory()) {
 43  0
             home = new File("."); 
 44  0
             log.warn("The system property hapi.home is not a valid directory: {}.  Using . instead", dir);
 45  
         }
 46  
          
 47  5
         log.info("hapi.home is set to " + home.getAbsolutePath());
 48  5
     }
 49  
     
 50  
     public static void main(String args[]) {
 51  0
         System.out.println("HOME: " + getHomeDirectory().getAbsolutePath());
 52  0
     }
 53  
         
 54  
 }