24#include <com/sun/star/beans/NamedValue.hpp>
25#include <com/sun/star/container/NoSuchElementException.hpp>
26#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
27#include <com/sun/star/container/XNamed.hpp>
28#include <com/sun/star/lang/XMultiServiceFactory.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
31#include <com/sun/star/registry/InvalidRegistryException.hpp>
32#include <com/sun/star/registry/InvalidValueException.hpp>
33#include <com/sun/star/registry/RegistryKeyType.hpp>
34#include <com/sun/star/registry/RegistryValueType.hpp>
35#include <com/sun/star/registry/XRegistryKey.hpp>
36#include <com/sun/star/registry/XSimpleRegistry.hpp>
37#include <com/sun/star/uno/Any.hxx>
38#include <com/sun/star/uno/DeploymentException.hpp>
39#include <com/sun/star/uno/Exception.hpp>
40#include <com/sun/star/uno/Reference.hxx>
41#include <com/sun/star/uno/RuntimeException.hpp>
42#include <com/sun/star/uno/Sequence.hxx>
43#include <com/sun/star/uno/Type.hxx>
44#include <com/sun/star/uno/TypeClass.hpp>
45#include <com/sun/star/uno/XComponentContext.hpp>
46#include <com/sun/star/uno/XInterface.hpp>
47#include <com/sun/star/util/XFlushable.hpp>
54#include <rtl/ustring.hxx>
67 public cppu::WeakImplHelper<
68 css::lang::XServiceInfo, css::registry::XSimpleRegistry,
69 css::util::XFlushable >
72 explicit Service(css::uno::Reference< css::uno::XComponentContext >
const & context);
78 virtual ~Service()
override {}
81 {
return "com.sun.star.comp.configuration.ConfigurationRegistry"; }
86 virtual css::uno::Sequence< OUString > SAL_CALL
88 {
return {
"com.sun.star.configuration.ConfigurationRegistry" }; }
90 virtual OUString SAL_CALL getURL()
override;
92 virtual void SAL_CALL open(
95 virtual sal_Bool SAL_CALL isValid()
override;
97 virtual void SAL_CALL
close()
override;
99 virtual void SAL_CALL destroy()
override;
101 virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
102 getRootKey()
override;
104 virtual sal_Bool SAL_CALL isReadOnly()
override;
106 virtual void SAL_CALL mergeKey(OUString
const &, OUString
const &)
override;
108 virtual void SAL_CALL flush()
override;
110 virtual void SAL_CALL addFlushListener(
111 css::uno::Reference< css::util::XFlushListener >
const &)
override;
113 virtual void SAL_CALL removeFlushListener(
114 css::uno::Reference< css::util::XFlushListener >
const &)
override;
118 void checkValid_RuntimeException();
122 css::uno::Reference< css::lang::XMultiServiceFactory >
provider_;
124 css::uno::Reference< css::uno::XInterface >
access_;
132 public cppu::WeakImplHelper< css::registry::XRegistryKey >
135 RegistryKey(Service & service, css::uno::Any value):
144 virtual OUString SAL_CALL
getKeyName()
override;
146 virtual sal_Bool SAL_CALL isReadOnly()
override;
148 virtual sal_Bool SAL_CALL isValid()
override;
150 virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
151 OUString
const &)
override;
153 virtual css::registry::RegistryValueType SAL_CALL getValueType()
override;
155 virtual sal_Int32 SAL_CALL getLongValue()
override;
157 virtual void SAL_CALL setLongValue(sal_Int32)
override;
159 virtual css::uno::Sequence< sal_Int32 > SAL_CALL
getLongListValue()
override;
162 css::uno::Sequence< sal_Int32 >
const &)
override;
164 virtual OUString SAL_CALL getAsciiValue()
override;
166 virtual void SAL_CALL setAsciiValue(OUString
const &)
override;
168 virtual css::uno::Sequence< OUString > SAL_CALL getAsciiListValue()
override;
170 virtual void SAL_CALL setAsciiListValue(
171 css::uno::Sequence< OUString >
const &)
override;
173 virtual OUString SAL_CALL getStringValue()
override;
175 virtual void SAL_CALL setStringValue(OUString
const &)
override;
180 css::uno::Sequence< OUString >
const &)
override;
182 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue()
override;
184 virtual void SAL_CALL setBinaryValue(css::uno::Sequence< sal_Int8 >
const &)
override;
186 virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
openKey(
187 OUString
const & aKeyName)
override;
189 virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
192 virtual void SAL_CALL
closeKey()
override;
194 virtual void SAL_CALL
deleteKey(OUString
const &)
override;
197 css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
198 SAL_CALL openKeys()
override;
200 virtual css::uno::Sequence< OUString > SAL_CALL
getKeyNames()
override;
202 virtual sal_Bool SAL_CALL createLink(
203 OUString
const &, OUString
const &)
override;
205 virtual void SAL_CALL deleteLink(OUString
const &)
override;
207 virtual OUString SAL_CALL getLinkTarget(OUString
const &)
override;
209 virtual OUString SAL_CALL getResolvedName(
210 OUString
const & aKeyName)
override;
217 css::uno::Reference< css::uno::XComponentContext >
const & context)
220 assert(context.is());
223 context->getServiceManager()->createInstanceWithContext(
224 "com.sun.star.configuration.DefaultProvider", context),
225 css::uno::UNO_QUERY_THROW);
226 }
catch (css::uno::RuntimeException &) {
228 }
catch (css::uno::Exception & e) {
229 throw css::uno::DeploymentException(
230 (
"component context fails to supply service"
231 " com.sun.star.configuration.DefaultProvider of type"
232 " com.sun.star.lang.XMultiServiceFactory: " + e.Message),
237OUString Service::getURL() {
238 std::unique_lock g(
mutex_);
239 checkValid_RuntimeException();
246 std::unique_lock g(
mutex_);
250 css::uno::Sequence< css::uno::Any >
args{ css::uno::Any(
251 css::beans::NamedValue(
"nodepath", css::uno::Any(rURL))) };
255 ? OUString(
"com.sun.star.configuration.ConfigurationAccess")
257 "com.sun.star.configuration.ConfigurationUpdateAccess")),
259 }
catch (css::uno::RuntimeException &) {
261 }
catch (css::uno::Exception & e) {
263 throw css::lang::WrappedTargetRuntimeException(
264 "com.sun.star.configuration.ConfigurationRegistry: open failed: " +
273 std::unique_lock g(
mutex_);
279 std::unique_lock g(
mutex_);
284void Service::destroy()
286 throw css::uno::RuntimeException(
287 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
291css::uno::Reference< css::registry::XRegistryKey > Service::getRootKey()
293 std::unique_lock g(
mutex_);
299 std::unique_lock g(
mutex_);
300 checkValid_RuntimeException();
304void Service::mergeKey(OUString
const &, OUString
const &)
306 throw css::uno::RuntimeException(
307 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
313 throw css::uno::RuntimeException(
314 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
318void Service::addFlushListener(
319 css::uno::Reference< css::util::XFlushListener >
const &)
321 throw css::uno::RuntimeException(
322 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
326void Service::removeFlushListener(
327 css::uno::Reference< css::util::XFlushListener >
const &)
329 throw css::uno::RuntimeException(
330 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
334void Service::checkValid() {
336 throw css::registry::InvalidRegistryException(
337 "com.sun.star.configuration.ConfigurationRegistry: not valid",
342void Service::checkValid_RuntimeException() {
344 throw css::uno::RuntimeException(
345 "com.sun.star.configuration.ConfigurationRegistry: not valid",
350void Service::doClose() {
354OUString RegistryKey::getKeyName() {
355 std::unique_lock g(
service_.mutex_);
356 service_.checkValid_RuntimeException();
357 css::uno::Reference< css::container::XNamed > named;
359 return named->getName();
361 throw css::uno::RuntimeException(
362 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
368 std::unique_lock g(
service_.mutex_);
369 service_.checkValid_RuntimeException();
377css::registry::RegistryKeyType RegistryKey::getKeyType(OUString
const &)
379 std::unique_lock g(
service_.mutex_);
381 return css::registry::RegistryKeyType_KEY;
384css::registry::RegistryValueType RegistryKey::getValueType()
386 std::unique_lock g(
service_.mutex_);
389 switch (
t.getTypeClass()) {
390 case css::uno::TypeClass_LONG:
391 return css::registry::RegistryValueType_LONG;
392 case css::uno::TypeClass_STRING:
393 return css::registry::RegistryValueType_STRING;
394 case css::uno::TypeClass_SEQUENCE:
395 if (t ==
cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get()) {
396 return css::registry::RegistryValueType_BINARY;
397 }
else if (t ==
cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get())
399 return css::registry::RegistryValueType_LONGLIST;
403 return css::registry::RegistryValueType_STRINGLIST;
407 return css::registry::RegistryValueType_NOT_DEFINED;
411sal_Int32 RegistryKey::getLongValue()
413 std::unique_lock g(
service_.mutex_);
419 throw css::registry::InvalidValueException(
420 "com.sun.star.configuration.ConfigurationRegistry",
424void RegistryKey::setLongValue(sal_Int32)
426 throw css::uno::RuntimeException(
427 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
433 std::unique_lock g(
service_.mutex_);
435 css::uno::Sequence< sal_Int32 >
v;
439 throw css::registry::InvalidValueException(
440 "com.sun.star.configuration.ConfigurationRegistry",
446 throw css::uno::RuntimeException(
447 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
451OUString RegistryKey::getAsciiValue()
453 std::unique_lock g(
service_.mutex_);
459 throw css::registry::InvalidValueException(
460 "com.sun.star.configuration.ConfigurationRegistry",
464void RegistryKey::setAsciiValue(OUString
const &)
466 throw css::uno::RuntimeException(
467 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
471css::uno::Sequence< OUString > RegistryKey::getAsciiListValue()
473 std::unique_lock g(
service_.mutex_);
475 css::uno::Sequence< OUString >
v;
479 throw css::registry::InvalidValueException(
480 "com.sun.star.configuration.ConfigurationRegistry",
484void RegistryKey::setAsciiListValue(css::uno::Sequence< OUString >
const &)
486 throw css::uno::RuntimeException(
487 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
491OUString RegistryKey::getStringValue()
493 std::unique_lock g(
service_.mutex_);
499 throw css::registry::InvalidValueException(
500 "com.sun.star.configuration.ConfigurationRegistry",
504void RegistryKey::setStringValue(OUString
const &)
506 throw css::uno::RuntimeException(
507 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
513 std::unique_lock g(
service_.mutex_);
515 css::uno::Sequence< OUString >
v;
519 throw css::registry::InvalidValueException(
520 "com.sun.star.configuration.ConfigurationRegistry",
525 css::uno::Sequence< OUString >
const &)
527 throw css::uno::RuntimeException(
528 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
532css::uno::Sequence< sal_Int8 > RegistryKey::getBinaryValue()
534 std::unique_lock g(
service_.mutex_);
536 css::uno::Sequence< sal_Int8 >
v;
540 throw css::registry::InvalidValueException(
541 "com.sun.star.configuration.ConfigurationRegistry",
545void RegistryKey::setBinaryValue(css::uno::Sequence< sal_Int8 >
const &)
547 throw css::uno::RuntimeException(
548 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
553 OUString
const & aKeyName)
555 std::unique_lock g(
service_.mutex_);
556 service_.checkValid_RuntimeException();
557 css::uno::Reference< css::container::XHierarchicalNameAccess > access;
561 service_, access->getByHierarchicalName(aKeyName));
562 }
catch (css::container::NoSuchElementException &) {}
564 return css::uno::Reference< css::registry::XRegistryKey >();
570 throw css::uno::RuntimeException(
571 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
577 std::unique_lock g(
service_.mutex_);
578 service_.checkValid_RuntimeException();
583 throw css::uno::RuntimeException(
584 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
588css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
589RegistryKey::openKeys()
591 throw css::uno::RuntimeException(
592 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
598 throw css::uno::RuntimeException(
599 "com.sun.star.configuration.ConfigurationRegistry: not implemented",
603sal_Bool RegistryKey::createLink(OUString
const &, OUString
const &)
605 std::unique_lock g(
service_.mutex_);
606 service_.checkValid_RuntimeException();
610void RegistryKey::deleteLink(OUString
const &)
612 std::unique_lock g(
service_.mutex_);
613 service_.checkValid_RuntimeException();
616OUString RegistryKey::getLinkTarget(OUString
const &)
618 std::unique_lock g(
service_.mutex_);
619 service_.checkValid_RuntimeException();
623OUString RegistryKey::getResolvedName(OUString
const & aKeyName)
625 std::unique_lock g(
service_.mutex_);
626 service_.checkValid_RuntimeException();
632extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
634 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
636 return cppu::acquire(
new Service(context));
RegError getKeyNames(const OUString &keyName, RegistryKeyNames &rSubKeyNames)
RegError openKey(const OUString &keyName, RegistryKey &rOpenKey)
RegError deleteKey(const OUString &keyName)
RegError getLongListValue(const OUString &keyName, RegistryValueList< sal_Int32 > &rValueList)
RegError setStringListValue(const OUString &keyName, char **pValueList, sal_uInt32 len)
RegError setLongListValue(const OUString &keyName, sal_Int32 const *pValueList, sal_uInt32 len)
RegError createKey(const OUString &keyName, RegistryKey &rNewKey)
RegError getStringListValue(const OUString &keyName, RegistryValueList< char * > &rValueList)
css::uno::Reference< css::lang::XMultiServiceFactory > provider_
css::uno::Reference< css::uno::XInterface > access_
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_configuration_ConfigurationRegistry_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 const *pValueList, sal_uInt32 len)
RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phNewKey)
RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char **pValueList, sal_uInt32 len)
RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char ***pValueList, sal_uInt32 *pLen)
RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey, rtl_uString *keyName, rtl_uString ***pSubKeyNames, sal_uInt32 *pnSubKeys)
RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 **pValueList, sal_uInt32 *pLen)
RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString **pKeyName)
RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, rtl_uString *keyName)
RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phOpenKey)
RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey)