1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SD_FRAMEWORK_RESOURCE_FACTORY_MANAGER_HXX 25 #define SD_FRAMEWORK_RESOURCE_FACTORY_MANAGER_HXX 26 27 #include <com/sun/star/drawing/framework/XControllerManager.hpp> 28 #include <com/sun/star/drawing/framework/XModuleController.hpp> 29 #include <com/sun/star/drawing/framework/XResourceFactoryManager.hpp> 30 #include <com/sun/star/util/XURLTransformer.hpp> 31 #include <osl/mutex.hxx> 32 #include <comphelper/stl_types.hxx> 33 #include <hash_map> 34 35 namespace css = ::com::sun::star; 36 37 namespace sd { namespace framework { 38 39 /** Container of resource factories of the drawing framework. 40 */ 41 class ResourceFactoryManager 42 { 43 public: 44 ResourceFactoryManager ( 45 const css::uno::Reference<css::drawing::framework::XControllerManager>& rxManager); 46 47 ~ResourceFactoryManager (void); 48 49 /** Register a resource factory for one type of resource. 50 @param rsURL 51 The type of the resource that will be created by the factory. 52 @param rxFactory 53 The factory that will create resource objects of the specfied type. 54 */ 55 void AddFactory ( 56 const ::rtl::OUString& rsURL, 57 const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory) 58 throw (css::uno::RuntimeException); 59 60 /** Unregister the specifed factory. 61 @param rsURL 62 Unregister only the factory for this URL. When the same factory 63 is registered for other URLs then these remain registered. 64 */ 65 void RemoveFactoryForURL( 66 const ::rtl::OUString& rsURL) 67 throw (css::uno::RuntimeException); 68 69 /** Unregister the specified factory. 70 @param rxFactory 71 Unregister the this factory for all URLs that it has been 72 registered for. 73 */ 74 void RemoveFactoryForReference( 75 const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory) 76 throw (css::uno::RuntimeException); 77 78 /** Return a factory that can create resources specified by the given URL. 79 @param rsCompleteURL 80 This URL specifies the type of the resource. It may contain arguments. 81 @return 82 When a factory for the specified URL has been registered by a 83 previous call to AddFactory() then a reference to that factory 84 is returned. Otherwise an empty reference is returned. 85 */ 86 css::uno::Reference<css::drawing::framework::XResourceFactory> GetFactory ( 87 const ::rtl::OUString& rsURL) 88 throw (css::uno::RuntimeException); 89 90 private: 91 ::osl::Mutex maMutex; 92 typedef ::std::hash_map< 93 ::rtl::OUString, 94 css::uno::Reference<css::drawing::framework::XResourceFactory>, 95 ::comphelper::UStringHash, 96 ::comphelper::UStringEqual> FactoryMap; 97 FactoryMap maFactoryMap; 98 99 typedef ::std::vector< 100 ::std::pair< 101 rtl::OUString, 102 css::uno::Reference<css::drawing::framework::XResourceFactory> > > 103 FactoryPatternList; 104 FactoryPatternList maFactoryPatternList; 105 106 css::uno::Reference<css::drawing::framework::XControllerManager> mxControllerManager; 107 css::uno::Reference<css::util::XURLTransformer> mxURLTransformer; 108 109 /** Look up the factory for the given URL. 110 @param rsURLBase 111 The css::tools::URL.Main part of a URL. Arguments have to be 112 stripped off by the caller. 113 @return 114 When the factory has not yet been added then return NULL. 115 */ 116 css::uno::Reference<css::drawing::framework::XResourceFactory> FindFactory ( 117 const ::rtl::OUString& rsURLBase) 118 throw (css::uno::RuntimeException); 119 }; 120 121 122 } } // end of namespace sd::framework 123 124 #endif 125