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