1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_FRAMEWORK_MODULE_CONTROLLER_HXX
29 #define SD_FRAMEWORK_MODULE_CONTROLLER_HXX
30 
31 #include "MutexOwner.hxx"
32 
33 #include <osl/mutex.hxx>
34 #include <com/sun/star/drawing/framework/XModuleController.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/frame/XController.hpp>
38 #include <cppuhelper/compbase2.hxx>
39 
40 #include <boost/scoped_ptr.hpp>
41 #include <set>
42 
43 namespace css = ::com::sun::star;
44 
45 namespace {
46 
47 typedef ::cppu::WeakComponentImplHelper2 <
48     css::drawing::framework::XModuleController,
49     css::lang::XInitialization
50     > ModuleControllerInterfaceBase;
51 
52 } // end of anonymous namespace.
53 
54 
55 
56 namespace sd { namespace framework {
57 
58 /** The ModuleController has to tasks:
59 
60     1. It reads the
61     org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
62     configuration data that maps from resource URLs to service names of
63     factories that can create resources for the URLs.  When the
64     configuration controller wants to create a resource for which it does
65     not have a factory, it asks the ModuleController to provide one.  The
66     ModuleController looks up the service name registered for the URL of the
67     resource and instantiates this service.  The service is expected to
68     register on its creation a factory for the resource in question.
69 
70     2. The ModuleController reads on its creation
71     org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
72     configuration data and instantiates all listed services.  These servces
73     can then register as listeners at the ConfigurationController or do
74     whatever they like.
75 */
76 class ModuleController
77     : private sd::MutexOwner,
78       public ModuleControllerInterfaceBase
79 {
80 public:
81     static css::uno::Reference<
82         css::drawing::framework::XModuleController>
83         CreateInstance (
84             const css::uno::Reference<css::uno::XComponentContext>&
85             rxContext);
86 
87     virtual void SAL_CALL disposing (void);
88 
89 
90     // XModuleController
91 
92     virtual void SAL_CALL requestResource(const ::rtl::OUString& rsResourceURL)
93         throw (css::uno::RuntimeException);
94 
95 
96     // XInitialization
97 
98     virtual void SAL_CALL initialize(
99         const css::uno::Sequence<css::uno::Any>& aArguments)
100         throw (css::uno::Exception, css::uno::RuntimeException);
101 
102 private:
103     css::uno::Reference<
104         css::frame::XController> mxController;
105 
106     class ResourceToFactoryMap;
107     ::boost::scoped_ptr<ResourceToFactoryMap> mpResourceToFactoryMap;
108     class LoadedFactoryContainer;
109     ::boost::scoped_ptr<LoadedFactoryContainer> mpLoadedFactories;
110 
111     ModuleController (
112         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
113         throw();
114     ModuleController (void); // Not implemented.
115     ModuleController (const ModuleController&); // Not implemented.
116 	virtual ~ModuleController (void) throw();
117 
118     /** Load a list of URL to service mappings from the
119         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
120         configuration entry.  The mappings are stored in the
121         mpResourceToFactoryMap member.
122     */
123     void LoadFactories (const css::uno::Reference<css::uno::XComponentContext>& rxContext);
124 
125     /** Called for every entry in the ResourceFactories configuration entry.
126     */
127     void ProcessFactory (const ::std::vector<css::uno::Any>& rValues);
128 
129     /** Instantiate all startup services that are found in the
130         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
131         configuration entry.  This method is called once when a new
132         ModuleController object is created.
133     */
134     void InstantiateStartupServices (void);
135 
136     /** Called for one entry in the StartupServices configuration list this
137         method instantiates the service described by the entry.  It does not
138         hold references to the new object so that the object will be
139         destroyed on function exit when it does not register itself
140         somewhere.  It typically will register as
141         XConfigurationChangeListener at the configuration controller.
142     */
143     void ProcessStartupService (const ::std::vector<css::uno::Any>& rValues);
144 };
145 
146 } } // end of namespace sd::framework
147 
148 #endif
149