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 #include "precompiled_configmgr.hxx"
29*cdf0e10cSrcweir #include "sal/config.h"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <vector>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "boost/noncopyable.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/lang/EventObject.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/lang/Locale.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/lang/XLocalizable.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
40*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
41*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp"
42*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
43*cdf0e10cSrcweir #include "com/sun/star/uno/DeploymentException.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
46*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
48*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/util/XFlushListener.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/util/XFlushable.hpp"
52*cdf0e10cSrcweir #include "com/sun/star/util/XRefreshListener.hpp"
53*cdf0e10cSrcweir #include "com/sun/star/util/XRefreshable.hpp"
54*cdf0e10cSrcweir #include "comphelper/locale.hxx"
55*cdf0e10cSrcweir #include "cppu/unotype.hxx"
56*cdf0e10cSrcweir #include "cppuhelper/compbase5.hxx"
57*cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
58*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
59*cdf0e10cSrcweir #include "cppuhelper/interfacecontainer.hxx"
60*cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
61*cdf0e10cSrcweir #include "osl/diagnose.h"
62*cdf0e10cSrcweir #include "osl/mutex.hxx"
63*cdf0e10cSrcweir #include "sal/types.h"
64*cdf0e10cSrcweir #include "rtl/ref.hxx"
65*cdf0e10cSrcweir #include "rtl/unload.h"
66*cdf0e10cSrcweir #include "rtl/ustring.h"
67*cdf0e10cSrcweir #include "rtl/ustring.hxx"
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir #include "components.hxx"
70*cdf0e10cSrcweir #include "configurationprovider.hxx"
71*cdf0e10cSrcweir #include "lock.hxx"
72*cdf0e10cSrcweir #include "rootaccess.hxx"
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir namespace configmgr { namespace configuration_provider {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir namespace {
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace css = com::sun::star;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir char const accessServiceName[] =
81*cdf0e10cSrcweir     "com.sun.star.configuration.ConfigurationAccess";
82*cdf0e10cSrcweir char const updateAccessServiceName[] =
83*cdf0e10cSrcweir     "com.sun.star.configuration.ConfigurationUpdateAccess";
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void badNodePath() {
86*cdf0e10cSrcweir     throw css::uno::Exception(
87*cdf0e10cSrcweir         rtl::OUString(
88*cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM(
89*cdf0e10cSrcweir                 "com.sun.star.configuration.ConfigurationProvider expects a"
90*cdf0e10cSrcweir                 " single, non-empty, string nodepath argument")),
91*cdf0e10cSrcweir         0);
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir typedef
95*cdf0e10cSrcweir     cppu::WeakComponentImplHelper5<
96*cdf0e10cSrcweir         css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
97*cdf0e10cSrcweir         css::util::XRefreshable, css::util::XFlushable,
98*cdf0e10cSrcweir         css::lang::XLocalizable >
99*cdf0e10cSrcweir     ServiceBase;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir class Service:
102*cdf0e10cSrcweir     private osl::Mutex, public ServiceBase, private boost::noncopyable
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir public:
105*cdf0e10cSrcweir     Service(
106*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const context,
107*cdf0e10cSrcweir         rtl::OUString const & locale):
108*cdf0e10cSrcweir         ServiceBase(*static_cast< osl::Mutex * >(this)), context_(context),
109*cdf0e10cSrcweir         locale_(locale)
110*cdf0e10cSrcweir     {
111*cdf0e10cSrcweir         OSL_ASSERT(context.is());
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir private:
115*cdf0e10cSrcweir     virtual ~Service() {}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     virtual void SAL_CALL disposing() { flushModifications(); }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
120*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
121*cdf0e10cSrcweir     { return configuration_provider::getImplementationName(); }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
124*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
125*cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; } //TODO
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
128*cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
129*cdf0e10cSrcweir     { return configuration_provider::getSupportedServiceNames(); }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
132*cdf0e10cSrcweir         rtl::OUString const & aServiceSpecifier)
133*cdf0e10cSrcweir         throw (css::uno::Exception, css::uno::RuntimeException);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
136*cdf0e10cSrcweir     createInstanceWithArguments(
137*cdf0e10cSrcweir         rtl::OUString const & ServiceSpecifier,
138*cdf0e10cSrcweir         css::uno::Sequence< css::uno::Any > const & Arguments)
139*cdf0e10cSrcweir         throw (css::uno::Exception, css::uno::RuntimeException);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
142*cdf0e10cSrcweir     getAvailableServiceNames() throw (css::uno::RuntimeException);
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     virtual void SAL_CALL refresh() throw (css::uno::RuntimeException);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     virtual void SAL_CALL addRefreshListener(
147*cdf0e10cSrcweir         css::uno::Reference< css::util::XRefreshListener > const & l)
148*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     virtual void SAL_CALL removeRefreshListener(
151*cdf0e10cSrcweir         css::uno::Reference< css::util::XRefreshListener > const & l)
152*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     virtual void SAL_CALL flush() throw (css::uno::RuntimeException);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     virtual void SAL_CALL addFlushListener(
157*cdf0e10cSrcweir         css::uno::Reference< css::util::XFlushListener > const & l)
158*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     virtual void SAL_CALL removeFlushListener(
161*cdf0e10cSrcweir         css::uno::Reference< css::util::XFlushListener > const & l)
162*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     virtual void SAL_CALL setLocale(css::lang::Locale const & eLocale)
165*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     virtual css::lang::Locale SAL_CALL getLocale()
168*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     void flushModifications() const;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > context_;
173*cdf0e10cSrcweir     rtl::OUString locale_;
174*cdf0e10cSrcweir };
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > Service::createInstance(
177*cdf0e10cSrcweir     rtl::OUString const & aServiceSpecifier)
178*cdf0e10cSrcweir     throw (css::uno::Exception, css::uno::RuntimeException)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     return createInstanceWithArguments(
181*cdf0e10cSrcweir         aServiceSpecifier, css::uno::Sequence< css::uno::Any >());
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >
185*cdf0e10cSrcweir Service::createInstanceWithArguments(
186*cdf0e10cSrcweir     rtl::OUString const & ServiceSpecifier,
187*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > const & Arguments)
188*cdf0e10cSrcweir     throw (css::uno::Exception, css::uno::RuntimeException)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     rtl::OUString nodepath;
191*cdf0e10cSrcweir     rtl::OUString locale;
192*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < Arguments.getLength(); ++i) {
193*cdf0e10cSrcweir         css::beans::NamedValue v1;
194*cdf0e10cSrcweir         css::beans::PropertyValue v2;
195*cdf0e10cSrcweir         rtl::OUString name;
196*cdf0e10cSrcweir         css::uno::Any value;
197*cdf0e10cSrcweir         if (Arguments[i] >>= v1) {
198*cdf0e10cSrcweir             name = v1.Name;
199*cdf0e10cSrcweir             value = v1.Value;
200*cdf0e10cSrcweir         } else if (Arguments[i] >>= v2) {
201*cdf0e10cSrcweir             name = v2.Name;
202*cdf0e10cSrcweir             value = v2.Value;
203*cdf0e10cSrcweir         } else if (Arguments.getLength() == 1 && (Arguments[i] >>= nodepath)) {
204*cdf0e10cSrcweir             // For backwards compatibility, allow a single string argument that
205*cdf0e10cSrcweir             // denotes nodepath.
206*cdf0e10cSrcweir             if (nodepath.getLength() == 0) {
207*cdf0e10cSrcweir                 badNodePath();
208*cdf0e10cSrcweir             }
209*cdf0e10cSrcweir             break;
210*cdf0e10cSrcweir         } else {
211*cdf0e10cSrcweir             throw css::uno::Exception(
212*cdf0e10cSrcweir                 rtl::OUString(
213*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
214*cdf0e10cSrcweir                         "com.sun.star.configuration.ConfigurationProvider"
215*cdf0e10cSrcweir                         " expects NamedValue or PropertyValue arguments")),
216*cdf0e10cSrcweir                 0);
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir         // For backwards compatibility, allow "nodepath" and "Locale" in any
219*cdf0e10cSrcweir         // case:
220*cdf0e10cSrcweir         if (name.equalsIgnoreAsciiCaseAsciiL(
221*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM("nodepath")))
222*cdf0e10cSrcweir         {
223*cdf0e10cSrcweir             if (nodepath.getLength() != 0 || !(value >>= nodepath) ||
224*cdf0e10cSrcweir                 nodepath.getLength() == 0)
225*cdf0e10cSrcweir             {
226*cdf0e10cSrcweir                 badNodePath();
227*cdf0e10cSrcweir             }
228*cdf0e10cSrcweir         } else if (name.equalsIgnoreAsciiCaseAsciiL(
229*cdf0e10cSrcweir                        RTL_CONSTASCII_STRINGPARAM("locale")))
230*cdf0e10cSrcweir         {
231*cdf0e10cSrcweir             if (locale.getLength() != 0 || !(value >>= locale) ||
232*cdf0e10cSrcweir                 locale.getLength() == 0)
233*cdf0e10cSrcweir             {
234*cdf0e10cSrcweir                 throw css::uno::Exception(
235*cdf0e10cSrcweir                     rtl::OUString(
236*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
237*cdf0e10cSrcweir                             "com.sun.star.configuration.ConfigurationProvider"
238*cdf0e10cSrcweir                             " expects at most one, non-empty, string Locale"
239*cdf0e10cSrcweir                             " argument")),
240*cdf0e10cSrcweir                     0);
241*cdf0e10cSrcweir             }
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir     if (nodepath.getLength() == 0) {
245*cdf0e10cSrcweir         badNodePath();
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir     // For backwards compatibility, allow a nodepath that misses the leading
248*cdf0e10cSrcweir     // slash:
249*cdf0e10cSrcweir     if (nodepath[0] != '/') {
250*cdf0e10cSrcweir         nodepath = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + nodepath;
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir     if (locale.getLength() == 0) {
253*cdf0e10cSrcweir         //TODO: should the Access use the dynamically changing locale_ instead?
254*cdf0e10cSrcweir         locale = locale_;
255*cdf0e10cSrcweir         if (locale.getLength() == 0) {
256*cdf0e10cSrcweir             locale = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US"));
257*cdf0e10cSrcweir         }
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir     bool update;
260*cdf0e10cSrcweir     if (ServiceSpecifier.equalsAsciiL(
261*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM(accessServiceName)))
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir         update = false;
264*cdf0e10cSrcweir     } else if (ServiceSpecifier.equalsAsciiL(
265*cdf0e10cSrcweir                    RTL_CONSTASCII_STRINGPARAM(updateAccessServiceName)))
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         update = true;
268*cdf0e10cSrcweir     } else {
269*cdf0e10cSrcweir         throw css::uno::Exception(
270*cdf0e10cSrcweir             (rtl::OUString(
271*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
272*cdf0e10cSrcweir                     "com.sun.star.configuration.ConfigurationProvider does not"
273*cdf0e10cSrcweir                     " support service ")) +
274*cdf0e10cSrcweir              ServiceSpecifier),
275*cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this));
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir     osl::MutexGuard guard(lock);
278*cdf0e10cSrcweir     Components & components = Components::getSingleton(context_);
279*cdf0e10cSrcweir     rtl::Reference< RootAccess > root(
280*cdf0e10cSrcweir         new RootAccess(components, nodepath, locale, update));
281*cdf0e10cSrcweir     if (root->isValue()) {
282*cdf0e10cSrcweir         throw css::uno::Exception(
283*cdf0e10cSrcweir             (rtl::OUString(
284*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
285*cdf0e10cSrcweir                     "com.sun.star.configuration.ConfigurationProvider: there is"
286*cdf0e10cSrcweir                     " a leaf value at nodepath ")) +
287*cdf0e10cSrcweir              nodepath),
288*cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this));
289*cdf0e10cSrcweir     }
290*cdf0e10cSrcweir     components.addRootAccess(root);
291*cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(root.get());
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Service::getAvailableServiceNames()
295*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > names(2);
298*cdf0e10cSrcweir     names[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(accessServiceName));
299*cdf0e10cSrcweir     names[1] = rtl::OUString(
300*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(updateAccessServiceName));
301*cdf0e10cSrcweir     return names;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir void Service::refresh() throw (css::uno::RuntimeException) {
305*cdf0e10cSrcweir     //TODO
306*cdf0e10cSrcweir     cppu::OInterfaceContainerHelper * cont = rBHelper.getContainer(
307*cdf0e10cSrcweir         cppu::UnoType< css::util::XRefreshListener >::get());
308*cdf0e10cSrcweir     if (cont != 0) {
309*cdf0e10cSrcweir         css::lang::EventObject ev(static_cast< cppu::OWeakObject * >(this));
310*cdf0e10cSrcweir         cont->notifyEach(&css::util::XRefreshListener::refreshed, ev);
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir void Service::addRefreshListener(
315*cdf0e10cSrcweir     css::uno::Reference< css::util::XRefreshListener > const & l)
316*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir     rBHelper.addListener(
319*cdf0e10cSrcweir         cppu::UnoType< css::util::XRefreshListener >::get(), l);
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir void Service::removeRefreshListener(
323*cdf0e10cSrcweir     css::uno::Reference< css::util::XRefreshListener > const & l)
324*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir     rBHelper.removeListener(
327*cdf0e10cSrcweir         cppu::UnoType< css::util::XRefreshListener >::get(), l);
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir void Service::flush() throw (css::uno::RuntimeException) {
331*cdf0e10cSrcweir     flushModifications();
332*cdf0e10cSrcweir     cppu::OInterfaceContainerHelper * cont = rBHelper.getContainer(
333*cdf0e10cSrcweir         cppu::UnoType< css::util::XFlushListener >::get());
334*cdf0e10cSrcweir     if (cont != 0) {
335*cdf0e10cSrcweir         css::lang::EventObject ev(static_cast< cppu::OWeakObject * >(this));
336*cdf0e10cSrcweir         cont->notifyEach(&css::util::XFlushListener::flushed, ev);
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir void Service::addFlushListener(
341*cdf0e10cSrcweir     css::uno::Reference< css::util::XFlushListener > const & l)
342*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     rBHelper.addListener(cppu::UnoType< css::util::XFlushListener >::get(), l);
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir void Service::removeFlushListener(
348*cdf0e10cSrcweir     css::uno::Reference< css::util::XFlushListener > const & l)
349*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     rBHelper.removeListener(
352*cdf0e10cSrcweir         cppu::UnoType< css::util::XFlushListener >::get(), l);
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir void Service::setLocale(css::lang::Locale const & eLocale)
356*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir     osl::MutexGuard guard(lock);
359*cdf0e10cSrcweir     locale_ = comphelper::Locale(
360*cdf0e10cSrcweir         eLocale.Language, eLocale.Country, eLocale.Variant).toISO();
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir css::lang::Locale Service::getLocale() throw (css::uno::RuntimeException) {
364*cdf0e10cSrcweir     osl::MutexGuard guard(lock);
365*cdf0e10cSrcweir     css::lang::Locale loc;
366*cdf0e10cSrcweir     if (locale_.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("*"))) {
367*cdf0e10cSrcweir         loc.Language = locale_;
368*cdf0e10cSrcweir     } else if (locale_.getLength() != 0) {
369*cdf0e10cSrcweir         try {
370*cdf0e10cSrcweir             comphelper::Locale l(locale_);
371*cdf0e10cSrcweir             loc.Language = l.getLanguage();
372*cdf0e10cSrcweir             loc.Country = l.getCountry();
373*cdf0e10cSrcweir             loc.Variant = l.getVariant();
374*cdf0e10cSrcweir         } catch (comphelper::Locale::MalFormedLocaleException & e) {
375*cdf0e10cSrcweir             throw css::uno::RuntimeException(
376*cdf0e10cSrcweir                 (rtl::OUString(
377*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("MalformedLocaleException: ")) +
378*cdf0e10cSrcweir                  e.Message),
379*cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >(this));
380*cdf0e10cSrcweir         }
381*cdf0e10cSrcweir     }
382*cdf0e10cSrcweir     return loc;
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir void Service::flushModifications() const {
386*cdf0e10cSrcweir     Components * components;
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         osl::MutexGuard guard(lock);
389*cdf0e10cSrcweir         components = &Components::getSingleton(context_);
390*cdf0e10cSrcweir     }
391*cdf0e10cSrcweir     components->flushModifications();
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir class Factory:
395*cdf0e10cSrcweir     public cppu::WeakImplHelper2<
396*cdf0e10cSrcweir         css::lang::XSingleComponentFactory, css::lang::XServiceInfo >,
397*cdf0e10cSrcweir     private boost::noncopyable
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir public:
400*cdf0e10cSrcweir     Factory() {}
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir private:
403*cdf0e10cSrcweir     virtual ~Factory() {}
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
406*cdf0e10cSrcweir     createInstanceWithContext(
407*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & Context)
408*cdf0e10cSrcweir         throw (css::uno::Exception, css::uno::RuntimeException);
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
411*cdf0e10cSrcweir     createInstanceWithArgumentsAndContext(
412*cdf0e10cSrcweir         css::uno::Sequence< css::uno::Any > const & Arguments,
413*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & Context)
414*cdf0e10cSrcweir         throw (css::uno::Exception, css::uno::RuntimeException);
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
417*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
418*cdf0e10cSrcweir     { return configuration_provider::getImplementationName(); }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
421*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
422*cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; } //TODO
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
425*cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
426*cdf0e10cSrcweir     { return configuration_provider::getSupportedServiceNames(); }
427*cdf0e10cSrcweir };
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > Factory::createInstanceWithContext(
430*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & Context)
431*cdf0e10cSrcweir     throw (css::uno::Exception, css::uno::RuntimeException)
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     return createInstanceWithArgumentsAndContext(
434*cdf0e10cSrcweir         css::uno::Sequence< css::uno::Any >(), Context);
435*cdf0e10cSrcweir }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >
438*cdf0e10cSrcweir Factory::createInstanceWithArgumentsAndContext(
439*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > const & Arguments,
440*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & Context)
441*cdf0e10cSrcweir     throw (css::uno::Exception, css::uno::RuntimeException)
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir     if (Arguments.getLength() == 0) {
444*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > instance;
445*cdf0e10cSrcweir         if (!(Context->getValueByName(
446*cdf0e10cSrcweir                   rtl::OUString(
447*cdf0e10cSrcweir                       RTL_CONSTASCII_USTRINGPARAM(
448*cdf0e10cSrcweir                           "/singletons/"
449*cdf0e10cSrcweir                           "com.sun.star.configuration.theDefaultProvider")))
450*cdf0e10cSrcweir               >>= instance) ||
451*cdf0e10cSrcweir             !instance.is())
452*cdf0e10cSrcweir         {
453*cdf0e10cSrcweir             throw css::uno::DeploymentException(
454*cdf0e10cSrcweir                 rtl::OUString(
455*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
456*cdf0e10cSrcweir                         "component context fails to supply singleton"
457*cdf0e10cSrcweir                         " com.sun.star.configuration.theDefaultProvider")),
458*cdf0e10cSrcweir                 Context);
459*cdf0e10cSrcweir         }
460*cdf0e10cSrcweir         return instance;
461*cdf0e10cSrcweir     } else {
462*cdf0e10cSrcweir         rtl::OUString locale;
463*cdf0e10cSrcweir         for (sal_Int32 i = 0; i < Arguments.getLength(); ++i) {
464*cdf0e10cSrcweir             css::beans::NamedValue v1;
465*cdf0e10cSrcweir             css::beans::PropertyValue v2;
466*cdf0e10cSrcweir             rtl::OUString name;
467*cdf0e10cSrcweir             css::uno::Any value;
468*cdf0e10cSrcweir             if (Arguments[i] >>= v1) {
469*cdf0e10cSrcweir                 name = v1.Name;
470*cdf0e10cSrcweir                 value = v1.Value;
471*cdf0e10cSrcweir             } else if (Arguments[i] >>= v2) {
472*cdf0e10cSrcweir                 name = v2.Name;
473*cdf0e10cSrcweir                 value = v2.Value;
474*cdf0e10cSrcweir             } else {
475*cdf0e10cSrcweir                 throw css::uno::Exception(
476*cdf0e10cSrcweir                     rtl::OUString(
477*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
478*cdf0e10cSrcweir                             "com.sun.star.configuration.ConfigurationProvider"
479*cdf0e10cSrcweir                             " factory expects NamedValue or PropertyValue"
480*cdf0e10cSrcweir                             " arguments")),
481*cdf0e10cSrcweir                     0);
482*cdf0e10cSrcweir             }
483*cdf0e10cSrcweir             // For backwards compatibility, allow "Locale" and (ignored)
484*cdf0e10cSrcweir             // "EnableAsync" in any case:
485*cdf0e10cSrcweir             if (name.equalsIgnoreAsciiCaseAsciiL(
486*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM("locale")))
487*cdf0e10cSrcweir             {
488*cdf0e10cSrcweir                 if (locale.getLength() != 0 || !(value >>= locale) ||
489*cdf0e10cSrcweir                     locale.getLength() == 0)
490*cdf0e10cSrcweir                 {
491*cdf0e10cSrcweir                     throw css::uno::Exception(
492*cdf0e10cSrcweir                         rtl::OUString(
493*cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM(
494*cdf0e10cSrcweir                                 "com.sun.star.configuration."
495*cdf0e10cSrcweir                                 "ConfigurationProvider factory expects at most"
496*cdf0e10cSrcweir                                 " one, non-empty, string Locale argument")),
497*cdf0e10cSrcweir                         0);
498*cdf0e10cSrcweir                 }
499*cdf0e10cSrcweir             } else if (!name.equalsIgnoreAsciiCaseAsciiL(
500*cdf0e10cSrcweir                            RTL_CONSTASCII_STRINGPARAM("enableasync")))
501*cdf0e10cSrcweir             {
502*cdf0e10cSrcweir                 throw css::uno::Exception(
503*cdf0e10cSrcweir                     rtl::OUString(
504*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
505*cdf0e10cSrcweir                             "com.sun.star.configuration.ConfigurationProvider"
506*cdf0e10cSrcweir                             " factory: unknown argument ")) + name,
507*cdf0e10cSrcweir                     0);
508*cdf0e10cSrcweir             }
509*cdf0e10cSrcweir         }
510*cdf0e10cSrcweir         return static_cast< cppu::OWeakObject * >(new Service(Context, locale));
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > createDefault(
517*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context)
518*cdf0e10cSrcweir {
519*cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(
520*cdf0e10cSrcweir         new Service(context, rtl::OUString()));
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir rtl::OUString getImplementationName() {
524*cdf0e10cSrcweir     return rtl::OUString(
525*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
526*cdf0e10cSrcweir             "com.sun.star.comp.configuration.ConfigurationProvider"));
527*cdf0e10cSrcweir }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
530*cdf0e10cSrcweir     rtl::OUString name(
531*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
532*cdf0e10cSrcweir             "com.sun.star.configuration.ConfigurationProvider"));
533*cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >(&name, 1);
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleComponentFactory >
537*cdf0e10cSrcweir createFactory(
538*cdf0e10cSrcweir     cppu::ComponentFactoryFunc, rtl::OUString const &,
539*cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > const &, rtl_ModuleCount *)
540*cdf0e10cSrcweir     SAL_THROW(())
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir     return new Factory;
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir } }
546