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 __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
25 #define __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
26 
27 //_______________________________________________
28 // own includes
29 
30 #include <threadhelp/threadhelpbase.hxx>
31 #include <macros/xinterface.hxx>
32 #include <macros/xtypeprovider.hxx>
33 #include <macros/xserviceinfo.hxx>
34 #include <general.h>
35 #include <general.h>
36 #include <stdtypes.h>
37 
38 //_______________________________________________
39 // interface includes
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/lang/XTypeProvider.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/frame/XModuleManager.hpp>
45 #include <com/sun/star/container/XNameReplace.hpp>
46 #include <com/sun/star/container/XContainerQuery.hpp>
47 
48 //_______________________________________________
49 // other includes
50 #include <cppuhelper/weak.hxx>
51 
52 //_______________________________________________
53 // definition
54 
55 namespace framework
56 {
57 
58 //_______________________________________________
59 /**
60     implements the service com.sun.star.frame.ModuleManager
61  */
62 class ModuleManager : public  css::lang::XTypeProvider
63                     , public  css::lang::XServiceInfo
64                     , public  css::frame::XModuleManager
65                     , public  css::container::XNameReplace // => XNameAccess, XElementAccess
66                     , public  css::container::XContainerQuery
67                     // attention! Must be the first base class to guarentee right initialize lock ...
68                     , private ThreadHelpBase
69                     , public  ::cppu::OWeakObject
70 {
71     //___________________________________________
72     // member
73 
74     private:
75 
76         //---------------------------------------
77         /** the global uno service manager.
78             Must be used to create own needed services.
79          */
80         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
81 
82         //---------------------------------------
83         /** points to the underlying configuration.
84             This ModuleManager does not cache - it calls directly the
85             configuration API!
86           */
87         css::uno::Reference< css::container::XNameAccess > m_xCFG;
88 
89     //___________________________________________
90     // interface
91 
92     public:
93 
94                  ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
95         virtual ~ModuleManager(                                                                   );
96 
97         // XInterface, XTypeProvider, XServiceInfo
98         FWK_DECLARE_XINTERFACE
99         FWK_DECLARE_XTYPEPROVIDER
100         DECLARE_XSERVICEINFO
101 
102         // XModuleManager
103         virtual ::rtl::OUString SAL_CALL identify(const css::uno::Reference< css::uno::XInterface >& xModule)
104             throw(css::lang::IllegalArgumentException,
105                   css::frame::UnknownModuleException,
106                   css::uno::RuntimeException         );
107 
108         // XNameReplace
109         virtual void SAL_CALL replaceByName(const ::rtl::OUString& sName ,
110                                             const css::uno::Any&   aValue)
111             throw (css::lang::IllegalArgumentException   ,
112                    css::container::NoSuchElementException,
113                    css::lang::WrappedTargetException     ,
114                    css::uno::RuntimeException            );
115 
116         // XNameAccess
117         virtual css::uno::Any SAL_CALL getByName(const ::rtl::OUString& sName)
118             throw(css::container::NoSuchElementException,
119                   css::lang::WrappedTargetException     ,
120                   css::uno::RuntimeException            );
121 
122         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
123             throw(css::uno::RuntimeException);
124 
125         virtual sal_Bool SAL_CALL hasByName(const ::rtl::OUString& sName)
126             throw(css::uno::RuntimeException);
127 
128         // XElementAccess
129         virtual css::uno::Type SAL_CALL getElementType()
130             throw(css::uno::RuntimeException);
131 
132         virtual sal_Bool SAL_CALL hasElements()
133             throw(css::uno::RuntimeException);
134 
135         // XContainerQuery
136         virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByQuery(const ::rtl::OUString& sQuery)
137             throw(css::uno::RuntimeException);
138 
139         virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByProperties(const css::uno::Sequence< css::beans::NamedValue >& lProperties)
140             throw(css::uno::RuntimeException);
141     //___________________________________________
142     // helper
143 
144     private:
145 
146         //---------------------------------------
147         /** @short  open the underlying configuration.
148 
149             @descr  This method must be called everytimes
150                     a (reaonly!) configuration is needed. Because
151                     method works together with the member
152                     m_xCFG, open it on demand and cache it
153                     afterwards.
154 
155                     Note: A writable configuration access
156                     must be created explicitly. Otherwise
157                     we cant make sure that broken write requests
158                     wont affect our read access !
159 
160             @return [com.sun.star.container.XNameAccess]
161                     the configuration object
162 
163             @throw  [com.sun.star.uno.RuntimeException]
164                     if config could not be opened successfully!
165 
166             @threadsafe
167           */
168         css::uno::Reference< css::container::XNameAccess > implts_getConfig()
169             throw(css::uno::RuntimeException);
170 
171         //---------------------------------------
172         /** @short  makes the real identification of the module.
173 
174             @descr  It checks for the optional but preferred interface
175                     XModule first. If this module does not exists at the
176                     given component it tries to use XServiceInfo instead.
177 
178                     Note: This method try to locate a suitable module name.
179                     Nothing else. Selecting the right component and throwing suitable
180                     exceptions must be done outside.
181 
182             @see    identify()
183 
184             @param  xComponent
185                     the module for identification.
186 
187             @return The identifier of the given module.
188                     Can be empty if given component is not a real module !
189 
190             @threadsafe
191          */
192         ::rtl::OUString implts_identify(const css::uno::Reference< css::uno::XInterface >& xComponent);
193 };
194 
195 } // namespace framework
196 
197 #endif // __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
198