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