diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-09-17 16:56:19 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-09-17 16:59:53 +0200 |
commit | 543158edba6678d3d76eee983a9d4edd2a422fee (patch) | |
tree | 458133435b06afd5b50379c058a0f886fe9e82c1 /codemaker | |
parent | 6e78fd18c9ca2d70af93cad321f55f3d72172742 (diff) |
Require XComponentContext.getServiceManager to throw instead of returning null
This is such a fatal error that there is probably no point in trying to handle
it, so allow to simplify client code by removing the requirement to check for a
null return value.
Simplified some client code accordingly (modules configmgr and ure, and the code
generated by cppumaker and javamaker).
Change-Id: I51c0b270ec73409374f7439a47ee061407a46e31
Diffstat (limited to 'codemaker')
-rw-r--r-- | codemaker/source/cppumaker/cpputype.cxx | 51 | ||||
-rw-r--r-- | codemaker/source/cppumaker/includes.cxx | 6 | ||||
-rw-r--r-- | codemaker/source/cppumaker/includes.hxx | 2 | ||||
-rw-r--r-- | codemaker/source/javamaker/javatype.cxx | 71 | ||||
-rw-r--r-- | codemaker/test/javamaker/java15/Test.java | 7 |
5 files changed, 32 insertions, 105 deletions
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index b4637a9a30f6..23b0bc608596 100644 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -3872,10 +3872,10 @@ sal_Bool ServiceType::dumpHxxFile( //TODO: Decide whether the types added to includes should rather be // added to m_dependencies (and thus be generated during // dumpDependedTypes): + includes.addCassert(); includes.addReference(); includes.addRtlUstringH(); includes.addRtlUstringHxx(); - includes.add("com/sun/star/lang/XMultiComponentFactory"); includes.add("com/sun/star/uno/DeploymentException"); includes.add("com/sun/star/uno/XComponentContext"); for (sal_uInt16 i = 0; i < ctors; ++i) { @@ -3949,27 +3949,16 @@ sal_Bool ServiceType::dumpHxxFile( " ::com::sun::star::uno::XComponentContext > const &" " the_context) {\n"); inc(); - o << indent() - << ("::com::sun::star::uno::Reference<" - " ::com::sun::star::lang::XMultiComponentFactory >" - " the_factory(the_context->getServiceManager());\n") - << indent() << "if (!the_factory.is()) {\n"; - inc(); - o << indent() - << ("throw ::com::sun::star::uno::DeploymentException(" - "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\"component" - " context fails to supply service manager\"))," - " the_context);\n"); - dec(); - o << indent() << "}\n" << indent() + o << indent() << "assert(the_context.is());\n" << indent() << "::com::sun::star::uno::Reference< " << scopedBaseName << " > the_instance;\n" << indent() << "try {\n"; inc(); o << indent() << "the_instance = ::com::sun::star::uno::Reference< " << scopedBaseName - << (" >(the_factory->createInstanceWithContext(" - "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\"") + << (" >(the_context->getServiceManager()->" + "createInstanceWithContext(::rtl::OUString(" + "RTL_CONSTASCII_USTRINGPARAM(\"") << fullName << "\")), the_context), ::com::sun::star::uno::UNO_QUERY);\n"; dec(); @@ -4038,19 +4027,7 @@ sal_Bool ServiceType::dumpHxxFile( } o << ") {\n"; inc(); - o << indent() - << ("::com::sun::star::uno::Reference<" - " ::com::sun::star::lang::XMultiComponentFactory >" - " the_factory(the_context->getServiceManager());\n") - << indent() << "if (!the_factory.is()) {\n"; - inc(); - o << indent() - << ("throw com::sun::star::uno::DeploymentException(" - "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - "\"component context fails to supply service manager\"))," - " the_context);\n"); - dec(); - o << indent() << "}\n"; + o << indent() << "assert(the_context.is());\n"; if (!rest && params > 0) { o << indent() << ("::com::sun::star::uno::Sequence<" @@ -4108,8 +4085,9 @@ sal_Bool ServiceType::dumpHxxFile( o << indent() << "the_instance = ::com::sun::star::uno::Reference< " << scopedBaseName - << (" >(the_factory->createInstanceWithArgumentsAndContext(" - "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\"") + << (" >(the_context->getServiceManager()->" + "createInstanceWithArgumentsAndContext(::rtl::OUString(" + "RTL_CONSTASCII_USTRINGPARAM(\"") << fullName << "\")), "; if (rest) { o << translateUnoToCppIdentifier( @@ -4243,6 +4221,7 @@ sal_Bool SingletonType::dumpHxxFile( // m_dependencies (and thus be generated during dumpDependedTypes): includes.add("com/sun/star/uno/DeploymentException"); includes.add("com/sun/star/uno/XComponentContext"); + includes.addCassert(); includes.addAny(); includes.addReference(); includes.addRtlUstringH(); @@ -4258,11 +4237,13 @@ sal_Bool SingletonType::dumpHxxFile( << scopedBaseName << " > " << translateUnoToCppIdentifier("get", "method", ITM_NONGLOBAL, &cppName) << ("(::com::sun::star::uno::Reference<" - " ::com::sun::star::uno::XComponentContext > const & context) {\n"); + " ::com::sun::star::uno::XComponentContext > const & the_context)" + " {\n"); inc(); - o << indent() << "::com::sun::star::uno::Reference< " << scopedBaseName + o << indent() << "assert(the_context.is());\n" << indent() + << "::com::sun::star::uno::Reference< " << scopedBaseName << " > instance;\n" << indent() - << ("if (!(context->getValueByName(" + << ("if (!(the_context->getValueByName(" "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\"/singletons/") << fullName << "\"))) >>= instance) || !instance.is()) {\n"; inc(); @@ -4270,7 +4251,7 @@ sal_Bool SingletonType::dumpHxxFile( << ("throw ::com::sun::star::uno::DeploymentException(" "::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\"component context" " fails to supply singleton ") - << fullName << " of type " << fullBaseName << "\")), context);\n"; + << fullName << " of type " << fullBaseName << "\")), the_context);\n"; dec(); o << indent() << "}\n" << indent() << "return instance;\n"; dec(); diff --git a/codemaker/source/cppumaker/includes.cxx b/codemaker/source/cppumaker/includes.cxx index b6c9a63f4734..9411312eca93 100644 --- a/codemaker/source/cppumaker/includes.cxx +++ b/codemaker/source/cppumaker/includes.cxx @@ -40,7 +40,8 @@ Includes::Includes( TypeManager const & manager, codemaker::Dependencies const & dependencies, bool hpp): m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp), - m_includeAny(dependencies.hasAnyDependency()), m_includeReference(false), + m_includeCassert(false), m_includeAny(dependencies.hasAnyDependency()), + m_includeReference(false), m_includeSequence(dependencies.hasSequenceDependency()), m_includeType(dependencies.hasTypeDependency()), m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false), @@ -155,6 +156,9 @@ void Includes::dump(FileStream & out, rtl::OString const * companionHdl) { } } out << "#include \"sal/config.h\"\n"; + if (m_includeCassert) { + out << "\n#include <cassert>\n"; + } if (companionHdl) { out << "\n"; dumpInclude(out, *companionHdl, false); diff --git a/codemaker/source/cppumaker/includes.hxx b/codemaker/source/cppumaker/includes.hxx index 7913d78e5ff0..dafc659211a4 100644 --- a/codemaker/source/cppumaker/includes.hxx +++ b/codemaker/source/cppumaker/includes.hxx @@ -37,6 +37,7 @@ public: ~Includes(); void add(rtl::OString const & registryType); + void addCassert() { m_includeCassert = true; } void addAny() { m_includeAny = true; } void addReference() { m_includeReference = true; } void addSequence() { m_includeSequence = true; } @@ -72,6 +73,7 @@ private: TypeManager const & m_manager; codemaker::Dependencies::Map m_map; bool m_hpp; + bool m_includeCassert; bool m_includeAny; bool m_includeReference; bool m_includeSequence; diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 113354f22fa4..b762823ed311 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -2634,12 +2634,14 @@ void addConstructor( SAL_WNODEPRECATED_DECLARATIONS_POP code->loadLocalReference(0); // stack: context - code->instrInvokestatic( - className, rtl::OString(RTL_CONSTASCII_STRINGPARAM("$getFactory")), + code->instrInvokeinterface( + rtl::OString( + RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")), + rtl::OString(RTL_CONSTASCII_STRINGPARAM("getServiceManager")), rtl::OString( RTL_CONSTASCII_STRINGPARAM( - "(Lcom/sun/star/uno/XComponentContext;)" - "Lcom/sun/star/lang/XMultiComponentFactory;"))); + "()Lcom/sun/star/lang/XMultiComponentFactory;")), + 1); // stack: factory code->loadStringConstant(unoName); // stack: factory serviceName @@ -2905,67 +2907,6 @@ void handleService( manager, realJavaBaseName, unoName, className, reader, i, name, base, defaultCtor, dependencies, cf.get()); } - // Synthetic getFactory method: - { - SAL_WNODEPRECATED_DECLARATIONS_PUSH - std::auto_ptr< ClassFile::Code > code(cf->newCode()); - SAL_WNODEPRECATED_DECLARATIONS_POP - code->loadLocalReference(0); - // stack: context - code->instrInvokeinterface( - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "com/sun/star/uno/XComponentContext")), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("getServiceManager")), - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "()Lcom/sun/star/lang/XMultiComponentFactory;")), - 1); - // stack: factory - code->instrDup(); - // stack: factory factory - ClassFile::Code::Branch branch = code->instrIfnull(); - // stack: factory - code->instrAreturn(); - code->branchHere(branch); - code->instrPop(); - // stack: - - code->instrNew( - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "com/sun/star/uno/DeploymentException"))); - // stack: ex - code->instrDup(); - // stack: ex ex - code->loadStringConstant( - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "component context fails to supply service manager"))); - // stack: ex ex "..." - code->loadLocalReference(0); - // stack: ex ex "..." context - code->instrInvokespecial( - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "com/sun/star/uno/DeploymentException")), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")), - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "(Ljava/lang/String;Ljava/lang/Object;)V"))); - // stack: ex - code->instrAthrow(); - code->setMaxStackAndLocals(4, 1); - cf->addMethod( - static_cast< ClassFile::AccessFlags >( - ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC - | ClassFile::ACC_SYNTHETIC), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("$getFactory")), - rtl::OString( - RTL_CONSTASCII_STRINGPARAM( - "(Lcom/sun/star/uno/XComponentContext;)" - "Lcom/sun/star/lang/XMultiComponentFactory;")), - code.get(), std::vector< rtl::OString >(), rtl::OString()); - } // Synthetic castInstance method: { SAL_WNODEPRECATED_DECLARATIONS_PUSH diff --git a/codemaker/test/javamaker/java15/Test.java b/codemaker/test/javamaker/java15/Test.java index 30b9e08d68ab..40401cf010be 100644 --- a/codemaker/test/javamaker/java15/Test.java +++ b/codemaker/test/javamaker/java15/Test.java @@ -19,7 +19,6 @@ package test.codemaker.javamaker.java15; import com.sun.star.lang.XMultiComponentFactory; -import com.sun.star.uno.DeploymentException; import com.sun.star.uno.XComponentContext; import complexlib.ComplexTestCase; @@ -69,18 +68,18 @@ public final class Test extends ComplexTestCase { } public XMultiComponentFactory getServiceManager() { - return null; + throw new com.sun.star.uno.RuntimeException(); } }; try { Service.create(context); failed(); - } catch (DeploymentException e) {} + } catch (com.sun.star.uno.RuntimeException e) {} try { Service.create( context, false, (byte) 1, (short) 2, Integer.valueOf(4)); failed(); - } catch (DeploymentException e) {} + } catch (com.sun.star.uno.RuntimeException e) {} } private static final class Ifc implements XIfc { |