xref: /trunk/main/sd/source/ui/framework/configuration/ResourceFactoryManager.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 specified type.
54     */
55     void AddFactory (
56         const ::rtl::OUString& rsURL,
57         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory);
58 
59     /** Unregister the specified factory.
60         @param rsURL
61             Unregister only the factory for this URL.  When the same factory
62             is registered for other URLs then these remain registered.
63     */
64     void RemoveFactoryForURL(
65         const ::rtl::OUString& rsURL);
66 
67     /** Unregister the specified factory.
68         @param rxFactory
69             Unregister the this factory for all URLs that it has been
70             registered for.
71     */
72     void RemoveFactoryForReference(
73         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory);
74 
75     /** Return a factory that can create resources specified by the given URL.
76         @param rsCompleteURL
77             This URL specifies the type of the resource.  It may contain arguments.
78         @return
79             When a factory for the specified URL has been registered by a
80             previous call to AddFactory() then a reference to that factory
81             is returned.  Otherwise an empty reference is returned.
82     */
83     css::uno::Reference<css::drawing::framework::XResourceFactory> GetFactory (
84         const ::rtl::OUString& rsURL);
85 
86 private:
87     ::osl::Mutex maMutex;
88     typedef ::std::hash_map<
89         ::rtl::OUString,
90         css::uno::Reference<css::drawing::framework::XResourceFactory>,
91         ::comphelper::UStringHash,
92         ::comphelper::UStringEqual> FactoryMap;
93     FactoryMap maFactoryMap;
94 
95     typedef ::std::vector<
96         ::std::pair<
97             rtl::OUString,
98             css::uno::Reference<css::drawing::framework::XResourceFactory> > >
99         FactoryPatternList;
100     FactoryPatternList maFactoryPatternList;
101 
102     css::uno::Reference<css::drawing::framework::XControllerManager> mxControllerManager;
103     css::uno::Reference<css::util::XURLTransformer> mxURLTransformer;
104 
105     /** Look up the factory for the given URL.
106         @param rsURLBase
107             The css::tools::URL.Main part of a URL. Arguments have to be
108             stripped off by the caller.
109         @return
110             When the factory has not yet been added then return NULL.
111     */
112     css::uno::Reference<css::drawing::framework::XResourceFactory> FindFactory (
113         const ::rtl::OUString& rsURLBase);
114 };
115 
116 
117 } } // end of namespace sd::framework
118 
119 #endif
120