Commits

Anonymous committed ebf1e66

sb129: #i113189# textualservices no longer associates singletons with services, adapted bootstrapInitialContext accordingly

Comments (0)

Files changed (2)

cppuhelper/source/servicefactory.cxx

 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_cppuhelper.hxx"
 
-#if OSL_DEBUG_LEVEL > 0
-#include <stdio.h>
-#endif
 #include <vector>
 
 #include "rtl/string.hxx"
-#include "rtl/ustrbuf.hxx"
 #include "rtl/bootstrap.hxx"
 #include "osl/diagnose.h"
 #include "osl/file.h"
 #include "cppuhelper/servicefactory.hxx"
 #include "cppuhelper/bootstrap.hxx"
 
+#include "com/sun/star/uno/DeploymentException.hpp"
 #include "com/sun/star/uno/XComponentContext.hpp"
 #include "com/sun/star/lang/XInitialization.hpp"
 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
 using namespace ::osl;
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
+namespace css = com::sun::star;
 
 namespace cppu
 {
                     keys.getConstArray();
                 for ( sal_Int32 nPos = keys.getLength(); nPos--; )
                 {
-                    Reference< registry::XRegistryKey > const & xKey2 =
-                        pKeys[ nPos ];
-                    try
-                    {
-                        OUStringBuffer buf( 32 );
-                        buf.appendAscii(
-                            RTL_CONSTASCII_STRINGPARAM("/singletons/") );
-                        buf.append(
-                            xKey2->getKeyName().copy(
-                                sizeof("/SINGLETONS") /* -\0 +'/' */ ) );
-                        entry.name = buf.makeStringAndClear();
-                        entry.value <<= xKey2->getStringValue();
-                        context_values.push_back( entry );
+                    css::uno::Sequence< rtl::OUString > impls(
+                        css::uno::Reference< css::registry::XRegistryKey >(
+                            pKeys[nPos]->openKey(
+                                rtl::OUString(
+                                    RTL_CONSTASCII_USTRINGPARAM(
+                                        "REGISTERED_BY"))),
+                            css::uno::UNO_SET_THROW)->getAsciiListValue());
+                    switch (impls.getLength()) {
+                    case 0:
+                        throw css::uno::DeploymentException(
+                            (pKeys[nPos]->getKeyName() +
+                             rtl::OUString(
+                                 RTL_CONSTASCII_USTRINGPARAM(
+                                     "/REGISTERED_BY is empty"))),
+                            css::uno::Reference< css::uno::XInterface >());
+                    case 1:
+                        break;
+                    default:
+                        OSL_TRACE(
+                            ("arbitrarily chosing \"%s\" among multiple"
+                             " implementations for \"%s\""),
+                            rtl::OUStringToOString(
+                                impls[0], RTL_TEXTENCODING_UTF8).getStr(),
+                            rtl::OUStringToOString(
+                                pKeys[nPos]->getKeyName(),
+                                RTL_TEXTENCODING_UTF8).getStr());
+                        break;
                     }
-                    catch (Exception & rExc)
-                    {
-#if OSL_DEBUG_LEVEL > 0
-                        OString aStr(
-                            OUStringToOString(
-                                xKey2->getKeyName().copy( 11 ),
-                                RTL_TEXTENCODING_ASCII_US ) );
-                        OString aStr2(
-                            OUStringToOString(
-                                rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
-                        fprintf(
-                            stderr,
-                            "### failed reading singleton [%s]"
-                            " service name from registry: %s\n",
-                            aStr.getStr(), aStr2.getStr() );
-#else
-                        (void) rExc; // avoid warning about unused variable
-#endif
-                    }
+                    context_values.push_back(
+                        ContextEntry_Init(
+                            (rtl::OUString(
+                                RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
+                             pKeys[nPos]->getKeyName().copy(
+                                 RTL_CONSTASCII_LENGTH("/SINGLETONS/"))),
+                            css::uno::makeAny(impls[0]),
+                            true));
                 }
             }
         }

stoc/source/simpleregistry/textualservices.cxx

 
 typedef std::map< rtl::OUString, Implementation > Implementations;
 
-struct Service {
-    std::vector< rtl::OUString > implementations;
-};
-
-typedef std::map< rtl::OUString, Service > Services;
-
-struct Singleton {
-    rtl::OUString service;
-    std::vector< rtl::OUString > implementations;
-};
-
-typedef std::map< rtl::OUString, Singleton > Singletons;
+typedef std::map< rtl::OUString, std::vector< rtl::OUString > >
+    ImplementationMap;
 
 }
 
 {
 public:
     Implementations implementations;
-    Services services;
-    Singletons singletons;
+    ImplementationMap services;
+    ImplementationMap singletons;
 };
 
 namespace {
                 "http://openoffice.org/2010/uno-components")));
     enum State {
         STATE_BEGIN, STATE_END, STATE_COMPONENTS, STATE_COMPONENT_INITIAL,
-        STATE_COMPONENT, STATE_IMPLEMENTATION_INITIAL,
-        STATE_IMPLEMENTATION_SERVICE, STATE_IMPLEMENTATION_SINGLETON,
-        STATE_SERVICE, STATE_SINGLETON };
+        STATE_COMPONENT, STATE_IMPLEMENTATION, STATE_SERVICE, STATE_SINGLETON };
     for (State state = STATE_BEGIN;;) {
         xmlreader::Span name;
         int nsId;
                 name.equals(RTL_CONSTASCII_STRINGPARAM("implementation")))
             {
                 handleImplementation();
-                state = STATE_IMPLEMENTATION_INITIAL;
+                state = STATE_IMPLEMENTATION;
                 break;
             }
             throw css::registry::InvalidRegistryException(
                      RTL_CONSTASCII_USTRINGPARAM(
                          ": unexpected item in <component>"))),
                 css::uno::Reference< css::uno::XInterface >());
-        case STATE_IMPLEMENTATION_INITIAL:
-        case STATE_IMPLEMENTATION_SERVICE:
-        case STATE_IMPLEMENTATION_SINGLETON:
+        case STATE_IMPLEMENTATION:
             if (res == xmlreader::XmlReader::RESULT_END) {
                 state = STATE_COMPONENT;
                 break;
             }
-            if (state != STATE_IMPLEMENTATION_SINGLETON &&
-                res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
+            if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
                 name.equals(RTL_CONSTASCII_STRINGPARAM("service")))
             {
                 handleService();
                 state = STATE_SERVICE;
                 break;
             }
-            if (state != STATE_IMPLEMENTATION_INITIAL &&
-                res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
+            if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
                 name.equals(RTL_CONSTASCII_STRINGPARAM("singleton")))
             {
                 handleSingleton();
                 css::uno::Reference< css::uno::XInterface >());
         case STATE_SERVICE:
             if (res == xmlreader::XmlReader::RESULT_END) {
-                state = STATE_IMPLEMENTATION_SERVICE;
+                state = STATE_IMPLEMENTATION;
                 break;
             }
             throw css::registry::InvalidRegistryException(
                 css::uno::Reference< css::uno::XInterface >());
         case STATE_SINGLETON:
             if (res == xmlreader::XmlReader::RESULT_END) {
-                state = STATE_IMPLEMENTATION_SINGLETON;
+                state = STATE_IMPLEMENTATION;
                 break;
             }
             throw css::registry::InvalidRegistryException(
 void Parser::handleService() {
     rtl::OUString name = getNameAttribute();
     data_->implementations[attrImplementation_].services.push_back(name);
-    data_->services[name].implementations.push_back(attrImplementation_);
+    data_->services[name].push_back(attrImplementation_);
 }
 
 void Parser::handleSingleton() {
     rtl::OUString name = getNameAttribute();
     data_->implementations[attrImplementation_].singletons.push_back(name);
-    data_->singletons[name].service =
-        data_->implementations[attrImplementation_].services[0];
-    data_->singletons[name].implementations.push_back(attrImplementation_);
+    data_->singletons[name].push_back(attrImplementation_);
 }
 
 rtl::OUString Parser::getNameAttribute() {
     std::vector< rtl::OUString > const * list;
     switch (state) {
     case STATE_SERVICE:
-        list = &data_->services[path_[1]].implementations;
+        list = &data_->services[path_[1]];
         break;
     case STATE_REGISTEREDBY:
-        list = &data_->singletons[path_[1]].implementations;
+        list = &data_->singletons[path_[1]];
         break;
     default:
         throw css::registry::InvalidValueException(
     OSL_VERIFY(find(rtl::OUString(), 0, &state, 0));
     switch (state) {
     case STATE_IMPLEMENTATION_SINGLETON:
-        return data_->implementations[path_[1]].services[0];
     case STATE_SINGLETON:
-        return data_->singletons[path_[1]].service;
-    default:
-        throw css::registry::InvalidValueException(
+        throw css::registry::InvalidRegistryException(
             rtl::OUString(
                 RTL_CONSTASCII_USTRINGPARAM(
                     "com.sun.star.registry.SimpleRegistry textual services key"
-                    " getStringValue: wrong type")),
+                    " getStringValue: does not associate singletons with"
+                    " services")),
             static_cast< OWeakObject * >(this));
     }
+    // default case extracted from switch to avoid erroneous compiler warnings
+    // on Solaris:
+    throw css::registry::InvalidValueException(
+        rtl::OUString(
+            RTL_CONSTASCII_USTRINGPARAM(
+                "com.sun.star.registry.SimpleRegistry textual services key"
+                " getStringValue: wrong type")),
+        static_cast< OWeakObject * >(this));
 }
 
 void Key::setStringValue(rtl::OUString const &)
             css::uno::Sequence< rtl::OUString > seq(
                 static_cast< sal_Int32 >(data_->services.size()));
             sal_Int32 i = 0;
-            for (Services::iterator j(data_->services.begin());
+            for (ImplementationMap::iterator j(data_->services.begin());
                  j != data_->services.end(); ++j)
             {
                 seq[i++] = j->first;
             css::uno::Sequence< rtl::OUString > seq(
                 static_cast< sal_Int32 >(data_->singletons.size()));
             sal_Int32 i = 0;
-            for (Singletons::iterator j(data_->singletons.begin());
+            for (ImplementationMap::iterator j(data_->singletons.begin());
                  j != data_->singletons.end(); ++j)
             {
                 seq[i++] = j->first;