1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 3b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * Copyright (C) 2001-2011, International Business Machines Corporation. * 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * All Rights Reserved. * 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef ICUSERV_H 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ICUSERV_H 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if UCONFIG_NO_SERVICE 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Allow the declaration of APIs with pointers to ICUService 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * even when service is removed from the build. 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ICUService; 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/locid.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/umisc.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "hash.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uvector.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "servnotf.h" 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ICUServiceTest; 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ICUServiceKey; 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ICUServiceFactory; 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass SimpleFactory; 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ServiceListener; 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ICUService; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass DNCache; 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************* 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceKey 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUServiceKeys are used to communicate with factories to 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * generate an instance of the service. ICUServiceKeys define how 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ids are canonicalized, provide both a current id and a current 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * descriptor to use in querying the cache and factories, and 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * determine the fallback strategy.</p> 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUServiceKeys provide both a currentDescriptor and a currentID. 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The descriptor contains an optional prefix, followed by '/' 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and the currentID. Factories that handle complex keys, 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for example number format factories that generate multiple 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * kinds of formatters for the same locale, use the descriptor 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to provide a fully unique identifier for the service object, 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * while using the currentID (in this case, the locale string), 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * as the visible IDs that can be localized.</p> 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation of ICUServiceKey has no fallbacks and 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * has no custom descriptors.</p> 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API ICUServiceKey : public UObject { 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru private: 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString _id; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected: 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar PREFIX_DELIMITER; 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Construct a key from an id.</p> 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID from which to construct the key. 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUServiceKey(const UnicodeString& id); 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Virtual destructor.</p> 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ~ICUServiceKey(); 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the original ID used to construct this key.</p> 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the ID used to construct this key. 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual const UnicodeString& getID() const; 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the canonical version of the original ID. This implementation 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * appends the original ID to result. Result is returned as a convenience.</p> 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the output parameter to which the id will be appended. 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& canonicalID(UnicodeString& result) const; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the (canonical) current ID. This implementation appends 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the canonical ID to result. Result is returned as a convenience.</p> 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the output parameter to which the current id will be appended. 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& currentID(UnicodeString& result) const; 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the current descriptor. This implementation appends 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the current descriptor to result. Result is returned as a convenience.</p> 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The current descriptor is used to fully 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * identify an instance of the service in the cache. A 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factory may handle all descriptors for an ID, or just a 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * particular descriptor. The factory can either parse the 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * descriptor or use custom API on the key in order to 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * instantiate the service.</p> 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the output parameter to which the current id will be appended. 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& currentDescriptor(UnicodeString& result) const; 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>If the key has a fallback, modify the key and return true, 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * otherwise return false. The current ID will change if there 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is a fallback. No currentIDs should be repeated, and fallback 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * must eventually return false. This implementation has no fallbacks 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and always returns false.</p> 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the ICUServiceKey changed to a valid fallback value. 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UBool fallback(); 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return TRUE if a key created from id matches, or would eventually 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * fallback to match, the canonical ID of this ICUServiceKey.</p> 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the id to test. 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if this ICUServiceKey's canonical ID is a fallback of id. 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UBool isFallbackOf(const UnicodeString& id) const; 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the prefix. This implementation leaves result unchanged. 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Result is returned as a convenience.</p> 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the output parameter to which the prefix will be appended. 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& prefix(UnicodeString& result) const; 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A utility to parse the prefix out of a descriptor string. Only 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the (undelimited) prefix, if any, remains in result. Result is returned as a 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * convenience.</p> 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result an input/output parameter that on entry is a descriptor, and 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * on exit is the prefix of that descriptor. 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UnicodeString& parsePrefix(UnicodeString& result); 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A utility to parse the suffix out of a descriptor string. Only 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the (undelimited) suffix, if any, remains in result. Result is returned as a 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * convenience.</p> 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result an input/output parameter that on entry is a descriptor, and 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * on exit is the suffix of that descriptor. 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UnicodeString& parseSuffix(UnicodeString& result); 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UClassID U_EXPORT2 getStaticClassID(); 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID() const; 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef SERVICE_DEBUG 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& debug(UnicodeString& result) const; 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& debugClass(UnicodeString& result) const; 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /******************************************************************* 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceFactory 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>An implementing ICUServiceFactory generates the service objects maintained by the 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * service. A factory generates a service object from a key, 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * updates id->factory mappings, and returns the display name for 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * a supported id.</p> 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API ICUServiceFactory : public UObject { 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 21483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius virtual ~ICUServiceFactory(); 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Create a service object from the key, if this factory 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * supports the key. Otherwise, return NULL.</p> 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>If the factory supports the key, then it can call 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the service's getKey(ICUServiceKey, String[], ICUServiceFactory) method 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * passing itself as the factory to get the object that 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the service would have created prior to the factory's 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * registration with the service. This can change the 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * key, so any information required from the key should 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * be extracted before making such a callback.</p> 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the service key. 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param service the service with which this factory is registered. 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service object, or NULL if the factory does not support the key. 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const = 0; 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Update result to reflect the IDs (not descriptors) that this 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factory publicly handles. Result contains mappings from ID to 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factory. On entry it will contain all (visible) mappings from 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * previously-registered factories.</p> 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This function, together with getDisplayName, are used to 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * support ICUService::getDisplayNames. The factory determines 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * which IDs (of those it supports) it will make visible, and of 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * those, which it will provide localized display names for. In 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * most cases it will register mappings from all IDs it supports 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to itself.</p> 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the mapping table to update. 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const = 0; 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return, in result, the display name of the id in the provided locale. 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This is an id, not a descriptor. If the id is 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * not visible, sets result to bogus. If the 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * incoming result is bogus, it remains bogus. Result is returned as a 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * convenience. Results are not defined if id is not one supported by this 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factory.</p> 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id a visible id supported by this factory. 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale the locale for which to generate the corresponding localized display name. 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result output parameter to hold the display name. 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return result. 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const = 0; 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ****************************************************************** 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A default implementation of factory. This provides default 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * implementations for subclasses, and implements a singleton 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factory that matches a single ID and returns a single 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (possibly deferred-initialized) instance. This implements 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * updateVisibleIDs to add a mapping from its ID to itself 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * if visible is true, or to remove any existing mapping 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for its ID if visible is false. No localization of display 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * names is performed.</p> 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API SimpleFactory : public ICUServiceFactory { 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected: 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* _instance; 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString _id; 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UBool _visible; 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Construct a SimpleFactory that maps a single ID to a single 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * service instance. If visible is TRUE, the ID will be visible. 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The instance must not be NULL. The SimpleFactory will adopt 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the instance, which must not be changed subsequent to this call.</p> 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param instanceToAdopt the service instance to adopt. 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID to assign to this service instance. 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param visible if TRUE, the ID will be visible. 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible = TRUE); 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Destructor.</p> 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ~SimpleFactory(); 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This implementation returns a clone of the service instance if the factory's ID is equal to 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the key's currentID. Service and prefix are ignored.</p> 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the service key. 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param service the service with which this factory is registered. 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service object, or NULL if the factory does not support the key. 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const; 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This implementation adds a mapping from ID -> this to result if visible is TRUE, 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * otherwise it removes ID from result.</p> 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result the mapping table to update. 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const; 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This implementation returns the factory ID if it equals id and visible is TRUE, 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * otherwise it returns the empty string. (This implementation provides 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * no localized id information.)</p> 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id a visible id supported by this factory. 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale the locale for which to generate the corresponding localized display name. 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result output parameter to hold the display name. 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return result. 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const; 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UClassID U_EXPORT2 getStaticClassID(); 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID() const; 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef SERVICE_DEBUG 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& debug(UnicodeString& toAppendTo) const; 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UnicodeString& debugClass(UnicodeString& toAppendTo) const; 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ****************************************************************** 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ServiceListener is the listener that ICUService provides by default. 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService will notifiy this listener when factories are added to 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * or removed from the service. Subclasses can provide 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * different listener interfaces that extend EventListener, and modify 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * acceptsListener and notifyListener as appropriate.</p> 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API ServiceListener : public EventListener { 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 37183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius virtual ~ServiceListener(); 37283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This method is called when the service changes. At the time of the 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * call this listener is registered with the service. It must 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * not modify the notifier in the context of this call.</p> 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param service the service that changed. 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void serviceChanged(const ICUService& service) const = 0; 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UClassID U_EXPORT2 getStaticClassID(); 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UObject RTTI boilerplate. 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID() const; 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ****************************************************************** 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A StringPair holds a displayName/ID pair. ICUService uses it 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * as the array elements returned by getDisplayNames. 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API StringPair : public UMemory { 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The display name of the pair.</p> 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString displayName; 409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The ID of the pair.</p> 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString id; 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Creates a string pair from a displayName and an ID.</p> 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param displayName the displayName. 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID. 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a StringPair if the creation was successful, otherwise NULL. 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static StringPair* create(const UnicodeString& displayName, 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString& id, 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode& status); 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return TRUE if either string of the pair is bogus.</p> 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if either string of the pair is bogus. 430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool isBogus() const; 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru StringPair(const UnicodeString& displayName, const UnicodeString& id); 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************* 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A Service provides access to service objects that implement a 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * particular service, e.g. transliterators. Users provide a String 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * id (for example, a locale string) to the service, and get back an 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * object for that id. Service objects can be any kind of object. A 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * new service object is returned for each query. The caller is 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * responsible for deleting it.</p> 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Services 'canonicalize' the query ID and use the canonical ID to 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * query for the service. The service also defines a mechanism to 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 'fallback' the ID multiple times. Clients can optionally request 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the actual ID that was matched by a query when they use an ID to 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * retrieve a service object.</p> 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Service objects are instantiated by ICUServiceFactory objects 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * registered with the service. The service queries each 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceFactory in turn, from most recently registered to 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * earliest registered, until one returns a service object. If none 459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * responds with a service object, a fallback ID is generated, and the 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * process repeats until a service object is returned or until the ID 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * has no further fallbacks.</p> 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>In ICU 2.4, UObject (the base class of service instances) does 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * not define a polymorphic clone function. ICUService uses clones to 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * manage ownership. Thus, for now, ICUService defines an abstract 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * method, cloneInstance, that clients must implement to create clones 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * of the service instances. This may change in future releases of 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU.</p> 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUServiceFactories can be dynamically registered and 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * unregistered with the service. When registered, an 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceFactory is installed at the head of the factory list, and 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * so gets 'first crack' at any keys or fallback keys. When 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * unregistered, it is removed from the service and can no longer be 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * located through it. Service objects generated by this factory and 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * held by the client are unaffected.</p> 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>If a service has variants (e.g., the different variants of 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * BreakIterator) an ICUServiceFactory can use the prefix of the 480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceKey to determine the variant of a service to generate. 481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If it does not support all variants, it can request 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * previously-registered factories to handle the ones it does not 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * support.</p> 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUService uses ICUServiceKeys to query factories and perform 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * fallback. The ICUServiceKey defines the canonical form of the ID, 487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and implements the fallback strategy. Custom ICUServiceKeys can be 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * defined that parse complex IDs into components that 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceFactories can more easily use. The ICUServiceKey can 490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * cache the results of this parsing to save repeated effort. 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService provides convenience APIs that take UnicodeStrings and 492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * generate default ICUServiceKeys for use in querying.</p> 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUService provides API to get the list of IDs publicly 495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * supported by the service (although queries aren't restricted to 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * this list). This list contains only 'simple' IDs, and not fully 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * unique IDs. ICUServiceFactories are associated with each simple ID 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and the responsible factory can also return a human-readable 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * localized version of the simple ID, for use in user interfaces. 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService can also provide an array of the all the localized 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * visible IDs and their corresponding internal IDs.</p> 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>ICUService implements ICUNotifier, so that clients can register 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to receive notification when factories are added or removed from 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the service. ICUService provides a default EventListener 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * subinterface, ServiceListener, which can be registered with the 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * service. When the service changes, the ServiceListener's 508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * serviceChanged method is called with the service as the 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * argument.</p> 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The ICUService API is both rich and generic, and it is expected 512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that most implementations will statically 'wrap' ICUService to 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * present a more appropriate API-- for example, to declare the type 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * of the objects returned from get, to limit the factories that can 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * be registered with the service, or to define their own listener 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * interface with a custom callback method. They might also customize 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService by overriding it, for example, to customize the 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceKey and fallback strategy. ICULocaleService is a 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * subclass of ICUService that uses Locale names as IDs and uses 520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUServiceKeys that implement the standard resource bundle fallback 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * strategy. Most clients will wish to subclass it instead of 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICUService.</p> 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API ICUService : public ICUNotifier { 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected: 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Name useful for debugging. 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString name; 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru private: 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Timestamp so iterators can be fail-fast. 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t timestamp; 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * All the factories registered with this service. 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector* factories; 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The service cache. 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Hashtable* serviceCache; 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The ID cache. 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Hashtable* idCache; 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The name cache. 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DNCache* dnCache; 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Constructor. 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Construct a new ICUService.</p> 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUService(); 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Construct with a name (useful for debugging).</p> 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param name a name to use in debugging. 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUService(const UnicodeString& name); 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Destructor.</p> 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ~ICUService(); 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the name of this service. This will be the empty string if none was assigned. 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Returns result as a convenience.</p> 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result an output parameter to contain the name of this service. 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the name of this service. 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString& getName(UnicodeString& result) const; 587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override for get(ICUServiceKey&, UnicodeString*). This uses 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * createKey to create a key for the provided descriptor.</p> 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param descriptor the descriptor. 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* get(const UnicodeString& descriptor, UErrorCode& status) const; 597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override for get(ICUServiceKey&, UnicodeString*). This uses 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * createKey to create a key from the provided descriptor.</p> 601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param descriptor the descriptor. 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL. 604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* get(const UnicodeString& descriptor, UnicodeString* actualReturn, UErrorCode& status) const; 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override for get(ICUServiceKey&, UnicodeString*).</p> 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the key. 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* getKey(ICUServiceKey& key, UErrorCode& status) const; 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Given a key, return a service object, and, if actualReturn 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is not NULL, the descriptor with which it was found in the 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * first element of actualReturn. If no service object matches 622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * this key, returns NULL and leaves actualReturn unchanged.</p> 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This queries the cache using the key's descriptor, and if no 625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * object in the cache matches, tries the key on each 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * registered factory, in order. If none generates a service 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * object for the key, repeats the process with each fallback of 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the key, until either a factory returns a service object, or the key 629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * has no fallback. If no object is found, the result of handleDefault 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is returned.</p> 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Subclasses can override this method to further customize the 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * result before returning it. 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the key. 636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL. 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const; 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This version of getKey is only called by ICUServiceFactories within the scope 644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * of a previous getKey call, to determine what previously-registered factories would 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * have returned. For details, see getKey(ICUServiceKey&, UErrorCode&). Subclasses 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * should not call it directly, but call through one of the other get functions.</p> 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the key. 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL. 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param factory the factory making the recursive call. 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUServiceFactory* factory, UErrorCode& status) const; 655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override for getVisibleIDs(String) that passes null 658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * as the fallback, thus returning all visible IDs.</p> 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result a vector to hold the returned IDs. 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the result vector. 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector& getVisibleIDs(UVector& result, UErrorCode& status) const; 665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return a snapshot of the visible IDs for this service. This 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * list will not change as ICUServiceFactories are added or removed, but the 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * supported IDs will, so there is no guarantee that all and only 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the IDs in the returned list will be visible and supported by the 671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * service in subsequent calls.</p> 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The IDs are returned as pointers to UnicodeStrings. The 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * caller owns the IDs. Previous contents of result are discarded before 675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * new elements, if any, are added.</p> 676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>matchID is passed to createKey to create a key. If the key 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is not NULL, its isFallbackOf method is used to filter out IDs 679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that don't match the key or have it as a fallback.</p> 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result a vector to hold the returned IDs. 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param matchID an ID used to filter the result, or NULL if all IDs are desired. 683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the result vector. 685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector& getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorCode& status) const; 687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override for getDisplayName(const UnicodeString&, const Locale&, UnicodeString&) that 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * uses the current default locale.</p> 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID for which to retrieve the localized displayName. 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result an output parameter to hold the display name. 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result) const; 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Given a visible ID, return the display name in the requested locale. 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If there is no directly supported ID corresponding to this ID, result is 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * set to bogus.</p> 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID for which to retrieve the localized displayName. 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result an output parameter to hold the display name. 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale the locale in which to localize the ID. 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result. 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result, const Locale& locale) const; 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * uses the current default Locale as the locale and NULL for 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the matchID.</p> 714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result a vector to hold the returned displayName/id StringPairs. 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result vector. 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector& getDisplayNames(UVector& result, UErrorCode& status) const; 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that 723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * uses NULL for the matchID.</p> 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result a vector to hold the returned displayName/id StringPairs. 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale the locale in which to localize the ID. 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the modified result vector. 729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector& getDisplayNames(UVector& result, const Locale& locale, UErrorCode& status) const; 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return a snapshot of the mapping from display names to visible 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * IDs for this service. This set will not change as factories 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * are added or removed, but the supported IDs will, so there is 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * no guarantee that all and only the IDs in the returned map will 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * be visible and supported by the service in subsequent calls, 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * nor is there any guarantee that the current display names match 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * those in the result.</p> 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The names are returned as pointers to StringPairs, which 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * contain both the displayName and the corresponding ID. The 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * caller owns the StringPairs. Previous contents of result are 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * discarded before new elements, if any, are added.</p> 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>matchID is passed to createKey to create a key. If the key 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is not NULL, its isFallbackOf method is used to filter out IDs 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that don't match the key or have it as a fallback.</p> 749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param result a vector to hold the returned displayName/id StringPairs. 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale the locale in which to localize the ID. 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param matchID an ID used to filter the result, or NULL if all IDs are desired. 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the result vector. */ 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector& getDisplayNames(UVector& result, 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Locale& locale, 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString* matchID, 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode& status) const; 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>A convenience override of registerInstance(UObject*, const UnicodeString&, UBool) 762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that defaults visible to TRUE.</p> 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param objToAdopt the object to register and adopt. 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID to assign to this object. 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a registry key that can be passed to unregister to unregister 768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (and discard) this instance. 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UErrorCode& status); 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Register a service instance with the provided ID. The ID will be 774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * canonicalized. The canonicalized ID will be returned by 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * getVisibleIDs if visible is TRUE. The service instance will be adopted and 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * must not be modified subsequent to this call.</p> 777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This issues a serviceChanged notification to registered listeners.</p> 779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This implementation wraps the object using 781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * createSimpleFactory, and calls registerFactory.</p> 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param objToAdopt the object to register and adopt. 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID to assign to this object. 785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param visible TRUE if getVisibleIDs is to return this ID. 786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a registry key that can be passed to unregister() to unregister 788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (and discard) this instance. 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status); 791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Register an ICUServiceFactory. Returns a registry key that 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * can be used to unregister the factory. The factory 795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * must not be modified subsequent to this call. The service owns 796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * all registered factories. In case of an error, the factory is 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * deleted.</p> 798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This issues a serviceChanged notification to registered listeners.</p> 800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation accepts all factories.</p> 802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param factoryToAdopt the factory to register and adopt. 804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a registry key that can be passed to unregister to unregister 806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (and discard) this factory. 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual URegistryKey registerFactory(ICUServiceFactory* factoryToAdopt, UErrorCode& status); 809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Unregister a factory using a registry key returned by 812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * registerInstance or registerFactory. After a successful call, 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the factory will be removed from the service factory list and 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * deleted, and the key becomes invalid.</p> 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This issues a serviceChanged notification to registered 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * listeners.</p> 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param rkey the registry key. 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the call successfully unregistered the factory. 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UBool unregister(URegistryKey rkey, UErrorCode& status); 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * </p>Reset the service to the default factories. The factory 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * lock is acquired and then reInitializeFactories is called.</p> 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This issues a serviceChanged notification to registered listeners.</p> 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void reset(void); 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return TRUE if the service is in its default state.</p> 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation returns TRUE if there are no 837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * factories registered.</p> 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UBool isDefault(void) const; 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Create a key from an ID. If ID is NULL, returns NULL.</p> 843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation creates an ICUServiceKey instance. 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Subclasses can override to define more useful keys appropriate 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to the factories they accept.</p> 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param a pointer to the ID for which to create a default ICUServiceKey. 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the ICUServiceKey corresponding to ID, or NULL. 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ICUServiceKey* createKey(const UnicodeString* id, UErrorCode& status) const; 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Clone object so that caller can own the copy. In ICU2.4, UObject doesn't define 856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * clone, so we need an instance-aware method that knows how to do this. 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This is public so factories can call it, but should really be protected.</p> 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param instance the service instance to clone. 860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a clone of the passed-in instance, or NULL if cloning was unsuccessful. 861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UObject* cloneInstance(UObject* instance) const = 0; 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /************************************************************************ 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Subclassing API 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected: 870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Create a factory that wraps a single service object. Called by registerInstance.</p> 873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation returns an instance of SimpleFactory.</p> 875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param instanceToAdopt the service instance to adopt. 877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID to assign to this service instance. 878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param visible if TRUE, the ID will be visible. 879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return an instance of ICUServiceFactory that maps this instance to the provided ID. 881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ICUServiceFactory* createSimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status); 883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Reinitialize the factory list to its default state. After this call, isDefault() 886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * must return TRUE.</p> 887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This issues a serviceChanged notification to registered listeners.</p> 889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation clears the factory list. 891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Subclasses can override to provide other default initialization 892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * of the factory list. Subclasses must not call this method 893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * directly, since it must only be called while holding write 894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * access to the factory list.</p> 895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void reInitializeFactories(void); 897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Default handler for this service if no factory in the factory list 900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * handled the key passed to getKey.</p> 901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation returns NULL.</p> 903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param key the key. 905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL. 906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the service instance, or NULL. 908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const; 910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Clear caches maintained by this service.</p> 913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Subclasses can override if they implement additional caches 915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that need to be cleared when the service changes. Subclasses 916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * should generally not call this method directly, as it must only 917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * be called while synchronized on the factory lock.</p> 918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void clearCaches(void); 920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return true if the listener is accepted.</p> 923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation accepts the listener if it is 925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * a ServiceListener. Subclasses can override this to accept 926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * different listeners.</p> 927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param l the listener to test. 929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the service accepts the listener. 930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UBool acceptsListener(const EventListener& l) const; 932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Notify the listener of a service change.</p> 935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>The default implementation assumes a ServiceListener. 937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If acceptsListener has been overridden to accept different 938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * listeners, this should be overridden as well.</p> 939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param l the listener to notify. 941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void notifyListener(EventListener& l) const; 943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /************************************************************************ 945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Utilities for subclasses. 946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Clear only the service cache.</p> 950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This can be called by subclasses when a change affects the service 952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * cache but not the ID caches, e.g., when the default locale changes 953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the resolution of IDs also changes, requiring the cache to be 954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * flushed, but not the visible IDs themselves.</p> 955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void clearServiceCache(void); 957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return a map from visible IDs to factories. 960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This must only be called when the mutex is held.</p> 961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code status. 963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return a Hashtable containing mappings from visible 964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * IDs to factories. 965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Hashtable* getVisibleIDMap(UErrorCode& status) const; 967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Allow subclasses to read the time stamp.</p> 970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the timestamp. 972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t getTimestamp(void) const; 974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Return the number of registered factories.</p> 977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the number of factories registered at the time of the call. 979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t countFactories(void) const; 981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru friend class ::ICUServiceTest; // give tests access to countFactories. 985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* UCONFIG_NO_SERVICE */ 990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* ICUSERV_H */ 993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 995