Coverage Report - ca.uhn.hl7v2.conf.store.ProfileStoreFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ProfileStoreFactory
71%
10/14
100%
2/2
1.167
 
 1  
 package ca.uhn.hl7v2.conf.store;
 2  
 
 3  
 import ca.uhn.hl7v2.util.Home;
 4  
 
 5  
 /**
 6  
  * Provides access to a (configurable) ProfileStore.
 7  
  * 
 8  
  * @author Bryan Tripp
 9  
  */
 10  
 public class ProfileStoreFactory {
 11  
 
 12  
         /**
 13  
          * The default profile store directory
 14  
          */
 15  1
     public static final String DEFAULT_PROFILE_STORE_DIRECTORY = Home.getHomeDirectory().getAbsolutePath() + "/profiles";
 16  
     
 17  
         private static ProfileStore instance;
 18  1
     private static CodeStoreRegistry codeRegistry = new DefaultCodeStoreRegistry();
 19  
 
 20  
     /** Non instantiable */
 21  
     private ProfileStoreFactory() {
 22  0
             super();
 23  0
     }
 24  
     
 25  
     /**
 26  
      * Returns a single configurable instance of a ProfileStore. Configurable by calling setStore().
 27  
      * Defaults to FileProfileStore using the current <hapi.home>/profiles as a base directory Note:
 28  
      * not a singleton (by design) in that nothing prevents creation of profile stores by other
 29  
      * means.
 30  
      */
 31  
     public synchronized static ProfileStore getProfileStore() {
 32  470
         if (instance == null)
 33  1
             instance = new FileProfileStore(DEFAULT_PROFILE_STORE_DIRECTORY);
 34  
 
 35  470
         return instance;
 36  
     }
 37  
 
 38  
     /**
 39  
      * Sets the profile store that will be returned in subsequent calls to getProfileStore().
 40  
      * 
 41  
      * @deprecated use HapiContext to define the ProfileStore to be used
 42  
      */
 43  
     public synchronized static void setStore(ProfileStore store) {
 44  0
         instance = store;
 45  0
     }
 46  
 
 47  
     /**
 48  
      * Registers a code store for use with all profiles.
 49  
      * 
 50  
      * @deprecated use {@link CodeStoreRegistry#addCodeStore(CodeStore)}
 51  
      */
 52  
     public static void addCodeStore(CodeStore store) {
 53  1
         codeRegistry.addCodeStore(store);
 54  1
     }
 55  
 
 56  
     /**
 57  
      * Registers a code store for use with certain profiles. The profiles with which the code store
 58  
      * are used are determined by profileIdPattern, which is a regular expression that will be
 59  
      * matched against profile IDs. For example suppose there are three profiles in the profile
 60  
      * store, with the following IDs:
 61  
      * <ol>
 62  
      * <li>ADT:confsig-UHN-2.4-profile-AL-NE-Immediate</li>
 63  
      * <li>ADT:confsig-CIHI-2.4-profile-AL-NE-Immediate</li>
 64  
      * <li>ADT:confsig-CIHI-2.3-profile-AL-NE-Immediate</li>
 65  
      * </ol>
 66  
      * Then to use a code store with only the first profile, the profileIdPattern would be
 67  
      * "ADT:confsig-UHN-2.4-profile-AL-NE-Immediate". To use a code store with both of the 2.4
 68  
      * profiles, the pattern would be ".*2\\.4.*". To use a code store with all profiles, the
 69  
      * pattern would be '.*". Multiple stores can be registered for use with the same profile. If
 70  
      * this happens, the first one that returned true for knowsCodes(codeSystem) will used. Stores
 71  
      * are searched in the order they are added here.
 72  
      * 
 73  
      * @deprecated use {@link CodeStoreRegistry#addCodeStore(CodeStore, String)}
 74  
      */
 75  
     public static void addCodeStore(CodeStore store, String profileID) {
 76  8
         codeRegistry.addCodeStore(store, profileID);
 77  8
     }
 78  
 
 79  
     /**
 80  
      * Returns the first code store that knows the codes in the given code system (as per
 81  
      * CodeStore.knowsCodes) and is registered for the given profile. Code stores are checked in the
 82  
      * order in which they are added (with addCodeStore()).
 83  
      * 
 84  
      * @return null if none are found
 85  
      * 
 86  
      * @deprecated use {@link CodeStoreRegistry#getCodeStore(String, String)}
 87  
      */
 88  
     public static CodeStore getCodeStore(String profileID, String codeSystem) {
 89  4
         return codeRegistry.getCodeStore(profileID, codeSystem);
 90  
     }
 91  
 }