View Javadoc
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      public static final String DEFAULT_PROFILE_STORE_DIRECTORY = Home.getHomeDirectory().getAbsolutePath() + "/profiles";
16      
17  	private static ProfileStore instance;
18      private static final CodeStoreRegistry codeRegistry = new DefaultCodeStoreRegistry();
19  
20      /** Non instantiable */
21      private ProfileStoreFactory() {
22      	super();
23      }
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          if (instance == null)
33              instance = new FileProfileStore(DEFAULT_PROFILE_STORE_DIRECTORY);
34  
35          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          instance = store;
45      }
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          codeRegistry.addCodeStore(store);
54      }
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          codeRegistry.addCodeStore(store, profileID);
77      }
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          return codeRegistry.getCodeStore(profileID, codeSystem);
90      }
91  }