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