001package ca.uhn.hl7v2.conf.store; 002 003import ca.uhn.hl7v2.util.Home; 004 005/** 006 * Provides access to a (configurable) ProfileStore. 007 * 008 * @author Bryan Tripp 009 */ 010public class ProfileStoreFactory { 011 012 /** 013 * The default profile store directory 014 */ 015 public static final String DEFAULT_PROFILE_STORE_DIRECTORY = Home.getHomeDirectory().getAbsolutePath() + "/profiles"; 016 017 private static ProfileStore instance; 018 private static CodeStoreRegistry codeRegistry = new DefaultCodeStoreRegistry(); 019 020 /** Non instantiable */ 021 private ProfileStoreFactory() { 022 super(); 023 } 024 025 /** 026 * Returns a single configurable instance of a ProfileStore. Configurable by calling setStore(). 027 * Defaults to FileProfileStore using the current <hapi.home>/profiles as a base directory Note: 028 * not a singleton (by design) in that nothing prevents creation of profile stores by other 029 * means. 030 */ 031 public synchronized static ProfileStore getProfileStore() { 032 if (instance == null) 033 instance = new FileProfileStore(DEFAULT_PROFILE_STORE_DIRECTORY); 034 035 return instance; 036 } 037 038 /** 039 * Sets the profile store that will be returned in subsequent calls to getProfileStore(). 040 * 041 * @deprecated use HapiContext to define the ProfileStore to be used 042 */ 043 public synchronized static void setStore(ProfileStore store) { 044 instance = store; 045 } 046 047 /** 048 * Registers a code store for use with all profiles. 049 * 050 * @deprecated use {@link CodeStoreRegistry#addCodeStore(CodeStore)} 051 */ 052 public static void addCodeStore(CodeStore store) { 053 codeRegistry.addCodeStore(store); 054 } 055 056 /** 057 * Registers a code store for use with certain profiles. The profiles with which the code store 058 * are used are determined by profileIdPattern, which is a regular expression that will be 059 * matched against profile IDs. For example suppose there are three profiles in the profile 060 * store, with the following IDs: 061 * <ol> 062 * <li>ADT:confsig-UHN-2.4-profile-AL-NE-Immediate</li> 063 * <li>ADT:confsig-CIHI-2.4-profile-AL-NE-Immediate</li> 064 * <li>ADT:confsig-CIHI-2.3-profile-AL-NE-Immediate</li> 065 * </ol> 066 * Then to use a code store with only the first profile, the profileIdPattern would be 067 * "ADT:confsig-UHN-2.4-profile-AL-NE-Immediate". To use a code store with both of the 2.4 068 * profiles, the pattern would be ".*2\\.4.*". To use a code store with all profiles, the 069 * pattern would be '.*". Multiple stores can be registered for use with the same profile. If 070 * this happens, the first one that returned true for knowsCodes(codeSystem) will used. Stores 071 * are searched in the order they are added here. 072 * 073 * @deprecated use {@link CodeStoreRegistry#addCodeStore(CodeStore, String)} 074 */ 075 public static void addCodeStore(CodeStore store, String profileID) { 076 codeRegistry.addCodeStore(store, profileID); 077 } 078 079 /** 080 * Returns the first code store that knows the codes in the given code system (as per 081 * CodeStore.knowsCodes) and is registered for the given profile. Code stores are checked in the 082 * order in which they are added (with addCodeStore()). 083 * 084 * @return null if none are found 085 * 086 * @deprecated use {@link CodeStoreRegistry#getCodeStore(String, String)} 087 */ 088 public static CodeStore getCodeStore(String profileID, String codeSystem) { 089 return codeRegistry.getCodeStore(profileID, codeSystem); 090 } 091}