xref: /AOO41X/main/desktop/source/deployment/registry/component/dp_component.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "dp_component.hrc"
32*cdf0e10cSrcweir #include "dp_backend.h"
33*cdf0e10cSrcweir #include "dp_platform.hxx"
34*cdf0e10cSrcweir #include "dp_ucb.h"
35*cdf0e10cSrcweir #include "rtl/string.hxx"
36*cdf0e10cSrcweir #include "rtl/strbuf.hxx"
37*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
38*cdf0e10cSrcweir #include "rtl/uri.hxx"
39*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
40*cdf0e10cSrcweir #include "ucbhelper/content.hxx"
41*cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
42*cdf0e10cSrcweir #include "comphelper/servicedecl.hxx"
43*cdf0e10cSrcweir #include "comphelper/sequence.hxx"
44*cdf0e10cSrcweir #include "xmlscript/xml_helper.hxx"
45*cdf0e10cSrcweir #include "svl/inettype.hxx"
46*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/container/XNameContainer.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/container/XSet.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/registry/XSimpleRegistry.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/registry/XImplementationRegistration.hpp"
52*cdf0e10cSrcweir #include "com/sun/star/loader/XImplementationLoader.hpp"
53*cdf0e10cSrcweir #include "com/sun/star/io/XInputStream.hpp"
54*cdf0e10cSrcweir #include "com/sun/star/ucb/NameClash.hpp"
55*cdf0e10cSrcweir #include "com/sun/star/util/XMacroExpander.hpp"
56*cdf0e10cSrcweir #include <list>
57*cdf0e10cSrcweir #include <hash_map>
58*cdf0e10cSrcweir #include <vector>
59*cdf0e10cSrcweir #include <memory>
60*cdf0e10cSrcweir #include <algorithm>
61*cdf0e10cSrcweir #include "dp_compbackenddb.hxx"
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using namespace ::dp_misc;
64*cdf0e10cSrcweir using namespace ::com::sun::star;
65*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
66*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
67*cdf0e10cSrcweir using ::rtl::OUString;
68*cdf0e10cSrcweir namespace css = com::sun::star;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir namespace dp_registry {
71*cdf0e10cSrcweir namespace backend {
72*cdf0e10cSrcweir namespace component {
73*cdf0e10cSrcweir namespace {
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir typedef ::std::list<OUString> t_stringlist;
76*cdf0e10cSrcweir typedef ::std::vector< ::std::pair<OUString, OUString> > t_stringpairvec;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir #define IMPLEMENTATION_NAME  "com.sun.star.comp.deployment.component.PackageRegistryBackend"
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir /** return a vector of bootstrap variables which have been provided
81*cdf0e10cSrcweir     as command arguments.
82*cdf0e10cSrcweir */
83*cdf0e10cSrcweir ::std::vector<OUString> getCmdBootstrapVariables()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     ::std::vector<OUString> ret;
86*cdf0e10cSrcweir     sal_uInt32 count = osl_getCommandArgCount();
87*cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < count; i++)
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         OUString arg;
90*cdf0e10cSrcweir         osl_getCommandArg(i, &arg.pData);
91*cdf0e10cSrcweir         if (arg.matchAsciiL("-env:", 5))
92*cdf0e10cSrcweir             ret.push_back(arg);
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir     return ret;
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir bool jarManifestHeaderPresent(
98*cdf0e10cSrcweir     OUString const & url, OUString const & name,
99*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     ::rtl::OUStringBuffer buf;
102*cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip://") );
103*cdf0e10cSrcweir     buf.append(
104*cdf0e10cSrcweir         ::rtl::Uri::encode(
105*cdf0e10cSrcweir             url, rtl_UriCharClassRegName, rtl_UriEncodeIgnoreEscapes,
106*cdf0e10cSrcweir             RTL_TEXTENCODING_UTF8 ) );
107*cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/META-INF/MANIFEST.MF") );
108*cdf0e10cSrcweir     ::ucbhelper::Content manifestContent;
109*cdf0e10cSrcweir     OUString line;
110*cdf0e10cSrcweir     return
111*cdf0e10cSrcweir         create_ucb_content(
112*cdf0e10cSrcweir             &manifestContent, buf.makeStringAndClear(), xCmdEnv,
113*cdf0e10cSrcweir             false /* no throw */ )
114*cdf0e10cSrcweir         && readLine( &line, name, manifestContent, RTL_TEXTENCODING_ASCII_US );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir //==============================================================================
118*cdf0e10cSrcweir class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     class ComponentPackageImpl : public ::dp_registry::backend::Package
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         BackendImpl * getMyBackend() const;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         const OUString m_loader;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         enum reg {
127*cdf0e10cSrcweir             REG_UNINIT, REG_VOID, REG_REGISTERED, REG_NOT_REGISTERED, REG_MAYBE_REGISTERED
128*cdf0e10cSrcweir         } m_registered;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         void getComponentInfo(
131*cdf0e10cSrcweir             ComponentBackendDb::Data * data,
132*cdf0e10cSrcweir             std::vector< css::uno::Reference< css::uno::XInterface > > *
133*cdf0e10cSrcweir                 factories,
134*cdf0e10cSrcweir             Reference<XComponentContext> const & xContext );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         virtual void SAL_CALL disposing();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         // Package
139*cdf0e10cSrcweir         virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
140*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
141*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
142*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
143*cdf0e10cSrcweir         virtual void processPackage_(
144*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
145*cdf0e10cSrcweir             bool registerPackage,
146*cdf0e10cSrcweir             bool startup,
147*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
148*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         const Reference<registry::XSimpleRegistry> getRDB() const;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         //Provides the read-only registry (e.g. not the one based on the duplicated
153*cdf0e10cSrcweir         //rdb files
154*cdf0e10cSrcweir         const Reference<registry::XSimpleRegistry> getRDB_RO() const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     public:
157*cdf0e10cSrcweir         ComponentPackageImpl(
158*cdf0e10cSrcweir             ::rtl::Reference<PackageRegistryBackend> const & myBackend,
159*cdf0e10cSrcweir             OUString const & url, OUString const & name,
160*cdf0e10cSrcweir             Reference<deployment::XPackageTypeInfo> const & xPackageType,
161*cdf0e10cSrcweir             OUString const & loader, bool bRemoved,
162*cdf0e10cSrcweir             OUString const & identifier);
163*cdf0e10cSrcweir     };
164*cdf0e10cSrcweir     friend class ComponentPackageImpl;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     class ComponentsPackageImpl : public ::dp_registry::backend::Package
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir         BackendImpl * getMyBackend() const;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         // Package
171*cdf0e10cSrcweir         virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
172*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
173*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
174*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
175*cdf0e10cSrcweir         virtual void processPackage_(
176*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
177*cdf0e10cSrcweir             bool registerPackage,
178*cdf0e10cSrcweir             bool startup,
179*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
180*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
181*cdf0e10cSrcweir     public:
182*cdf0e10cSrcweir         ComponentsPackageImpl(
183*cdf0e10cSrcweir             ::rtl::Reference<PackageRegistryBackend> const & myBackend,
184*cdf0e10cSrcweir             OUString const & url, OUString const & name,
185*cdf0e10cSrcweir             Reference<deployment::XPackageTypeInfo> const & xPackageType,
186*cdf0e10cSrcweir             bool bRemoved, OUString const & identifier);
187*cdf0e10cSrcweir     };
188*cdf0e10cSrcweir     friend class ComponentsPackageImpl;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     class TypelibraryPackageImpl : public ::dp_registry::backend::Package
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         BackendImpl * getMyBackend() const;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         const bool m_jarFile;
195*cdf0e10cSrcweir         Reference<container::XHierarchicalNameAccess> m_xTDprov;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir         virtual void SAL_CALL disposing();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         // Package
200*cdf0e10cSrcweir         virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
201*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
202*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
203*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
204*cdf0e10cSrcweir         virtual void processPackage_(
205*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
206*cdf0e10cSrcweir             bool registerPackage,
207*cdf0e10cSrcweir             bool startup,
208*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
209*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     public:
212*cdf0e10cSrcweir         TypelibraryPackageImpl(
213*cdf0e10cSrcweir             ::rtl::Reference<PackageRegistryBackend> const & myBackend,
214*cdf0e10cSrcweir             OUString const & url, OUString const & name,
215*cdf0e10cSrcweir             Reference<deployment::XPackageTypeInfo> const & xPackageType,
216*cdf0e10cSrcweir             bool jarFile, bool bRemoved,
217*cdf0e10cSrcweir             OUString const & identifier);
218*cdf0e10cSrcweir     };
219*cdf0e10cSrcweir     friend class TypelibraryPackageImpl;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     t_stringlist m_jar_typelibs;
222*cdf0e10cSrcweir     t_stringlist m_rdb_typelibs;
223*cdf0e10cSrcweir     t_stringlist m_components;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     enum RcItem { RCITEM_JAR_TYPELIB, RCITEM_RDB_TYPELIB, RCITEM_COMPONENTS };
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     t_stringlist & getRcItemList( RcItem kind ) {
228*cdf0e10cSrcweir         switch (kind)
229*cdf0e10cSrcweir         {
230*cdf0e10cSrcweir         case RCITEM_JAR_TYPELIB:
231*cdf0e10cSrcweir             return m_jar_typelibs;
232*cdf0e10cSrcweir         case RCITEM_RDB_TYPELIB:
233*cdf0e10cSrcweir             return m_rdb_typelibs;
234*cdf0e10cSrcweir         default: // case RCITEM_COMPONENTS
235*cdf0e10cSrcweir             return m_components;
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     bool m_unorc_inited;
240*cdf0e10cSrcweir     bool m_unorc_modified;
241*cdf0e10cSrcweir     bool bSwitchedRdbFiles;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     typedef ::std::hash_map< OUString, Reference<XInterface>,
244*cdf0e10cSrcweir                              ::rtl::OUStringHash > t_string2object;
245*cdf0e10cSrcweir     t_string2object m_backendObjects;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     // PackageRegistryBackend
248*cdf0e10cSrcweir     virtual Reference<deployment::XPackage> bindPackage_(
249*cdf0e10cSrcweir         OUString const & url, OUString const & mediaType,
250*cdf0e10cSrcweir         sal_Bool bRemoved, OUString const & identifier,
251*cdf0e10cSrcweir         Reference<XCommandEnvironment> const & xCmdEnv );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     virtual void SAL_CALL disposing();
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xDynComponentTypeInfo;
256*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xJavaComponentTypeInfo;
257*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xPythonComponentTypeInfo;
258*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xComponentsTypeInfo;
259*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xRDBTypelibTypeInfo;
260*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xJavaTypelibTypeInfo;
261*cdf0e10cSrcweir     Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     OUString m_commonRDB;
264*cdf0e10cSrcweir     OUString m_nativeRDB;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     //URLs of the read-only rdbs (e.g. not the ones of the duplicated files)
267*cdf0e10cSrcweir     OUString m_commonRDB_RO;
268*cdf0e10cSrcweir     OUString m_nativeRDB_RO;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     std::auto_ptr<ComponentBackendDb> m_backendDb;
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     void addDataToDb(OUString const & url, ComponentBackendDb::Data const & data);
273*cdf0e10cSrcweir     ComponentBackendDb::Data readDataFromDb(OUString const & url);
274*cdf0e10cSrcweir     void revokeEntryFromDb(OUString const & url);
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     //These rdbs are for writing new service entries. The rdb files are copies
278*cdf0e10cSrcweir     //which are created when services are added or removed.
279*cdf0e10cSrcweir     Reference<registry::XSimpleRegistry> m_xCommonRDB;
280*cdf0e10cSrcweir     Reference<registry::XSimpleRegistry> m_xNativeRDB;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     //These rdbs are created on the read-only rdbs which are already used
283*cdf0e10cSrcweir     //by UNO since the startup of the current session.
284*cdf0e10cSrcweir     Reference<registry::XSimpleRegistry> m_xCommonRDB_RO;
285*cdf0e10cSrcweir     Reference<registry::XSimpleRegistry> m_xNativeRDB_RO;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     void unorc_verify_init( Reference<XCommandEnvironment> const & xCmdEnv );
289*cdf0e10cSrcweir     void unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     Reference<XInterface> getObject( OUString const & id );
292*cdf0e10cSrcweir     Reference<XInterface> insertObject(
293*cdf0e10cSrcweir         OUString const & id, Reference<XInterface> const & xObject );
294*cdf0e10cSrcweir     void releaseObject( OUString const & id );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     bool addToUnoRc( RcItem kind, OUString const & url,
297*cdf0e10cSrcweir                      Reference<XCommandEnvironment> const & xCmdEnv );
298*cdf0e10cSrcweir     bool removeFromUnoRc( RcItem kind, OUString const & url,
299*cdf0e10cSrcweir                           Reference<XCommandEnvironment> const & xCmdEnv );
300*cdf0e10cSrcweir     bool hasInUnoRc( RcItem kind, OUString const & url );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir     css::uno::Reference< css::registry::XRegistryKey > openRegistryKey(
303*cdf0e10cSrcweir         css::uno::Reference< css::registry::XRegistryKey > const & base,
304*cdf0e10cSrcweir         rtl::OUString const & path);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     void extractComponentData(
307*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & context,
308*cdf0e10cSrcweir         css::uno::Reference< css::registry::XRegistryKey > const & registry,
309*cdf0e10cSrcweir         ComponentBackendDb::Data * data,
310*cdf0e10cSrcweir         std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
311*cdf0e10cSrcweir         css::uno::Reference< css::loader::XImplementationLoader > const *
312*cdf0e10cSrcweir             componentLoader,
313*cdf0e10cSrcweir         rtl::OUString const * componentUrl);
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     void componentLiveInsertion(
316*cdf0e10cSrcweir         ComponentBackendDb::Data const & data,
317*cdf0e10cSrcweir         std::vector< css::uno::Reference< css::uno::XInterface > > const &
318*cdf0e10cSrcweir             factories);
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     void componentLiveRemoval(ComponentBackendDb::Data const & data);
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir public:
323*cdf0e10cSrcweir     BackendImpl( Sequence<Any> const & args,
324*cdf0e10cSrcweir                  Reference<XComponentContext> const & xComponentContext );
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     // XPackageRegistry
327*cdf0e10cSrcweir     virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
328*cdf0e10cSrcweir     getSupportedPackageTypes() throw (RuntimeException);
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
331*cdf0e10cSrcweir         throw (deployment::DeploymentException,
332*cdf0e10cSrcweir                uno::RuntimeException);
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     using PackageRegistryBackend::disposing;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     //Will be called from ComponentPackageImpl
337*cdf0e10cSrcweir     void initServiceRdbFiles();
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     //Creates the READ ONLY registries (m_xCommonRDB_RO,m_xNativeRDB_RO)
340*cdf0e10cSrcweir     void initServiceRdbFiles_RO();
341*cdf0e10cSrcweir };
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir //______________________________________________________________________________
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir BackendImpl::ComponentPackageImpl::ComponentPackageImpl(
346*cdf0e10cSrcweir     ::rtl::Reference<PackageRegistryBackend> const & myBackend,
347*cdf0e10cSrcweir     OUString const & url, OUString const & name,
348*cdf0e10cSrcweir     Reference<deployment::XPackageTypeInfo> const & xPackageType,
349*cdf0e10cSrcweir     OUString const & loader, bool bRemoved,
350*cdf0e10cSrcweir     OUString const & identifier)
351*cdf0e10cSrcweir     : Package( myBackend, url, name, name /* display-name */,
352*cdf0e10cSrcweir                xPackageType, bRemoved, identifier),
353*cdf0e10cSrcweir       m_loader( loader ),
354*cdf0e10cSrcweir       m_registered( REG_UNINIT )
355*cdf0e10cSrcweir {}
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir const Reference<registry::XSimpleRegistry>
358*cdf0e10cSrcweir BackendImpl::ComponentPackageImpl::getRDB() const
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     //Late "initialization" of the services rdb files
363*cdf0e10cSrcweir     //This is to prevent problems when running several
364*cdf0e10cSrcweir     //instances of OOo with root rights in parallel. This
365*cdf0e10cSrcweir     //would otherwise cause problems when copying the rdbs.
366*cdf0e10cSrcweir     //See  http://qa.openoffice.org/issues/show_bug.cgi?id=99257
367*cdf0e10cSrcweir     {
368*cdf0e10cSrcweir         const ::osl::MutexGuard guard( getMutex() );
369*cdf0e10cSrcweir         if (!that->bSwitchedRdbFiles)
370*cdf0e10cSrcweir         {
371*cdf0e10cSrcweir             that->bSwitchedRdbFiles = true;
372*cdf0e10cSrcweir             that->initServiceRdbFiles();
373*cdf0e10cSrcweir         }
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir     if (m_loader.equalsAsciiL(
376*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.SharedLibrary") ))
377*cdf0e10cSrcweir         return that->m_xNativeRDB;
378*cdf0e10cSrcweir     else
379*cdf0e10cSrcweir         return that->m_xCommonRDB;
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir //Returns the read only RDB.
383*cdf0e10cSrcweir const Reference<registry::XSimpleRegistry>
384*cdf0e10cSrcweir BackendImpl::ComponentPackageImpl::getRDB_RO() const
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     if (m_loader.equalsAsciiL(
389*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.SharedLibrary") ))
390*cdf0e10cSrcweir         return that->m_xNativeRDB_RO;
391*cdf0e10cSrcweir     else
392*cdf0e10cSrcweir         return that->m_xCommonRDB_RO;
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend() const
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir     BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
398*cdf0e10cSrcweir     if (NULL == pBackend)
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         //Throws a DisposedException
401*cdf0e10cSrcweir         check();
402*cdf0e10cSrcweir         //We should never get here...
403*cdf0e10cSrcweir         throw RuntimeException(
404*cdf0e10cSrcweir             OUSTR("Failed to get the BackendImpl"),
405*cdf0e10cSrcweir             static_cast<OWeakObject*>(const_cast<ComponentPackageImpl *>(this)));
406*cdf0e10cSrcweir     }
407*cdf0e10cSrcweir     return pBackend;
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir //______________________________________________________________________________
412*cdf0e10cSrcweir void BackendImpl::ComponentPackageImpl::disposing()
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir //    m_xRemoteContext.clear();
415*cdf0e10cSrcweir     Package::disposing();
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //______________________________________________________________________________
419*cdf0e10cSrcweir void BackendImpl::TypelibraryPackageImpl::disposing()
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir     m_xTDprov.clear();
422*cdf0e10cSrcweir     Package::disposing();
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir //______________________________________________________________________________
426*cdf0e10cSrcweir void BackendImpl::disposing()
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     try {
429*cdf0e10cSrcweir         m_backendObjects = t_string2object();
430*cdf0e10cSrcweir         if (m_xNativeRDB.is()) {
431*cdf0e10cSrcweir             m_xNativeRDB->close();
432*cdf0e10cSrcweir             m_xNativeRDB.clear();
433*cdf0e10cSrcweir         }
434*cdf0e10cSrcweir         if (m_xCommonRDB.is()) {
435*cdf0e10cSrcweir             m_xCommonRDB->close();
436*cdf0e10cSrcweir             m_xCommonRDB.clear();
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir         unorc_flush( Reference<XCommandEnvironment>() );
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         PackageRegistryBackend::disposing();
441*cdf0e10cSrcweir     }
442*cdf0e10cSrcweir     catch (RuntimeException &) {
443*cdf0e10cSrcweir         throw;
444*cdf0e10cSrcweir     }
445*cdf0e10cSrcweir     catch (Exception &) {
446*cdf0e10cSrcweir         Any exc( ::cppu::getCaughtException() );
447*cdf0e10cSrcweir         throw lang::WrappedTargetRuntimeException(
448*cdf0e10cSrcweir             OUSTR("caught unexpected exception while disposing..."),
449*cdf0e10cSrcweir             static_cast<OWeakObject *>(this), exc );
450*cdf0e10cSrcweir     }
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir void BackendImpl::initServiceRdbFiles()
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir     const Reference<XCommandEnvironment> xCmdEnv;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     ::ucbhelper::Content cacheDir( getCachePath(), xCmdEnv );
459*cdf0e10cSrcweir     ::ucbhelper::Content oldRDB;
460*cdf0e10cSrcweir     // switch common rdb:
461*cdf0e10cSrcweir     if (m_commonRDB_RO.getLength() > 0)
462*cdf0e10cSrcweir     {
463*cdf0e10cSrcweir         create_ucb_content(
464*cdf0e10cSrcweir             &oldRDB, makeURL( getCachePath(), m_commonRDB_RO),
465*cdf0e10cSrcweir             xCmdEnv, false /* no throw */ );
466*cdf0e10cSrcweir     }
467*cdf0e10cSrcweir     m_commonRDB = m_commonRDB_RO.equalsAsciiL(
468*cdf0e10cSrcweir         RTL_CONSTASCII_STRINGPARAM("common.rdb") )
469*cdf0e10cSrcweir         ? OUSTR("common_.rdb") : OUSTR("common.rdb");
470*cdf0e10cSrcweir     if (oldRDB.get().is())
471*cdf0e10cSrcweir     {
472*cdf0e10cSrcweir         if (! cacheDir.transferContent(
473*cdf0e10cSrcweir                 oldRDB, ::ucbhelper::InsertOperation_COPY,
474*cdf0e10cSrcweir                 m_commonRDB, NameClash::OVERWRITE ))
475*cdf0e10cSrcweir         {
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir             throw RuntimeException(
478*cdf0e10cSrcweir                 OUSTR("UCB transferContent() failed!"), 0 );
479*cdf0e10cSrcweir         }
480*cdf0e10cSrcweir         oldRDB = ::ucbhelper::Content();
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir     // switch native rdb:
483*cdf0e10cSrcweir     if (m_nativeRDB_RO.getLength() > 0)
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         create_ucb_content(
486*cdf0e10cSrcweir             &oldRDB, makeURL(getCachePath(), m_nativeRDB_RO),
487*cdf0e10cSrcweir             xCmdEnv, false /* no throw */ );
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir     const OUString plt_rdb( getPlatformString() + OUSTR(".rdb") );
490*cdf0e10cSrcweir     const OUString plt_rdb_( getPlatformString() + OUSTR("_.rdb") );
491*cdf0e10cSrcweir     m_nativeRDB = m_nativeRDB_RO.equals( plt_rdb ) ? plt_rdb_ : plt_rdb;
492*cdf0e10cSrcweir     if (oldRDB.get().is())
493*cdf0e10cSrcweir     {
494*cdf0e10cSrcweir         if (! cacheDir.transferContent(
495*cdf0e10cSrcweir                 oldRDB, ::ucbhelper::InsertOperation_COPY,
496*cdf0e10cSrcweir                 m_nativeRDB, NameClash::OVERWRITE ))
497*cdf0e10cSrcweir             throw RuntimeException(
498*cdf0e10cSrcweir                 OUSTR("UCB transferContent() failed!"), 0 );
499*cdf0e10cSrcweir     }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     // UNO is bootstrapped, flush for next process start:
502*cdf0e10cSrcweir     m_unorc_modified = true;
503*cdf0e10cSrcweir     unorc_flush( Reference<XCommandEnvironment>() );
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     // common rdb for java, native rdb for shared lib components
507*cdf0e10cSrcweir     if (m_commonRDB.getLength() > 0) {
508*cdf0e10cSrcweir         m_xCommonRDB.set(
509*cdf0e10cSrcweir             m_xComponentContext->getServiceManager()
510*cdf0e10cSrcweir             ->createInstanceWithContext(
511*cdf0e10cSrcweir             OUSTR("com.sun.star.registry.SimpleRegistry"),
512*cdf0e10cSrcweir             m_xComponentContext ), UNO_QUERY_THROW );
513*cdf0e10cSrcweir         m_xCommonRDB->open(
514*cdf0e10cSrcweir             makeURL( expandUnoRcUrl(getCachePath()), m_commonRDB ),
515*cdf0e10cSrcweir //            m_readOnly, !m_readOnly );
516*cdf0e10cSrcweir             false, true);
517*cdf0e10cSrcweir     }
518*cdf0e10cSrcweir     if (m_nativeRDB.getLength() > 0) {
519*cdf0e10cSrcweir         m_xNativeRDB.set(
520*cdf0e10cSrcweir             m_xComponentContext->getServiceManager()
521*cdf0e10cSrcweir             ->createInstanceWithContext(
522*cdf0e10cSrcweir             OUSTR("com.sun.star.registry.SimpleRegistry"),
523*cdf0e10cSrcweir             m_xComponentContext ), UNO_QUERY_THROW );
524*cdf0e10cSrcweir         m_xNativeRDB->open(
525*cdf0e10cSrcweir             makeURL( expandUnoRcUrl(getCachePath()), m_nativeRDB ),
526*cdf0e10cSrcweir //            m_readOnly, !m_readOnly );
527*cdf0e10cSrcweir             false, true);
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir void BackendImpl::initServiceRdbFiles_RO()
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir     const Reference<XCommandEnvironment> xCmdEnv;
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir     // common rdb for java, native rdb for shared lib components
536*cdf0e10cSrcweir     if (m_commonRDB_RO.getLength() > 0)
537*cdf0e10cSrcweir     {
538*cdf0e10cSrcweir         m_xCommonRDB_RO.set(
539*cdf0e10cSrcweir             m_xComponentContext->getServiceManager()
540*cdf0e10cSrcweir             ->createInstanceWithContext(
541*cdf0e10cSrcweir             OUSTR("com.sun.star.registry.SimpleRegistry"),
542*cdf0e10cSrcweir             m_xComponentContext), UNO_QUERY_THROW);
543*cdf0e10cSrcweir         m_xCommonRDB_RO->open(
544*cdf0e10cSrcweir             makeURL(expandUnoRcUrl(getCachePath()), m_commonRDB_RO),
545*cdf0e10cSrcweir             sal_True, //read-only
546*cdf0e10cSrcweir             sal_True); // create data source if necessary
547*cdf0e10cSrcweir     }
548*cdf0e10cSrcweir     if (m_nativeRDB_RO.getLength() > 0)
549*cdf0e10cSrcweir     {
550*cdf0e10cSrcweir         m_xNativeRDB_RO.set(
551*cdf0e10cSrcweir             m_xComponentContext->getServiceManager()
552*cdf0e10cSrcweir             ->createInstanceWithContext(
553*cdf0e10cSrcweir             OUSTR("com.sun.star.registry.SimpleRegistry"),
554*cdf0e10cSrcweir             m_xComponentContext), UNO_QUERY_THROW);
555*cdf0e10cSrcweir         m_xNativeRDB_RO->open(
556*cdf0e10cSrcweir             makeURL(expandUnoRcUrl(getCachePath()), m_nativeRDB_RO),
557*cdf0e10cSrcweir             sal_True, //read-only
558*cdf0e10cSrcweir             sal_True); // create data source if necessary
559*cdf0e10cSrcweir     }
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir //______________________________________________________________________________
563*cdf0e10cSrcweir BackendImpl::BackendImpl(
564*cdf0e10cSrcweir     Sequence<Any> const & args,
565*cdf0e10cSrcweir     Reference<XComponentContext> const & xComponentContext )
566*cdf0e10cSrcweir     : PackageRegistryBackend( args, xComponentContext ),
567*cdf0e10cSrcweir       m_unorc_inited( false ),
568*cdf0e10cSrcweir       m_unorc_modified( false ),
569*cdf0e10cSrcweir       bSwitchedRdbFiles(false),
570*cdf0e10cSrcweir       m_xDynComponentTypeInfo( new Package::TypeInfo(
571*cdf0e10cSrcweir                                    OUSTR("application/"
572*cdf0e10cSrcweir                                          "vnd.sun.star.uno-component;"
573*cdf0e10cSrcweir                                          "type=native;platform=") +
574*cdf0e10cSrcweir                                    getPlatformString(),
575*cdf0e10cSrcweir                                    OUSTR("*" SAL_DLLEXTENSION),
576*cdf0e10cSrcweir                                    getResourceString(RID_STR_DYN_COMPONENT),
577*cdf0e10cSrcweir                                    RID_IMG_COMPONENT,
578*cdf0e10cSrcweir                                    RID_IMG_COMPONENT_HC ) ),
579*cdf0e10cSrcweir       m_xJavaComponentTypeInfo( new Package::TypeInfo(
580*cdf0e10cSrcweir                                     OUSTR("application/"
581*cdf0e10cSrcweir                                           "vnd.sun.star.uno-component;"
582*cdf0e10cSrcweir                                           "type=Java"),
583*cdf0e10cSrcweir                                     OUSTR("*.jar"),
584*cdf0e10cSrcweir                                     getResourceString(RID_STR_JAVA_COMPONENT),
585*cdf0e10cSrcweir                                     RID_IMG_JAVA_COMPONENT,
586*cdf0e10cSrcweir                                     RID_IMG_JAVA_COMPONENT_HC ) ),
587*cdf0e10cSrcweir       m_xPythonComponentTypeInfo( new Package::TypeInfo(
588*cdf0e10cSrcweir                                       OUSTR("application/"
589*cdf0e10cSrcweir                                             "vnd.sun.star.uno-component;"
590*cdf0e10cSrcweir                                             "type=Python"),
591*cdf0e10cSrcweir                                       OUSTR("*.py"),
592*cdf0e10cSrcweir                                       getResourceString(
593*cdf0e10cSrcweir                                           RID_STR_PYTHON_COMPONENT),
594*cdf0e10cSrcweir                                       RID_IMG_COMPONENT,
595*cdf0e10cSrcweir                                       RID_IMG_COMPONENT_HC ) ),
596*cdf0e10cSrcweir       m_xComponentsTypeInfo( new Package::TypeInfo(
597*cdf0e10cSrcweir                                  OUSTR("application/"
598*cdf0e10cSrcweir                                        "vnd.sun.star.uno-components"),
599*cdf0e10cSrcweir                                  OUSTR("*.components"),
600*cdf0e10cSrcweir                                  getResourceString(RID_STR_COMPONENTS),
601*cdf0e10cSrcweir                                  RID_IMG_COMPONENT,
602*cdf0e10cSrcweir                                  RID_IMG_COMPONENT_HC ) ),
603*cdf0e10cSrcweir       m_xRDBTypelibTypeInfo( new Package::TypeInfo(
604*cdf0e10cSrcweir                                  OUSTR("application/"
605*cdf0e10cSrcweir                                        "vnd.sun.star.uno-typelibrary;"
606*cdf0e10cSrcweir                                        "type=RDB"),
607*cdf0e10cSrcweir                                  OUSTR("*.rdb"),
608*cdf0e10cSrcweir                                  getResourceString(RID_STR_RDB_TYPELIB),
609*cdf0e10cSrcweir                                  RID_IMG_TYPELIB, RID_IMG_TYPELIB_HC ) ),
610*cdf0e10cSrcweir       m_xJavaTypelibTypeInfo( new Package::TypeInfo(
611*cdf0e10cSrcweir                                   OUSTR("application/"
612*cdf0e10cSrcweir                                         "vnd.sun.star.uno-typelibrary;"
613*cdf0e10cSrcweir                                         "type=Java"),
614*cdf0e10cSrcweir                                   OUSTR("*.jar"),
615*cdf0e10cSrcweir                                   getResourceString(RID_STR_JAVA_TYPELIB),
616*cdf0e10cSrcweir                                   RID_IMG_JAVA_TYPELIB,
617*cdf0e10cSrcweir                                   RID_IMG_JAVA_TYPELIB_HC ) ),
618*cdf0e10cSrcweir       m_typeInfos( 6 )
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir     m_typeInfos[ 0 ] = m_xDynComponentTypeInfo;
621*cdf0e10cSrcweir     m_typeInfos[ 1 ] = m_xJavaComponentTypeInfo;
622*cdf0e10cSrcweir     m_typeInfos[ 2 ] = m_xPythonComponentTypeInfo;
623*cdf0e10cSrcweir     m_typeInfos[ 3 ] = m_xComponentsTypeInfo;
624*cdf0e10cSrcweir     m_typeInfos[ 4 ] = m_xRDBTypelibTypeInfo;
625*cdf0e10cSrcweir     m_typeInfos[ 5 ] = m_xJavaTypelibTypeInfo;
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir     const Reference<XCommandEnvironment> xCmdEnv;
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir     if (transientMode())
630*cdf0e10cSrcweir     {
631*cdf0e10cSrcweir         // in-mem rdbs:
632*cdf0e10cSrcweir         // common rdb for java, native rdb for shared lib components
633*cdf0e10cSrcweir         m_xCommonRDB.set(
634*cdf0e10cSrcweir             xComponentContext->getServiceManager()->createInstanceWithContext(
635*cdf0e10cSrcweir                 OUSTR("com.sun.star.registry.SimpleRegistry"),
636*cdf0e10cSrcweir                 xComponentContext ), UNO_QUERY_THROW );
637*cdf0e10cSrcweir         m_xCommonRDB->open( OUString() /* in-mem */,
638*cdf0e10cSrcweir                             false /* ! read-only */, true /* create */ );
639*cdf0e10cSrcweir         m_xNativeRDB.set(
640*cdf0e10cSrcweir             xComponentContext->getServiceManager()->createInstanceWithContext(
641*cdf0e10cSrcweir                 OUSTR("com.sun.star.registry.SimpleRegistry"),
642*cdf0e10cSrcweir                 xComponentContext ), UNO_QUERY_THROW );
643*cdf0e10cSrcweir         m_xNativeRDB->open( OUString() /* in-mem */,
644*cdf0e10cSrcweir                             false /* ! read-only */, true /* create */ );
645*cdf0e10cSrcweir     }
646*cdf0e10cSrcweir     else
647*cdf0e10cSrcweir     {
648*cdf0e10cSrcweir         //do this before initServiceRdbFiles_RO, because it determines
649*cdf0e10cSrcweir         //m_commonRDB and m_nativeRDB
650*cdf0e10cSrcweir         unorc_verify_init( xCmdEnv );
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir         initServiceRdbFiles_RO();
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir         OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml"));
655*cdf0e10cSrcweir         m_backendDb.reset(
656*cdf0e10cSrcweir             new ComponentBackendDb(getComponentContext(), dbFile));
657*cdf0e10cSrcweir     }
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir void BackendImpl::addDataToDb(
661*cdf0e10cSrcweir     OUString const & url, ComponentBackendDb::Data const & data)
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir     if (m_backendDb.get())
664*cdf0e10cSrcweir         m_backendDb->addEntry(url, data);
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir ComponentBackendDb::Data BackendImpl::readDataFromDb(OUString const & url)
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir     ComponentBackendDb::Data data;
670*cdf0e10cSrcweir     if (m_backendDb.get())
671*cdf0e10cSrcweir         data = m_backendDb->getEntry(url);
672*cdf0e10cSrcweir     return data;
673*cdf0e10cSrcweir }
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir void BackendImpl::revokeEntryFromDb(OUString const & url)
676*cdf0e10cSrcweir {
677*cdf0e10cSrcweir     if (m_backendDb.get())
678*cdf0e10cSrcweir         m_backendDb->revokeEntry(url);
679*cdf0e10cSrcweir }
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir // XPackageRegistry
682*cdf0e10cSrcweir //______________________________________________________________________________
683*cdf0e10cSrcweir Sequence< Reference<deployment::XPackageTypeInfo> >
684*cdf0e10cSrcweir BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
685*cdf0e10cSrcweir {
686*cdf0e10cSrcweir     return m_typeInfos;
687*cdf0e10cSrcweir }
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
690*cdf0e10cSrcweir         throw (deployment::DeploymentException,
691*cdf0e10cSrcweir                uno::RuntimeException)
692*cdf0e10cSrcweir {
693*cdf0e10cSrcweir     if (m_backendDb.get())
694*cdf0e10cSrcweir         m_backendDb->removeEntry(url);
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir // PackageRegistryBackend
698*cdf0e10cSrcweir //______________________________________________________________________________
699*cdf0e10cSrcweir Reference<deployment::XPackage> BackendImpl::bindPackage_(
700*cdf0e10cSrcweir     OUString const & url, OUString const & mediaType_,
701*cdf0e10cSrcweir     sal_Bool bRemoved, OUString const & identifier,
702*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
703*cdf0e10cSrcweir {
704*cdf0e10cSrcweir     OUString mediaType(mediaType_);
705*cdf0e10cSrcweir     if (mediaType.getLength() == 0 ||
706*cdf0e10cSrcweir         mediaType.equalsAsciiL(
707*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM(
708*cdf0e10cSrcweir                 "application/vnd.sun.star.uno-component") ) ||
709*cdf0e10cSrcweir         mediaType.equalsAsciiL(
710*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM(
711*cdf0e10cSrcweir                 "application/vnd.sun.star.uno-typelibrary") ))
712*cdf0e10cSrcweir     {
713*cdf0e10cSrcweir         // detect exact media-type:
714*cdf0e10cSrcweir         ::ucbhelper::Content ucbContent;
715*cdf0e10cSrcweir         if (create_ucb_content( &ucbContent, url, xCmdEnv )) {
716*cdf0e10cSrcweir             const OUString title( ucbContent.getPropertyValue(
717*cdf0e10cSrcweir                                       StrTitle::get() ).get<OUString>() );
718*cdf0e10cSrcweir             if (title.endsWithIgnoreAsciiCaseAsciiL(
719*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM(SAL_DLLEXTENSION) ))
720*cdf0e10cSrcweir             {
721*cdf0e10cSrcweir                 mediaType = OUSTR("application/vnd.sun.star.uno-component;"
722*cdf0e10cSrcweir                                   "type=native;platform=") +
723*cdf0e10cSrcweir                     getPlatformString();
724*cdf0e10cSrcweir             }
725*cdf0e10cSrcweir             else if (title.endsWithIgnoreAsciiCaseAsciiL(
726*cdf0e10cSrcweir                          RTL_CONSTASCII_STRINGPARAM(".jar") ))
727*cdf0e10cSrcweir             {
728*cdf0e10cSrcweir                 if (jarManifestHeaderPresent(
729*cdf0e10cSrcweir                         url, OUSTR("RegistrationClassName"), xCmdEnv ))
730*cdf0e10cSrcweir                     mediaType = OUSTR(
731*cdf0e10cSrcweir                         "application/vnd.sun.star.uno-component;type=Java");
732*cdf0e10cSrcweir                 if (mediaType.getLength() == 0)
733*cdf0e10cSrcweir                     mediaType = OUSTR(
734*cdf0e10cSrcweir                         "application/vnd.sun.star.uno-typelibrary;type=Java");
735*cdf0e10cSrcweir             }
736*cdf0e10cSrcweir             else if (title.endsWithIgnoreAsciiCaseAsciiL(
737*cdf0e10cSrcweir                          RTL_CONSTASCII_STRINGPARAM(".py") ))
738*cdf0e10cSrcweir                 mediaType =
739*cdf0e10cSrcweir                     OUSTR("application/vnd.sun.star.uno-component;type=Python");
740*cdf0e10cSrcweir             else if (title.endsWithIgnoreAsciiCaseAsciiL(
741*cdf0e10cSrcweir                          RTL_CONSTASCII_STRINGPARAM(".rdb") ))
742*cdf0e10cSrcweir                 mediaType =
743*cdf0e10cSrcweir                     OUSTR("application/vnd.sun.star.uno-typelibrary;type=RDB");
744*cdf0e10cSrcweir         }
745*cdf0e10cSrcweir         if (mediaType.getLength() == 0)
746*cdf0e10cSrcweir             throw lang::IllegalArgumentException(
747*cdf0e10cSrcweir                 StrCannotDetectMediaType::get() + url,
748*cdf0e10cSrcweir                 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
749*cdf0e10cSrcweir     }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     String type, subType;
752*cdf0e10cSrcweir     INetContentTypeParameterList params;
753*cdf0e10cSrcweir     if (INetContentTypes::parse( mediaType, type, subType, &params ))
754*cdf0e10cSrcweir     {
755*cdf0e10cSrcweir         if (type.EqualsIgnoreCaseAscii("application"))
756*cdf0e10cSrcweir         {
757*cdf0e10cSrcweir             OUString name;
758*cdf0e10cSrcweir             if (!bRemoved)
759*cdf0e10cSrcweir             {
760*cdf0e10cSrcweir                 ::ucbhelper::Content ucbContent( url, xCmdEnv );
761*cdf0e10cSrcweir                 name = ucbContent.getPropertyValue(
762*cdf0e10cSrcweir                     StrTitle::get() ).get<OUString>();
763*cdf0e10cSrcweir             }
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir             if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.uno-component"))
766*cdf0e10cSrcweir             {
767*cdf0e10cSrcweir                 // xxx todo: probe and evaluate component xml description
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir                 INetContentTypeParameter const * param = params.find(
770*cdf0e10cSrcweir                     ByteString("platform") );
771*cdf0e10cSrcweir                 if (param == 0 || platform_fits( param->m_sValue )) {
772*cdf0e10cSrcweir                     param = params.find( ByteString("type") );
773*cdf0e10cSrcweir                     if (param != 0)
774*cdf0e10cSrcweir                     {
775*cdf0e10cSrcweir                         String const & value = param->m_sValue;
776*cdf0e10cSrcweir                         if (value.EqualsIgnoreCaseAscii("native")) {
777*cdf0e10cSrcweir                             return new BackendImpl::ComponentPackageImpl(
778*cdf0e10cSrcweir                                 this, url, name, m_xDynComponentTypeInfo,
779*cdf0e10cSrcweir                                 OUSTR("com.sun.star.loader.SharedLibrary"),
780*cdf0e10cSrcweir                                 bRemoved, identifier);
781*cdf0e10cSrcweir                         }
782*cdf0e10cSrcweir                         if (value.EqualsIgnoreCaseAscii("Java")) {
783*cdf0e10cSrcweir                             return new BackendImpl::ComponentPackageImpl(
784*cdf0e10cSrcweir                                 this, url, name, m_xJavaComponentTypeInfo,
785*cdf0e10cSrcweir                                 OUSTR("com.sun.star.loader.Java2"),
786*cdf0e10cSrcweir                                 bRemoved, identifier);
787*cdf0e10cSrcweir                         }
788*cdf0e10cSrcweir                         if (value.EqualsIgnoreCaseAscii("Python")) {
789*cdf0e10cSrcweir                             return new BackendImpl::ComponentPackageImpl(
790*cdf0e10cSrcweir                                 this, url, name, m_xPythonComponentTypeInfo,
791*cdf0e10cSrcweir                                 OUSTR("com.sun.star.loader.Python"),
792*cdf0e10cSrcweir                                 bRemoved, identifier);
793*cdf0e10cSrcweir                         }
794*cdf0e10cSrcweir                     }
795*cdf0e10cSrcweir                 }
796*cdf0e10cSrcweir             }
797*cdf0e10cSrcweir             else if (subType.EqualsIgnoreCaseAscii(
798*cdf0e10cSrcweir                          "vnd.sun.star.uno-components"))
799*cdf0e10cSrcweir             {
800*cdf0e10cSrcweir                 INetContentTypeParameter const * param = params.find(
801*cdf0e10cSrcweir                     ByteString("platform") );
802*cdf0e10cSrcweir                 if (param == 0 || platform_fits( param->m_sValue )) {
803*cdf0e10cSrcweir                     return new BackendImpl::ComponentsPackageImpl(
804*cdf0e10cSrcweir                         this, url, name, m_xComponentsTypeInfo, bRemoved,
805*cdf0e10cSrcweir                         identifier);
806*cdf0e10cSrcweir                 }
807*cdf0e10cSrcweir             }
808*cdf0e10cSrcweir             else if (subType.EqualsIgnoreCaseAscii(
809*cdf0e10cSrcweir                          "vnd.sun.star.uno-typelibrary"))
810*cdf0e10cSrcweir             {
811*cdf0e10cSrcweir                 INetContentTypeParameter const * param = params.find(
812*cdf0e10cSrcweir                     ByteString("type") );
813*cdf0e10cSrcweir                 if (param != 0) {
814*cdf0e10cSrcweir                     String const & value = param->m_sValue;
815*cdf0e10cSrcweir                     if (value.EqualsIgnoreCaseAscii("RDB"))
816*cdf0e10cSrcweir                     {
817*cdf0e10cSrcweir                         return new BackendImpl::TypelibraryPackageImpl(
818*cdf0e10cSrcweir                             this, url, name, m_xRDBTypelibTypeInfo,
819*cdf0e10cSrcweir                             false /* rdb */, bRemoved, identifier);
820*cdf0e10cSrcweir                     }
821*cdf0e10cSrcweir                     if (value.EqualsIgnoreCaseAscii("Java")) {
822*cdf0e10cSrcweir                         return new BackendImpl::TypelibraryPackageImpl(
823*cdf0e10cSrcweir                             this, url, name, m_xJavaTypelibTypeInfo,
824*cdf0e10cSrcweir                             true /* jar */, bRemoved, identifier);
825*cdf0e10cSrcweir                     }
826*cdf0e10cSrcweir                 }
827*cdf0e10cSrcweir             }
828*cdf0e10cSrcweir         }
829*cdf0e10cSrcweir     }
830*cdf0e10cSrcweir     throw lang::IllegalArgumentException(
831*cdf0e10cSrcweir         StrUnsupportedMediaType::get() + mediaType,
832*cdf0e10cSrcweir         static_cast<OWeakObject *>(this),
833*cdf0e10cSrcweir         static_cast<sal_Int16>(-1) );
834*cdf0e10cSrcweir }
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir //##############################################################################
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir //______________________________________________________________________________
839*cdf0e10cSrcweir void BackendImpl::unorc_verify_init(
840*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
841*cdf0e10cSrcweir {
842*cdf0e10cSrcweir     if (transientMode())
843*cdf0e10cSrcweir         return;
844*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
845*cdf0e10cSrcweir     if (! m_unorc_inited)
846*cdf0e10cSrcweir     {
847*cdf0e10cSrcweir         // common rc:
848*cdf0e10cSrcweir         ::ucbhelper::Content ucb_content;
849*cdf0e10cSrcweir         if (create_ucb_content(
850*cdf0e10cSrcweir                 &ucb_content,
851*cdf0e10cSrcweir                 makeURL( getCachePath(), OUSTR("unorc") ),
852*cdf0e10cSrcweir                 xCmdEnv, false /* no throw */ ))
853*cdf0e10cSrcweir         {
854*cdf0e10cSrcweir             OUString line;
855*cdf0e10cSrcweir             if (readLine( &line, OUSTR("UNO_JAVA_CLASSPATH="), ucb_content,
856*cdf0e10cSrcweir                           RTL_TEXTENCODING_UTF8 ))
857*cdf0e10cSrcweir             {
858*cdf0e10cSrcweir                 sal_Int32 index = sizeof ("UNO_JAVA_CLASSPATH=") - 1;
859*cdf0e10cSrcweir                 do {
860*cdf0e10cSrcweir                     OUString token( line.getToken( 0, ' ', index ).trim() );
861*cdf0e10cSrcweir                     if (token.getLength() > 0)
862*cdf0e10cSrcweir                     {
863*cdf0e10cSrcweir                         if (create_ucb_content(
864*cdf0e10cSrcweir                                 0, expandUnoRcTerm(token), xCmdEnv,
865*cdf0e10cSrcweir                                 false /* no throw */ ))
866*cdf0e10cSrcweir                         {
867*cdf0e10cSrcweir                             //The jar file may not exist anymore if a shared or bundled
868*cdf0e10cSrcweir                             //extension was removed, but it can still be in the unorc
869*cdf0e10cSrcweir                             //After running XExtensionManager::synchronize, the unorc is
870*cdf0e10cSrcweir                             //cleaned up
871*cdf0e10cSrcweir                             m_jar_typelibs.push_back( token );
872*cdf0e10cSrcweir                         }
873*cdf0e10cSrcweir                     }
874*cdf0e10cSrcweir                 }
875*cdf0e10cSrcweir                 while (index >= 0);
876*cdf0e10cSrcweir             }
877*cdf0e10cSrcweir             if (readLine( &line, OUSTR("UNO_TYPES="), ucb_content,
878*cdf0e10cSrcweir                           RTL_TEXTENCODING_UTF8 )) {
879*cdf0e10cSrcweir                 sal_Int32 index = sizeof ("UNO_TYPES=") - 1;
880*cdf0e10cSrcweir                 do {
881*cdf0e10cSrcweir                     OUString token( line.getToken( 0, ' ', index ).trim() );
882*cdf0e10cSrcweir                     if (token.getLength() > 0)
883*cdf0e10cSrcweir                     {
884*cdf0e10cSrcweir                         if (token[ 0 ] == '?')
885*cdf0e10cSrcweir                             token = token.copy( 1 );
886*cdf0e10cSrcweir                          if (create_ucb_content(
887*cdf0e10cSrcweir                                 0, expandUnoRcTerm(token), xCmdEnv,
888*cdf0e10cSrcweir                                 false /* no throw */ ))
889*cdf0e10cSrcweir                          {
890*cdf0e10cSrcweir                              //The RDB file may not exist anymore if a shared or bundled
891*cdf0e10cSrcweir                              //extension was removed, but it can still be in the unorc.
892*cdf0e10cSrcweir                              //After running XExtensionManager::synchronize, the unorc is
893*cdf0e10cSrcweir                              //cleaned up
894*cdf0e10cSrcweir                              m_rdb_typelibs.push_back( token );
895*cdf0e10cSrcweir                          }
896*cdf0e10cSrcweir                     }
897*cdf0e10cSrcweir                 }
898*cdf0e10cSrcweir                 while (index >= 0);
899*cdf0e10cSrcweir             }
900*cdf0e10cSrcweir             if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
901*cdf0e10cSrcweir                           RTL_TEXTENCODING_UTF8 ))
902*cdf0e10cSrcweir             {
903*cdf0e10cSrcweir                 // The UNO_SERVICES line always has the BNF form
904*cdf0e10cSrcweir                 //  "UNO_SERVICES="
905*cdf0e10cSrcweir                 //  ("?$ORIGIN/" <common-rdb>)?                        -- first
906*cdf0e10cSrcweir                 //  "${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}"?       -- second
907*cdf0e10cSrcweir                 //  ("?" ("BUNDLED_EXTENSIONS" |                       -- third
908*cdf0e10cSrcweir                 //   "UNO_SHARED_PACKAGES_CACHE" | "UNO_USER_PACKAGES_CACHE")
909*cdf0e10cSrcweir                 //   ...)*
910*cdf0e10cSrcweir                 // so can unambiguously be split into its thre parts:
911*cdf0e10cSrcweir                 int state = 1;
912*cdf0e10cSrcweir                 for (sal_Int32 i = RTL_CONSTASCII_LENGTH("UNO_SERVICES=");
913*cdf0e10cSrcweir                      i >= 0;)
914*cdf0e10cSrcweir                 {
915*cdf0e10cSrcweir                     rtl::OUString token(line.getToken(0, ' ', i));
916*cdf0e10cSrcweir                     if (token.getLength() != 0)
917*cdf0e10cSrcweir                     {
918*cdf0e10cSrcweir                         if (state == 1 &&
919*cdf0e10cSrcweir                             token.matchAsciiL(
920*cdf0e10cSrcweir                                 RTL_CONSTASCII_STRINGPARAM("?$ORIGIN/")))
921*cdf0e10cSrcweir                         {
922*cdf0e10cSrcweir                             m_commonRDB_RO = token.copy(
923*cdf0e10cSrcweir                                 RTL_CONSTASCII_LENGTH("?$ORIGIN/"));
924*cdf0e10cSrcweir                             state = 2;
925*cdf0e10cSrcweir                         }
926*cdf0e10cSrcweir                         else if (state <= 2 &&
927*cdf0e10cSrcweir                                  token.equalsAsciiL(
928*cdf0e10cSrcweir                                      RTL_CONSTASCII_STRINGPARAM(
929*cdf0e10cSrcweir                                          "${$ORIGIN/${_OS}_${_ARCH}rc:"
930*cdf0e10cSrcweir                                          "UNO_SERVICES}")))
931*cdf0e10cSrcweir                         {
932*cdf0e10cSrcweir                             state = 3;
933*cdf0e10cSrcweir                         }
934*cdf0e10cSrcweir                         else
935*cdf0e10cSrcweir                         {
936*cdf0e10cSrcweir                             if (token[0] == '?')
937*cdf0e10cSrcweir                             {
938*cdf0e10cSrcweir                                 token = token.copy(1);
939*cdf0e10cSrcweir                             }
940*cdf0e10cSrcweir                             m_components.push_back(token);
941*cdf0e10cSrcweir                             state = 3;
942*cdf0e10cSrcweir                         }
943*cdf0e10cSrcweir                     }
944*cdf0e10cSrcweir                 }
945*cdf0e10cSrcweir             }
946*cdf0e10cSrcweir 
947*cdf0e10cSrcweir             // native rc:
948*cdf0e10cSrcweir             if (create_ucb_content(
949*cdf0e10cSrcweir                     &ucb_content,
950*cdf0e10cSrcweir                     makeURL( getCachePath(), getPlatformString() + OUSTR("rc")),
951*cdf0e10cSrcweir                     xCmdEnv, false /* no throw */ )) {
952*cdf0e10cSrcweir                 if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
953*cdf0e10cSrcweir                               RTL_TEXTENCODING_UTF8 )) {
954*cdf0e10cSrcweir                     m_nativeRDB_RO = line.copy(
955*cdf0e10cSrcweir                         sizeof ("UNO_SERVICES=?$ORIGIN/") - 1 );
956*cdf0e10cSrcweir                 }
957*cdf0e10cSrcweir             }
958*cdf0e10cSrcweir         }
959*cdf0e10cSrcweir         m_unorc_modified = false;
960*cdf0e10cSrcweir         m_unorc_inited = true;
961*cdf0e10cSrcweir     }
962*cdf0e10cSrcweir }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir //______________________________________________________________________________
965*cdf0e10cSrcweir void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv )
966*cdf0e10cSrcweir {
967*cdf0e10cSrcweir     if (transientMode())
968*cdf0e10cSrcweir         return;
969*cdf0e10cSrcweir     if (!m_unorc_inited || !m_unorc_modified)
970*cdf0e10cSrcweir         return;
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir     ::rtl::OStringBuffer buf;
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir     buf.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN="));
975*cdf0e10cSrcweir     OUString sOrigin = dp_misc::makeRcTerm(m_cachePath);
976*cdf0e10cSrcweir     ::rtl::OString osOrigin = ::rtl::OUStringToOString(sOrigin, RTL_TEXTENCODING_UTF8);
977*cdf0e10cSrcweir     buf.append(osOrigin);
978*cdf0e10cSrcweir     buf.append(LF);
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir     if (! m_jar_typelibs.empty())
981*cdf0e10cSrcweir     {
982*cdf0e10cSrcweir         t_stringlist::const_iterator iPos( m_jar_typelibs.begin() );
983*cdf0e10cSrcweir         t_stringlist::const_iterator const iEnd( m_jar_typelibs.end() );
984*cdf0e10cSrcweir         buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_JAVA_CLASSPATH=") );
985*cdf0e10cSrcweir         while (iPos != iEnd) {
986*cdf0e10cSrcweir             // encoded ASCII file-urls:
987*cdf0e10cSrcweir             const ::rtl::OString item(
988*cdf0e10cSrcweir                 ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
989*cdf0e10cSrcweir             buf.append( item );
990*cdf0e10cSrcweir             ++iPos;
991*cdf0e10cSrcweir             if (iPos != iEnd)
992*cdf0e10cSrcweir                 buf.append( ' ' );
993*cdf0e10cSrcweir         }
994*cdf0e10cSrcweir         buf.append(LF);
995*cdf0e10cSrcweir     }
996*cdf0e10cSrcweir     if (! m_rdb_typelibs.empty())
997*cdf0e10cSrcweir     {
998*cdf0e10cSrcweir         t_stringlist::const_iterator iPos( m_rdb_typelibs.begin() );
999*cdf0e10cSrcweir         t_stringlist::const_iterator const iEnd( m_rdb_typelibs.end() );
1000*cdf0e10cSrcweir         buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_TYPES=") );
1001*cdf0e10cSrcweir         while (iPos != iEnd) {
1002*cdf0e10cSrcweir             buf.append( '?' );
1003*cdf0e10cSrcweir             // encoded ASCII file-urls:
1004*cdf0e10cSrcweir             const ::rtl::OString item(
1005*cdf0e10cSrcweir                 ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
1006*cdf0e10cSrcweir             buf.append( item );
1007*cdf0e10cSrcweir             ++iPos;
1008*cdf0e10cSrcweir             if (iPos != iEnd)
1009*cdf0e10cSrcweir                 buf.append( ' ' );
1010*cdf0e10cSrcweir         }
1011*cdf0e10cSrcweir         buf.append(LF);
1012*cdf0e10cSrcweir     }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir     // If we duplicated the common or native rdb then we must use those urls
1015*cdf0e10cSrcweir     //otherwise we use those of the original files. That is, m_commonRDB_RO and
1016*cdf0e10cSrcweir     //m_nativeRDB_RO;
1017*cdf0e10cSrcweir     OUString sCommonRDB(m_commonRDB.getLength() > 0 ? m_commonRDB : m_commonRDB_RO);
1018*cdf0e10cSrcweir     OUString sNativeRDB(m_nativeRDB.getLength() > 0 ? m_nativeRDB : m_nativeRDB_RO);
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir     if (sCommonRDB.getLength() > 0 || sNativeRDB.getLength() > 0 ||
1021*cdf0e10cSrcweir         !m_components.empty())
1022*cdf0e10cSrcweir     {
1023*cdf0e10cSrcweir         buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=") );
1024*cdf0e10cSrcweir         bool space = false;
1025*cdf0e10cSrcweir         if (sCommonRDB.getLength() > 0)
1026*cdf0e10cSrcweir         {
1027*cdf0e10cSrcweir             buf.append( RTL_CONSTASCII_STRINGPARAM("?$ORIGIN/") );
1028*cdf0e10cSrcweir             buf.append( ::rtl::OUStringToOString(
1029*cdf0e10cSrcweir                             sCommonRDB, RTL_TEXTENCODING_ASCII_US ) );
1030*cdf0e10cSrcweir             space = true;
1031*cdf0e10cSrcweir         }
1032*cdf0e10cSrcweir         if (sNativeRDB.getLength() > 0)
1033*cdf0e10cSrcweir         {
1034*cdf0e10cSrcweir             if (space)
1035*cdf0e10cSrcweir             {
1036*cdf0e10cSrcweir                 buf.append(' ');
1037*cdf0e10cSrcweir             }
1038*cdf0e10cSrcweir             buf.append( RTL_CONSTASCII_STRINGPARAM(
1039*cdf0e10cSrcweir                             "${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}") );
1040*cdf0e10cSrcweir             space = true;
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir             // write native rc:
1043*cdf0e10cSrcweir             ::rtl::OStringBuffer buf2;
1044*cdf0e10cSrcweir             buf2.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN="));
1045*cdf0e10cSrcweir             buf2.append(osOrigin);
1046*cdf0e10cSrcweir             buf2.append(LF);
1047*cdf0e10cSrcweir             buf2.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=?$ORIGIN/") );
1048*cdf0e10cSrcweir             buf2.append( ::rtl::OUStringToOString(
1049*cdf0e10cSrcweir                              sNativeRDB, RTL_TEXTENCODING_ASCII_US ) );
1050*cdf0e10cSrcweir             buf2.append(LF);
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir             const Reference<io::XInputStream> xData(
1053*cdf0e10cSrcweir                 ::xmlscript::createInputStream(
1054*cdf0e10cSrcweir                     ::rtl::ByteSequence(
1055*cdf0e10cSrcweir                         reinterpret_cast<sal_Int8 const *>(buf2.getStr()),
1056*cdf0e10cSrcweir                         buf2.getLength() ) ) );
1057*cdf0e10cSrcweir             ::ucbhelper::Content ucb_content(
1058*cdf0e10cSrcweir                 makeURL( getCachePath(), getPlatformString() + OUSTR("rc") ),
1059*cdf0e10cSrcweir                 xCmdEnv );
1060*cdf0e10cSrcweir             ucb_content.writeStream( xData, true /* replace existing */ );
1061*cdf0e10cSrcweir         }
1062*cdf0e10cSrcweir         for (t_stringlist::iterator i(m_components.begin());
1063*cdf0e10cSrcweir              i != m_components.end(); ++i)
1064*cdf0e10cSrcweir         {
1065*cdf0e10cSrcweir             if (space)
1066*cdf0e10cSrcweir             {
1067*cdf0e10cSrcweir                 buf.append(' ');
1068*cdf0e10cSrcweir             }
1069*cdf0e10cSrcweir             buf.append('?');
1070*cdf0e10cSrcweir             buf.append(rtl::OUStringToOString(*i, RTL_TEXTENCODING_UTF8));
1071*cdf0e10cSrcweir             space = true;
1072*cdf0e10cSrcweir         }
1073*cdf0e10cSrcweir         buf.append(LF);
1074*cdf0e10cSrcweir     }
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir     // write unorc:
1077*cdf0e10cSrcweir     const Reference<io::XInputStream> xData(
1078*cdf0e10cSrcweir         ::xmlscript::createInputStream(
1079*cdf0e10cSrcweir             ::rtl::ByteSequence(
1080*cdf0e10cSrcweir                 reinterpret_cast<sal_Int8 const *>(buf.getStr()),
1081*cdf0e10cSrcweir                 buf.getLength() ) ) );
1082*cdf0e10cSrcweir     ::ucbhelper::Content ucb_content(
1083*cdf0e10cSrcweir         makeURL( getCachePath(), OUSTR("unorc") ), xCmdEnv );
1084*cdf0e10cSrcweir     ucb_content.writeStream( xData, true /* replace existing */ );
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir     m_unorc_modified = false;
1087*cdf0e10cSrcweir }
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir //______________________________________________________________________________
1090*cdf0e10cSrcweir bool BackendImpl::addToUnoRc( RcItem kind, OUString const & url_,
1091*cdf0e10cSrcweir                               Reference<XCommandEnvironment> const & xCmdEnv )
1092*cdf0e10cSrcweir {
1093*cdf0e10cSrcweir     const OUString rcterm( dp_misc::makeRcTerm(url_) );
1094*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1095*cdf0e10cSrcweir     unorc_verify_init( xCmdEnv );
1096*cdf0e10cSrcweir     t_stringlist & rSet = getRcItemList(kind);
1097*cdf0e10cSrcweir     if (::std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
1098*cdf0e10cSrcweir         rSet.push_front( rcterm ); // prepend to list, thus overriding
1099*cdf0e10cSrcweir         // write immediately:
1100*cdf0e10cSrcweir         m_unorc_modified = true;
1101*cdf0e10cSrcweir         unorc_flush( xCmdEnv );
1102*cdf0e10cSrcweir         return true;
1103*cdf0e10cSrcweir     }
1104*cdf0e10cSrcweir     else
1105*cdf0e10cSrcweir         return false;
1106*cdf0e10cSrcweir }
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir //______________________________________________________________________________
1109*cdf0e10cSrcweir bool BackendImpl::removeFromUnoRc(
1110*cdf0e10cSrcweir     RcItem kind, OUString const & url_,
1111*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
1112*cdf0e10cSrcweir {
1113*cdf0e10cSrcweir     const OUString rcterm( dp_misc::makeRcTerm(url_) );
1114*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1115*cdf0e10cSrcweir     unorc_verify_init( xCmdEnv );
1116*cdf0e10cSrcweir     getRcItemList(kind).remove( rcterm );
1117*cdf0e10cSrcweir     // write immediately:
1118*cdf0e10cSrcweir     m_unorc_modified = true;
1119*cdf0e10cSrcweir     unorc_flush( xCmdEnv );
1120*cdf0e10cSrcweir     return true;
1121*cdf0e10cSrcweir }
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir //______________________________________________________________________________
1124*cdf0e10cSrcweir bool BackendImpl::hasInUnoRc(
1125*cdf0e10cSrcweir     RcItem kind, OUString const & url_ )
1126*cdf0e10cSrcweir {
1127*cdf0e10cSrcweir     const OUString rcterm( dp_misc::makeRcTerm(url_) );
1128*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1129*cdf0e10cSrcweir     t_stringlist const & rSet = getRcItemList(kind);
1130*cdf0e10cSrcweir     return ::std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end();
1131*cdf0e10cSrcweir }
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey > BackendImpl::openRegistryKey(
1134*cdf0e10cSrcweir     css::uno::Reference< css::registry::XRegistryKey > const & base,
1135*cdf0e10cSrcweir     rtl::OUString const & path)
1136*cdf0e10cSrcweir {
1137*cdf0e10cSrcweir     OSL_ASSERT(base.is());
1138*cdf0e10cSrcweir     css::uno::Reference< css::registry::XRegistryKey > key(base->openKey(path));
1139*cdf0e10cSrcweir     if (!key.is()) {
1140*cdf0e10cSrcweir         throw css::deployment::DeploymentException(
1141*cdf0e10cSrcweir             (rtl::OUString(
1142*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("missing registry entry ")) +
1143*cdf0e10cSrcweir              path + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" under ")) +
1144*cdf0e10cSrcweir              base->getKeyName()),
1145*cdf0e10cSrcweir             static_cast< OWeakObject * >(this), Any());
1146*cdf0e10cSrcweir     }
1147*cdf0e10cSrcweir     return key;
1148*cdf0e10cSrcweir }
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir void BackendImpl::extractComponentData(
1151*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context,
1152*cdf0e10cSrcweir     css::uno::Reference< css::registry::XRegistryKey > const & registry,
1153*cdf0e10cSrcweir     ComponentBackendDb::Data * data,
1154*cdf0e10cSrcweir     std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1155*cdf0e10cSrcweir     css::uno::Reference< css::loader::XImplementationLoader > const *
1156*cdf0e10cSrcweir         componentLoader,
1157*cdf0e10cSrcweir     rtl::OUString const * componentUrl)
1158*cdf0e10cSrcweir {
1159*cdf0e10cSrcweir     OSL_ASSERT(context.is() && registry.is() && data != 0 && factories != 0);
1160*cdf0e10cSrcweir     rtl::OUString registryName(registry->getKeyName());
1161*cdf0e10cSrcweir     sal_Int32 prefix = registryName.getLength();
1162*cdf0e10cSrcweir     if (!registryName.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("/"))) {
1163*cdf0e10cSrcweir         prefix += RTL_CONSTASCII_LENGTH("/");
1164*cdf0e10cSrcweir     }
1165*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1166*cdf0e10cSrcweir         keys(registry->openKeys());
1167*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
1168*cdf0e10cSrcweir         context->getServiceManager(), css::uno::UNO_QUERY_THROW);
1169*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < keys.getLength(); ++i) {
1170*cdf0e10cSrcweir         rtl::OUString name(keys[i]->getKeyName().copy(prefix));
1171*cdf0e10cSrcweir         data->implementationNames.push_back(name);
1172*cdf0e10cSrcweir         css::uno::Reference< css::registry::XRegistryKey > singletons(
1173*cdf0e10cSrcweir             keys[i]->openKey(
1174*cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UNO/SINGLETONS"))));
1175*cdf0e10cSrcweir         if (singletons.is()) {
1176*cdf0e10cSrcweir             sal_Int32 prefix2 = keys[i]->getKeyName().getLength() +
1177*cdf0e10cSrcweir                 RTL_CONSTASCII_LENGTH("/UNO/SINGLETONS/");
1178*cdf0e10cSrcweir             css::uno::Sequence<
1179*cdf0e10cSrcweir                 css::uno::Reference< css::registry::XRegistryKey > >
1180*cdf0e10cSrcweir                 singletonKeys(singletons->openKeys());
1181*cdf0e10cSrcweir             for (sal_Int32 j = 0; j < singletonKeys.getLength(); ++j) {
1182*cdf0e10cSrcweir                 data->singletons.push_back(
1183*cdf0e10cSrcweir                     std::pair< rtl::OUString, rtl::OUString >(
1184*cdf0e10cSrcweir                         singletonKeys[j]->getKeyName().copy(prefix2), name));
1185*cdf0e10cSrcweir             }
1186*cdf0e10cSrcweir         }
1187*cdf0e10cSrcweir         css::uno::Reference< css::loader::XImplementationLoader > loader;
1188*cdf0e10cSrcweir         if (componentLoader == 0) {
1189*cdf0e10cSrcweir             rtl::OUString activator(
1190*cdf0e10cSrcweir                 openRegistryKey(
1191*cdf0e10cSrcweir                     keys[i],
1192*cdf0e10cSrcweir                     rtl::OUString(
1193*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM("UNO/ACTIVATOR")))->
1194*cdf0e10cSrcweir                 getAsciiValue());
1195*cdf0e10cSrcweir             loader.set(
1196*cdf0e10cSrcweir                 smgr->createInstanceWithContext(activator, context),
1197*cdf0e10cSrcweir                 css::uno::UNO_QUERY);
1198*cdf0e10cSrcweir             if (!loader.is()) {
1199*cdf0e10cSrcweir                 throw css::deployment::DeploymentException(
1200*cdf0e10cSrcweir                     (rtl::OUString(
1201*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
1202*cdf0e10cSrcweir                             "cannot instantiate loader ")) +
1203*cdf0e10cSrcweir                      activator),
1204*cdf0e10cSrcweir                     static_cast< OWeakObject * >(this), Any());
1205*cdf0e10cSrcweir             }
1206*cdf0e10cSrcweir         } else {
1207*cdf0e10cSrcweir             OSL_ASSERT(componentLoader->is());
1208*cdf0e10cSrcweir             loader = *componentLoader;
1209*cdf0e10cSrcweir         }
1210*cdf0e10cSrcweir         factories->push_back(
1211*cdf0e10cSrcweir             loader->activate(
1212*cdf0e10cSrcweir                 name, rtl::OUString(),
1213*cdf0e10cSrcweir                 (componentUrl == 0
1214*cdf0e10cSrcweir                  ? (openRegistryKey(
1215*cdf0e10cSrcweir                         keys[i],
1216*cdf0e10cSrcweir                         rtl::OUString(
1217*cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM("UNO/LOCATION")))->
1218*cdf0e10cSrcweir                     getAsciiValue())
1219*cdf0e10cSrcweir                  : *componentUrl),
1220*cdf0e10cSrcweir                 keys[i]));
1221*cdf0e10cSrcweir     }
1222*cdf0e10cSrcweir }
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir void BackendImpl::componentLiveInsertion(
1225*cdf0e10cSrcweir     ComponentBackendDb::Data const & data,
1226*cdf0e10cSrcweir     std::vector< css::uno::Reference< css::uno::XInterface > > const &
1227*cdf0e10cSrcweir         factories)
1228*cdf0e10cSrcweir {
1229*cdf0e10cSrcweir     css::uno::Reference< css::container::XSet > set(
1230*cdf0e10cSrcweir         getComponentContext()->getServiceManager(), css::uno::UNO_QUERY_THROW);
1231*cdf0e10cSrcweir     std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
1232*cdf0e10cSrcweir         factory(factories.begin());
1233*cdf0e10cSrcweir     for (t_stringlist::const_iterator i(data.implementationNames.begin());
1234*cdf0e10cSrcweir          i != data.implementationNames.end(); ++i)
1235*cdf0e10cSrcweir     {
1236*cdf0e10cSrcweir         try {
1237*cdf0e10cSrcweir             set->insert(css::uno::Any(*factory++));
1238*cdf0e10cSrcweir         } catch (container::ElementExistException &) {
1239*cdf0e10cSrcweir             OSL_TRACE(
1240*cdf0e10cSrcweir                 "implementation %s already registered",
1241*cdf0e10cSrcweir                 rtl::OUStringToOString(*i, RTL_TEXTENCODING_UTF8).getStr());
1242*cdf0e10cSrcweir         }
1243*cdf0e10cSrcweir     }
1244*cdf0e10cSrcweir     if (!data.singletons.empty()) {
1245*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameContainer >
1246*cdf0e10cSrcweir             rootContext(
1247*cdf0e10cSrcweir                 getComponentContext()->getValueByName(
1248*cdf0e10cSrcweir                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
1249*cdf0e10cSrcweir                 css::uno::UNO_QUERY);
1250*cdf0e10cSrcweir         if (rootContext.is()) {
1251*cdf0e10cSrcweir             for (t_stringpairvec::const_iterator i(data.singletons.begin());
1252*cdf0e10cSrcweir                  i != data.singletons.end(); ++i)
1253*cdf0e10cSrcweir             {
1254*cdf0e10cSrcweir                 rtl::OUString name(
1255*cdf0e10cSrcweir                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
1256*cdf0e10cSrcweir                     i->first);
1257*cdf0e10cSrcweir                 try {
1258*cdf0e10cSrcweir                     rootContext->removeByName(
1259*cdf0e10cSrcweir                         name +
1260*cdf0e10cSrcweir                         rtl::OUString(
1261*cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM("/arguments")));
1262*cdf0e10cSrcweir                 } catch (container::NoSuchElementException &) {}
1263*cdf0e10cSrcweir                 try {
1264*cdf0e10cSrcweir                     rootContext->insertByName(
1265*cdf0e10cSrcweir                         (name +
1266*cdf0e10cSrcweir                          rtl::OUString(
1267*cdf0e10cSrcweir                              RTL_CONSTASCII_USTRINGPARAM("/service"))),
1268*cdf0e10cSrcweir                         css::uno::Any(i->second));
1269*cdf0e10cSrcweir                 } catch (container::ElementExistException &) {
1270*cdf0e10cSrcweir                     rootContext->replaceByName(
1271*cdf0e10cSrcweir                         (name +
1272*cdf0e10cSrcweir                          rtl::OUString(
1273*cdf0e10cSrcweir                              RTL_CONSTASCII_USTRINGPARAM("/service"))),
1274*cdf0e10cSrcweir                         css::uno::Any(i->second));
1275*cdf0e10cSrcweir                 }
1276*cdf0e10cSrcweir                 try {
1277*cdf0e10cSrcweir                     rootContext->insertByName(name, css::uno::Any());
1278*cdf0e10cSrcweir                 } catch (container::ElementExistException &) {
1279*cdf0e10cSrcweir                     OSL_TRACE(
1280*cdf0e10cSrcweir                         "singleton %s already registered",
1281*cdf0e10cSrcweir                         rtl::OUStringToOString(
1282*cdf0e10cSrcweir                             i->first, RTL_TEXTENCODING_UTF8).getStr());
1283*cdf0e10cSrcweir                     rootContext->replaceByName(name, css::uno::Any());
1284*cdf0e10cSrcweir                 }
1285*cdf0e10cSrcweir             }
1286*cdf0e10cSrcweir         }
1287*cdf0e10cSrcweir     }
1288*cdf0e10cSrcweir }
1289*cdf0e10cSrcweir 
1290*cdf0e10cSrcweir void BackendImpl::componentLiveRemoval(ComponentBackendDb::Data const & data) {
1291*cdf0e10cSrcweir     css::uno::Reference< css::container::XSet > set(
1292*cdf0e10cSrcweir         getComponentContext()->getServiceManager(), css::uno::UNO_QUERY_THROW);
1293*cdf0e10cSrcweir     for (t_stringlist::const_iterator i(data.implementationNames.begin());
1294*cdf0e10cSrcweir          i != data.implementationNames.end(); ++i)
1295*cdf0e10cSrcweir     {
1296*cdf0e10cSrcweir         try {
1297*cdf0e10cSrcweir             set->remove(css::uno::Any(*i));
1298*cdf0e10cSrcweir         } catch (css::container::NoSuchElementException &) {
1299*cdf0e10cSrcweir             // ignore if factory has not been live deployed
1300*cdf0e10cSrcweir         }
1301*cdf0e10cSrcweir     }
1302*cdf0e10cSrcweir     if (!data.singletons.empty()) {
1303*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameContainer > rootContext(
1304*cdf0e10cSrcweir             getComponentContext()->getValueByName(
1305*cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
1306*cdf0e10cSrcweir             css::uno::UNO_QUERY);
1307*cdf0e10cSrcweir         if (rootContext.is()) {
1308*cdf0e10cSrcweir             for (t_stringpairvec::const_iterator i(data.singletons.begin());
1309*cdf0e10cSrcweir                  i != data.singletons.end(); ++i)
1310*cdf0e10cSrcweir             {
1311*cdf0e10cSrcweir                 rtl::OUString name(
1312*cdf0e10cSrcweir                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
1313*cdf0e10cSrcweir                     i->first);
1314*cdf0e10cSrcweir                 try {
1315*cdf0e10cSrcweir                     rootContext->removeByName(
1316*cdf0e10cSrcweir                         name +
1317*cdf0e10cSrcweir                         rtl::OUString(
1318*cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM("/arguments")));
1319*cdf0e10cSrcweir                     rootContext->removeByName(
1320*cdf0e10cSrcweir                         name +
1321*cdf0e10cSrcweir                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service")));
1322*cdf0e10cSrcweir                     rootContext->removeByName(name);
1323*cdf0e10cSrcweir                 } catch (container::NoSuchElementException &) {}
1324*cdf0e10cSrcweir             }
1325*cdf0e10cSrcweir         }
1326*cdf0e10cSrcweir     }
1327*cdf0e10cSrcweir }
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir //______________________________________________________________________________
1330*cdf0e10cSrcweir void BackendImpl::releaseObject( OUString const & id )
1331*cdf0e10cSrcweir {
1332*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1333*cdf0e10cSrcweir     m_backendObjects.erase( id );
1334*cdf0e10cSrcweir }
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir //______________________________________________________________________________
1337*cdf0e10cSrcweir Reference<XInterface> BackendImpl::getObject( OUString const & id )
1338*cdf0e10cSrcweir {
1339*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1340*cdf0e10cSrcweir     const t_string2object::const_iterator iFind( m_backendObjects.find( id ) );
1341*cdf0e10cSrcweir     if (iFind == m_backendObjects.end())
1342*cdf0e10cSrcweir         return Reference<XInterface>();
1343*cdf0e10cSrcweir     else
1344*cdf0e10cSrcweir         return iFind->second;
1345*cdf0e10cSrcweir }
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir //______________________________________________________________________________
1348*cdf0e10cSrcweir Reference<XInterface> BackendImpl::insertObject(
1349*cdf0e10cSrcweir     OUString const & id, Reference<XInterface> const & xObject )
1350*cdf0e10cSrcweir {
1351*cdf0e10cSrcweir     const ::osl::MutexGuard guard( getMutex() );
1352*cdf0e10cSrcweir     const ::std::pair<t_string2object::iterator, bool> insertion(
1353*cdf0e10cSrcweir         m_backendObjects.insert( t_string2object::value_type(
1354*cdf0e10cSrcweir                                      id, xObject ) ) );
1355*cdf0e10cSrcweir     return insertion.first->second;
1356*cdf0e10cSrcweir }
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir //------------------------------------------------------------------------------
1359*cdf0e10cSrcweir Reference<XComponentContext> raise_uno_process(
1360*cdf0e10cSrcweir     Reference<XComponentContext> const & xContext,
1361*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const & abortChannel )
1362*cdf0e10cSrcweir {
1363*cdf0e10cSrcweir     OSL_ASSERT( xContext.is() );
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir     ::rtl::OUString url(
1366*cdf0e10cSrcweir         Reference<util::XMacroExpander>(
1367*cdf0e10cSrcweir             xContext->getValueByName(
1368*cdf0e10cSrcweir                 OUSTR("/singletons/com.sun.star.util.theMacroExpander") ),
1369*cdf0e10cSrcweir             UNO_QUERY_THROW )->
1370*cdf0e10cSrcweir         expandMacros( OUSTR("$URE_BIN_DIR/uno") ) );
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir     ::rtl::OUStringBuffer buf;
1373*cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno:pipe,name=") );
1374*cdf0e10cSrcweir     OUString pipeId( generateRandomPipeId() );
1375*cdf0e10cSrcweir     buf.append( pipeId );
1376*cdf0e10cSrcweir     buf.appendAscii(
1377*cdf0e10cSrcweir         RTL_CONSTASCII_STRINGPARAM(";urp;uno.ComponentContext") );
1378*cdf0e10cSrcweir     const OUString connectStr( buf.makeStringAndClear() );
1379*cdf0e10cSrcweir 
1380*cdf0e10cSrcweir     // raise core UNO process to register/run a component,
1381*cdf0e10cSrcweir     // javavm service uses unorc next to executable to retrieve deployed
1382*cdf0e10cSrcweir     // jar typelibs
1383*cdf0e10cSrcweir 
1384*cdf0e10cSrcweir     ::std::vector<OUString> args;
1385*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL <= 1
1386*cdf0e10cSrcweir     args.push_back( OUSTR("--quiet") );
1387*cdf0e10cSrcweir #endif
1388*cdf0e10cSrcweir     args.push_back( OUSTR("--singleaccept") );
1389*cdf0e10cSrcweir     args.push_back( OUSTR("-u") );
1390*cdf0e10cSrcweir     args.push_back( connectStr );
1391*cdf0e10cSrcweir     // don't inherit from unorc:
1392*cdf0e10cSrcweir     args.push_back( OUSTR("-env:INIFILENAME=") );
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir     //now add the bootstrap variables which were supplied on the command line
1395*cdf0e10cSrcweir     ::std::vector<OUString> bootvars = getCmdBootstrapVariables();
1396*cdf0e10cSrcweir     args.insert(args.end(), bootvars.begin(), bootvars.end());
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir     oslProcess hProcess = raiseProcess(
1399*cdf0e10cSrcweir         url, comphelper::containerToSequence(args) );
1400*cdf0e10cSrcweir     try {
1401*cdf0e10cSrcweir         return Reference<XComponentContext>(
1402*cdf0e10cSrcweir             resolveUnoURL( connectStr, xContext, abortChannel.get() ),
1403*cdf0e10cSrcweir             UNO_QUERY_THROW );
1404*cdf0e10cSrcweir     }
1405*cdf0e10cSrcweir     catch (...) {
1406*cdf0e10cSrcweir         // try to terminate process:
1407*cdf0e10cSrcweir         if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
1408*cdf0e10cSrcweir         {
1409*cdf0e10cSrcweir             OSL_ASSERT( false );
1410*cdf0e10cSrcweir         }
1411*cdf0e10cSrcweir         throw;
1412*cdf0e10cSrcweir     }
1413*cdf0e10cSrcweir }
1414*cdf0e10cSrcweir 
1415*cdf0e10cSrcweir //------------------------------------------------------------------------------
1416*cdf0e10cSrcweir void BackendImpl::ComponentPackageImpl::getComponentInfo(
1417*cdf0e10cSrcweir     ComponentBackendDb::Data * data,
1418*cdf0e10cSrcweir     std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1419*cdf0e10cSrcweir     Reference<XComponentContext> const & xContext )
1420*cdf0e10cSrcweir {
1421*cdf0e10cSrcweir     const Reference<loader::XImplementationLoader> xLoader(
1422*cdf0e10cSrcweir         xContext->getServiceManager()->createInstanceWithContext(
1423*cdf0e10cSrcweir             m_loader, xContext ), UNO_QUERY );
1424*cdf0e10cSrcweir     if (! xLoader.is())
1425*cdf0e10cSrcweir     {
1426*cdf0e10cSrcweir         throw css::deployment::DeploymentException(
1427*cdf0e10cSrcweir             (rtl::OUString(
1428*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("cannot instantiate loader ")) +
1429*cdf0e10cSrcweir              m_loader),
1430*cdf0e10cSrcweir             static_cast< OWeakObject * >(this), Any());
1431*cdf0e10cSrcweir     }
1432*cdf0e10cSrcweir 
1433*cdf0e10cSrcweir     // HACK: highly dependent on stoc/source/servicemanager
1434*cdf0e10cSrcweir     //       and stoc/source/implreg implementation which rely on the same
1435*cdf0e10cSrcweir     //       services.rdb format!
1436*cdf0e10cSrcweir     //       .../UNO/LOCATION and .../UNO/ACTIVATOR appear not to be written by
1437*cdf0e10cSrcweir     //       writeRegistryInfo, however, but are knwon, fixed values here, so
1438*cdf0e10cSrcweir     //       can be passed into extractComponentData
1439*cdf0e10cSrcweir     rtl::OUString url(getURL());
1440*cdf0e10cSrcweir     const Reference<registry::XSimpleRegistry> xMemReg(
1441*cdf0e10cSrcweir         xContext->getServiceManager()->createInstanceWithContext(
1442*cdf0e10cSrcweir             OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
1443*cdf0e10cSrcweir         UNO_QUERY_THROW );
1444*cdf0e10cSrcweir     xMemReg->open( OUString() /* in mem */, false, true );
1445*cdf0e10cSrcweir     xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
1446*cdf0e10cSrcweir     getMyBackend()->extractComponentData(
1447*cdf0e10cSrcweir         xContext, xMemReg->getRootKey(), data, factories, &xLoader, &url);
1448*cdf0e10cSrcweir }
1449*cdf0e10cSrcweir 
1450*cdf0e10cSrcweir // Package
1451*cdf0e10cSrcweir //______________________________________________________________________________
1452*cdf0e10cSrcweir //We could use here BackendImpl::hasActiveEntry. However, this check is just as well.
1453*cdf0e10cSrcweir //And it also shows the problem if another extension has overwritten an implementation
1454*cdf0e10cSrcweir //entry, because it contains the same service implementation
1455*cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> >
1456*cdf0e10cSrcweir BackendImpl::ComponentPackageImpl::isRegistered_(
1457*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1458*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const & abortChannel,
1459*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
1460*cdf0e10cSrcweir {
1461*cdf0e10cSrcweir     if (m_registered == REG_UNINIT)
1462*cdf0e10cSrcweir     {
1463*cdf0e10cSrcweir         m_registered = REG_NOT_REGISTERED;
1464*cdf0e10cSrcweir         bool bAmbiguousComponentName = false;
1465*cdf0e10cSrcweir         const Reference<registry::XSimpleRegistry> xRDB( getRDB_RO() );
1466*cdf0e10cSrcweir         if (xRDB.is())
1467*cdf0e10cSrcweir         {
1468*cdf0e10cSrcweir             // lookup rdb for location URL:
1469*cdf0e10cSrcweir             const Reference<registry::XRegistryKey> xRootKey(
1470*cdf0e10cSrcweir                 xRDB->getRootKey() );
1471*cdf0e10cSrcweir             const Reference<registry::XRegistryKey> xImplKey(
1472*cdf0e10cSrcweir                 xRootKey->openKey( OUSTR("IMPLEMENTATIONS") ) );
1473*cdf0e10cSrcweir             Sequence<OUString> implNames;
1474*cdf0e10cSrcweir             if (xImplKey.is() && xImplKey->isValid())
1475*cdf0e10cSrcweir                 implNames = xImplKey->getKeyNames();
1476*cdf0e10cSrcweir             OUString const * pImplNames = implNames.getConstArray();
1477*cdf0e10cSrcweir             sal_Int32 pos = implNames.getLength();
1478*cdf0e10cSrcweir             for ( ; pos--; )
1479*cdf0e10cSrcweir             {
1480*cdf0e10cSrcweir                 checkAborted( abortChannel );
1481*cdf0e10cSrcweir                 const OUString key(
1482*cdf0e10cSrcweir                     pImplNames[ pos ] + OUSTR("/UNO/LOCATION") );
1483*cdf0e10cSrcweir                 const Reference<registry::XRegistryKey> xKey(
1484*cdf0e10cSrcweir                     xRootKey->openKey(key) );
1485*cdf0e10cSrcweir                 if (xKey.is() && xKey->isValid())
1486*cdf0e10cSrcweir                 {
1487*cdf0e10cSrcweir                     const OUString location( xKey->getAsciiValue() );
1488*cdf0e10cSrcweir                     if (location.equalsIgnoreAsciiCase( getURL() ))
1489*cdf0e10cSrcweir                     {
1490*cdf0e10cSrcweir                         break;
1491*cdf0e10cSrcweir                     }
1492*cdf0e10cSrcweir                     else
1493*cdf0e10cSrcweir                     {
1494*cdf0e10cSrcweir                         //try to match only the file name
1495*cdf0e10cSrcweir                         OUString thisUrl(getURL());
1496*cdf0e10cSrcweir                         OUString thisFileName(thisUrl.copy(thisUrl.lastIndexOf('/')));
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir                         OUString locationFileName(location.copy(location.lastIndexOf('/')));
1499*cdf0e10cSrcweir                         if (locationFileName.equalsIgnoreAsciiCase(thisFileName))
1500*cdf0e10cSrcweir                             bAmbiguousComponentName = true;
1501*cdf0e10cSrcweir                     }
1502*cdf0e10cSrcweir                 }
1503*cdf0e10cSrcweir             }
1504*cdf0e10cSrcweir             if (pos >= 0)
1505*cdf0e10cSrcweir                 m_registered = REG_REGISTERED;
1506*cdf0e10cSrcweir             else if (bAmbiguousComponentName)
1507*cdf0e10cSrcweir                 m_registered = REG_MAYBE_REGISTERED;
1508*cdf0e10cSrcweir         }
1509*cdf0e10cSrcweir     }
1510*cdf0e10cSrcweir 
1511*cdf0e10cSrcweir     //Different extensions can use the same service implementations. Then the extensions
1512*cdf0e10cSrcweir     //which was installed last will overwrite the one from the other extension. That is
1513*cdf0e10cSrcweir     //the registry will contain the path (the location) of the library or jar of the
1514*cdf0e10cSrcweir     //second extension. In this case isRegistered called for the lib of the first extension
1515*cdf0e10cSrcweir     //would return "not registered". That would mean that during uninstallation
1516*cdf0e10cSrcweir     //XPackage::registerPackage is not called, because it just was not registered. This is,
1517*cdf0e10cSrcweir     //however, necessary for jar files. Registering and unregistering update
1518*cdf0e10cSrcweir     //uno_packages/cache/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc
1519*cdf0e10cSrcweir     //Therefore, we will return always "is ambiguous" if the path of this component cannot
1520*cdf0e10cSrcweir     //be found in the registry and if there is another path and both have the same file name (but
1521*cdf0e10cSrcweir     //the rest of the path is different).
1522*cdf0e10cSrcweir     //If the caller cannot precisely determine that this package was registered, then it must
1523*cdf0e10cSrcweir     //call registerPackage.
1524*cdf0e10cSrcweir     sal_Bool bAmbiguous = m_registered == REG_VOID // REG_VOID == we are in the progress of unregistration
1525*cdf0e10cSrcweir         || m_registered == REG_MAYBE_REGISTERED;
1526*cdf0e10cSrcweir     return beans::Optional< beans::Ambiguous<sal_Bool> >(
1527*cdf0e10cSrcweir         true /* IsPresent */,
1528*cdf0e10cSrcweir         beans::Ambiguous<sal_Bool>(
1529*cdf0e10cSrcweir             m_registered == REG_REGISTERED, bAmbiguous) );
1530*cdf0e10cSrcweir }
1531*cdf0e10cSrcweir 
1532*cdf0e10cSrcweir //______________________________________________________________________________
1533*cdf0e10cSrcweir void BackendImpl::ComponentPackageImpl::processPackage_(
1534*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1535*cdf0e10cSrcweir     bool doRegisterPackage,
1536*cdf0e10cSrcweir     bool startup,
1537*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const & abortChannel,
1538*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
1539*cdf0e10cSrcweir {
1540*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
1541*cdf0e10cSrcweir     rtl::OUString url(getURL());
1542*cdf0e10cSrcweir     if (doRegisterPackage) {
1543*cdf0e10cSrcweir         ComponentBackendDb::Data data;
1544*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > context;
1545*cdf0e10cSrcweir         if (startup) {
1546*cdf0e10cSrcweir             context = that->getComponentContext();
1547*cdf0e10cSrcweir         } else {
1548*cdf0e10cSrcweir             context.set(that->getObject(url), css::uno::UNO_QUERY);
1549*cdf0e10cSrcweir             if (!context.is()) {
1550*cdf0e10cSrcweir                 context.set(
1551*cdf0e10cSrcweir                     that->insertObject(
1552*cdf0e10cSrcweir                         url,
1553*cdf0e10cSrcweir                         raise_uno_process(
1554*cdf0e10cSrcweir                             that->getComponentContext(), abortChannel)),
1555*cdf0e10cSrcweir                     css::uno::UNO_QUERY_THROW);
1556*cdf0e10cSrcweir             }
1557*cdf0e10cSrcweir         }
1558*cdf0e10cSrcweir         css::uno::Reference< css::registry::XImplementationRegistration>(
1559*cdf0e10cSrcweir             context->getServiceManager()->createInstanceWithContext(
1560*cdf0e10cSrcweir                 rtl::OUString(
1561*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
1562*cdf0e10cSrcweir                         "com.sun.star.registry.ImplementationRegistration")),
1563*cdf0e10cSrcweir                 context),
1564*cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW)->registerImplementation(
1565*cdf0e10cSrcweir                 m_loader, url, getRDB());
1566*cdf0e10cSrcweir         // Only write to unorc after successful registration; it may fail if
1567*cdf0e10cSrcweir         // there is no suitable java
1568*cdf0e10cSrcweir         if (m_loader.equalsAsciiL(
1569*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.Java2")) &&
1570*cdf0e10cSrcweir             !jarManifestHeaderPresent(url, OUSTR("UNO-Type-Path"), xCmdEnv))
1571*cdf0e10cSrcweir         {
1572*cdf0e10cSrcweir             that->addToUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1573*cdf0e10cSrcweir             data.javaTypeLibrary = true;
1574*cdf0e10cSrcweir         }
1575*cdf0e10cSrcweir         std::vector< css::uno::Reference< css::uno::XInterface > > factories;
1576*cdf0e10cSrcweir         getComponentInfo(&data, &factories, context);
1577*cdf0e10cSrcweir         if (!startup) {
1578*cdf0e10cSrcweir             that->componentLiveInsertion(data, factories);
1579*cdf0e10cSrcweir         }
1580*cdf0e10cSrcweir         m_registered = REG_REGISTERED;
1581*cdf0e10cSrcweir         that->addDataToDb(url, data);
1582*cdf0e10cSrcweir     } else { // revoke
1583*cdf0e10cSrcweir         m_registered = REG_VOID;
1584*cdf0e10cSrcweir         ComponentBackendDb::Data data(that->readDataFromDb(url));
1585*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > context(
1586*cdf0e10cSrcweir             that->getObject(url), css::uno::UNO_QUERY);
1587*cdf0e10cSrcweir         bool remoteContext = context.is();
1588*cdf0e10cSrcweir         if (!remoteContext) {
1589*cdf0e10cSrcweir             context = that->getComponentContext();
1590*cdf0e10cSrcweir         }
1591*cdf0e10cSrcweir         if (!startup) {
1592*cdf0e10cSrcweir             that->componentLiveRemoval(data);
1593*cdf0e10cSrcweir         }
1594*cdf0e10cSrcweir         css::uno::Reference< css::registry::XImplementationRegistration >(
1595*cdf0e10cSrcweir             context->getServiceManager()->createInstanceWithContext(
1596*cdf0e10cSrcweir                 rtl::OUString(
1597*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
1598*cdf0e10cSrcweir                         "com.sun.star.registry.ImplementationRegistration")),
1599*cdf0e10cSrcweir                 context),
1600*cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW)->revokeImplementation(url, getRDB());
1601*cdf0e10cSrcweir         if (data.javaTypeLibrary) {
1602*cdf0e10cSrcweir             that->removeFromUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1603*cdf0e10cSrcweir         }
1604*cdf0e10cSrcweir         if (remoteContext) {
1605*cdf0e10cSrcweir             that->releaseObject(url);
1606*cdf0e10cSrcweir         }
1607*cdf0e10cSrcweir         m_registered = REG_NOT_REGISTERED;
1608*cdf0e10cSrcweir         getMyBackend()->revokeEntryFromDb(url);
1609*cdf0e10cSrcweir     }
1610*cdf0e10cSrcweir }
1611*cdf0e10cSrcweir 
1612*cdf0e10cSrcweir //##############################################################################
1613*cdf0e10cSrcweir BackendImpl::TypelibraryPackageImpl::TypelibraryPackageImpl(
1614*cdf0e10cSrcweir     ::rtl::Reference<PackageRegistryBackend> const & myBackend,
1615*cdf0e10cSrcweir     OUString const & url, OUString const & name,
1616*cdf0e10cSrcweir     Reference<deployment::XPackageTypeInfo> const & xPackageType,
1617*cdf0e10cSrcweir     bool jarFile, bool bRemoved, OUString const & identifier)
1618*cdf0e10cSrcweir     : Package( myBackend, url, name, name /* display-name */,
1619*cdf0e10cSrcweir                xPackageType, bRemoved, identifier),
1620*cdf0e10cSrcweir       m_jarFile( jarFile )
1621*cdf0e10cSrcweir {
1622*cdf0e10cSrcweir }
1623*cdf0e10cSrcweir 
1624*cdf0e10cSrcweir // Package
1625*cdf0e10cSrcweir BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend() const
1626*cdf0e10cSrcweir {
1627*cdf0e10cSrcweir     BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1628*cdf0e10cSrcweir     if (NULL == pBackend)
1629*cdf0e10cSrcweir     {
1630*cdf0e10cSrcweir         //May throw a DisposedException
1631*cdf0e10cSrcweir         check();
1632*cdf0e10cSrcweir         //We should never get here...
1633*cdf0e10cSrcweir         throw RuntimeException(
1634*cdf0e10cSrcweir             OUSTR("Failed to get the BackendImpl"),
1635*cdf0e10cSrcweir             static_cast<OWeakObject*>(const_cast<TypelibraryPackageImpl *>(this)));
1636*cdf0e10cSrcweir     }
1637*cdf0e10cSrcweir     return pBackend;
1638*cdf0e10cSrcweir }
1639*cdf0e10cSrcweir //______________________________________________________________________________
1640*cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> >
1641*cdf0e10cSrcweir BackendImpl::TypelibraryPackageImpl::isRegistered_(
1642*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1643*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
1644*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
1645*cdf0e10cSrcweir {
1646*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
1647*cdf0e10cSrcweir     return beans::Optional< beans::Ambiguous<sal_Bool> >(
1648*cdf0e10cSrcweir         true /* IsPresent */,
1649*cdf0e10cSrcweir         beans::Ambiguous<sal_Bool>(
1650*cdf0e10cSrcweir             that->hasInUnoRc(
1651*cdf0e10cSrcweir                 m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, getURL() ),
1652*cdf0e10cSrcweir             false /* IsAmbiguous */ ) );
1653*cdf0e10cSrcweir }
1654*cdf0e10cSrcweir 
1655*cdf0e10cSrcweir //______________________________________________________________________________
1656*cdf0e10cSrcweir void BackendImpl::TypelibraryPackageImpl::processPackage_(
1657*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1658*cdf0e10cSrcweir     bool doRegisterPackage,
1659*cdf0e10cSrcweir     bool /*startup*/,
1660*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
1661*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
1662*cdf0e10cSrcweir {
1663*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
1664*cdf0e10cSrcweir     const OUString url( getURL() );
1665*cdf0e10cSrcweir 
1666*cdf0e10cSrcweir     if (doRegisterPackage)
1667*cdf0e10cSrcweir     {
1668*cdf0e10cSrcweir         // live insertion:
1669*cdf0e10cSrcweir         if (m_jarFile) {
1670*cdf0e10cSrcweir             // xxx todo add to classpath at runtime: ???
1671*cdf0e10cSrcweir             //SB: It is probably not worth it to add the live inserted type
1672*cdf0e10cSrcweir             // library JAR to the UnoClassLoader in the soffice process.  Any
1673*cdf0e10cSrcweir             // live inserted component JAR that might reference this type
1674*cdf0e10cSrcweir             // library JAR runs in its own uno process, so there is probably no
1675*cdf0e10cSrcweir             // Java code in the soffice process that would see any UNO types
1676*cdf0e10cSrcweir             // introduced by this type library JAR.
1677*cdf0e10cSrcweir         }
1678*cdf0e10cSrcweir         else // RDB:
1679*cdf0e10cSrcweir         {
1680*cdf0e10cSrcweir             Reference<XComponentContext> const & xContext =
1681*cdf0e10cSrcweir                 that->getComponentContext();
1682*cdf0e10cSrcweir             if (! m_xTDprov.is())
1683*cdf0e10cSrcweir             {
1684*cdf0e10cSrcweir                 m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1685*cdf0e10cSrcweir                 if (! m_xTDprov.is())
1686*cdf0e10cSrcweir                 {
1687*cdf0e10cSrcweir                     const Reference<registry::XSimpleRegistry> xReg(
1688*cdf0e10cSrcweir                         xContext->getServiceManager()
1689*cdf0e10cSrcweir                         ->createInstanceWithContext(
1690*cdf0e10cSrcweir                             OUSTR("com.sun.star.registry.SimpleRegistry"),
1691*cdf0e10cSrcweir                             xContext ), UNO_QUERY_THROW );
1692*cdf0e10cSrcweir                     xReg->open( expandUnoRcUrl(url),
1693*cdf0e10cSrcweir                                 true /* read-only */, false /* ! create */ );
1694*cdf0e10cSrcweir                     const Any arg(xReg);
1695*cdf0e10cSrcweir                     Reference<container::XHierarchicalNameAccess> xTDprov(
1696*cdf0e10cSrcweir                         xContext->getServiceManager()
1697*cdf0e10cSrcweir                         ->createInstanceWithArgumentsAndContext(
1698*cdf0e10cSrcweir                             OUSTR("com.sun.star.comp.stoc."
1699*cdf0e10cSrcweir                                   "RegistryTypeDescriptionProvider"),
1700*cdf0e10cSrcweir                             Sequence<Any>( &arg, 1 ), xContext ), UNO_QUERY );
1701*cdf0e10cSrcweir                     OSL_ASSERT( xTDprov.is() );
1702*cdf0e10cSrcweir                     if (xTDprov.is())
1703*cdf0e10cSrcweir                         m_xTDprov.set( that->insertObject( url, xTDprov ),
1704*cdf0e10cSrcweir                                        UNO_QUERY_THROW );
1705*cdf0e10cSrcweir                 }
1706*cdf0e10cSrcweir             }
1707*cdf0e10cSrcweir             if (m_xTDprov.is()) {
1708*cdf0e10cSrcweir                 Reference<container::XSet> xSet(
1709*cdf0e10cSrcweir                     xContext->getValueByName(
1710*cdf0e10cSrcweir                         OUSTR("/singletons/com.sun.star."
1711*cdf0e10cSrcweir                               "reflection.theTypeDescriptionManager") ),
1712*cdf0e10cSrcweir                     UNO_QUERY_THROW );
1713*cdf0e10cSrcweir                 xSet->insert( Any(m_xTDprov) );
1714*cdf0e10cSrcweir             }
1715*cdf0e10cSrcweir         }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir         that->addToUnoRc( m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB,
1718*cdf0e10cSrcweir                           url, xCmdEnv );
1719*cdf0e10cSrcweir     }
1720*cdf0e10cSrcweir     else // revokePackage()
1721*cdf0e10cSrcweir     {
1722*cdf0e10cSrcweir         that->removeFromUnoRc(
1723*cdf0e10cSrcweir             m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, url, xCmdEnv );
1724*cdf0e10cSrcweir 
1725*cdf0e10cSrcweir         // revoking types at runtime, possible, sensible?
1726*cdf0e10cSrcweir         if (!m_xTDprov.is())
1727*cdf0e10cSrcweir             m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1728*cdf0e10cSrcweir         if (m_xTDprov.is()) {
1729*cdf0e10cSrcweir             // remove live:
1730*cdf0e10cSrcweir             const Reference<container::XSet> xSet(
1731*cdf0e10cSrcweir                 that->getComponentContext()->getValueByName(
1732*cdf0e10cSrcweir                     OUSTR("/singletons/com.sun.star."
1733*cdf0e10cSrcweir                           "reflection.theTypeDescriptionManager") ),
1734*cdf0e10cSrcweir                 UNO_QUERY_THROW );
1735*cdf0e10cSrcweir             xSet->remove( Any(m_xTDprov) );
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir             that->releaseObject( url );
1738*cdf0e10cSrcweir             m_xTDprov.clear();
1739*cdf0e10cSrcweir         }
1740*cdf0e10cSrcweir     }
1741*cdf0e10cSrcweir }
1742*cdf0e10cSrcweir 
1743*cdf0e10cSrcweir BackendImpl * BackendImpl::ComponentsPackageImpl::getMyBackend() const
1744*cdf0e10cSrcweir {
1745*cdf0e10cSrcweir     BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1746*cdf0e10cSrcweir     if (NULL == pBackend)
1747*cdf0e10cSrcweir     {
1748*cdf0e10cSrcweir         //Throws a DisposedException
1749*cdf0e10cSrcweir         check();
1750*cdf0e10cSrcweir         //We should never get here...
1751*cdf0e10cSrcweir         throw RuntimeException(
1752*cdf0e10cSrcweir             OUSTR("Failed to get the BackendImpl"),
1753*cdf0e10cSrcweir             static_cast<OWeakObject*>(const_cast<ComponentsPackageImpl *>(this)));
1754*cdf0e10cSrcweir     }
1755*cdf0e10cSrcweir     return pBackend;
1756*cdf0e10cSrcweir }
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> >
1759*cdf0e10cSrcweir BackendImpl::ComponentsPackageImpl::isRegistered_(
1760*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1761*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
1762*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
1763*cdf0e10cSrcweir {
1764*cdf0e10cSrcweir     return beans::Optional< beans::Ambiguous<sal_Bool> >(
1765*cdf0e10cSrcweir         true,
1766*cdf0e10cSrcweir         beans::Ambiguous<sal_Bool>(
1767*cdf0e10cSrcweir             getMyBackend()->hasInUnoRc(RCITEM_COMPONENTS, getURL()), false));
1768*cdf0e10cSrcweir }
1769*cdf0e10cSrcweir 
1770*cdf0e10cSrcweir void BackendImpl::ComponentsPackageImpl::processPackage_(
1771*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
1772*cdf0e10cSrcweir     bool doRegisterPackage,
1773*cdf0e10cSrcweir     bool startup,
1774*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const & abortChannel,
1775*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & xCmdEnv )
1776*cdf0e10cSrcweir {
1777*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
1778*cdf0e10cSrcweir     rtl::OUString url(getURL());
1779*cdf0e10cSrcweir     if (doRegisterPackage) {
1780*cdf0e10cSrcweir         ComponentBackendDb::Data data;
1781*cdf0e10cSrcweir         data.javaTypeLibrary = false;
1782*cdf0e10cSrcweir                 css::uno::Reference< css::uno::XComponentContext > context;
1783*cdf0e10cSrcweir         if (startup) {
1784*cdf0e10cSrcweir             context = that->getComponentContext();
1785*cdf0e10cSrcweir         } else {
1786*cdf0e10cSrcweir             context.set(that->getObject(url), css::uno::UNO_QUERY);
1787*cdf0e10cSrcweir             if (!context.is()) {
1788*cdf0e10cSrcweir                 context.set(
1789*cdf0e10cSrcweir                     that->insertObject(
1790*cdf0e10cSrcweir                         url,
1791*cdf0e10cSrcweir                         raise_uno_process(
1792*cdf0e10cSrcweir                             that->getComponentContext(), abortChannel)),
1793*cdf0e10cSrcweir                     css::uno::UNO_QUERY_THROW);
1794*cdf0e10cSrcweir             }
1795*cdf0e10cSrcweir         }
1796*cdf0e10cSrcweir 
1797*cdf0e10cSrcweir         std::vector< css::uno::Reference< css::uno::XInterface > > factories;
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir         css::uno::Reference< css::registry::XSimpleRegistry > registry(
1800*cdf0e10cSrcweir             css::uno::Reference< css::lang::XMultiComponentFactory >(
1801*cdf0e10cSrcweir                 that->getComponentContext()->getServiceManager(),
1802*cdf0e10cSrcweir                 css::uno::UNO_SET_THROW)->createInstanceWithContext(
1803*cdf0e10cSrcweir                     rtl::OUString(
1804*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
1805*cdf0e10cSrcweir                             "com.sun.star.registry.SimpleRegistry")),
1806*cdf0e10cSrcweir                     that->getComponentContext()),
1807*cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
1808*cdf0e10cSrcweir         registry->open(expandUnoRcUrl(url), true, false);
1809*cdf0e10cSrcweir         getMyBackend()->extractComponentData(
1810*cdf0e10cSrcweir             context,
1811*cdf0e10cSrcweir             that->openRegistryKey(
1812*cdf0e10cSrcweir                 registry->getRootKey(),
1813*cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IMPLEMENTATIONS"))),
1814*cdf0e10cSrcweir             &data, &factories, 0, 0);
1815*cdf0e10cSrcweir         registry->close();
1816*cdf0e10cSrcweir         if (!startup) {
1817*cdf0e10cSrcweir             that->componentLiveInsertion(data, factories);
1818*cdf0e10cSrcweir         }
1819*cdf0e10cSrcweir         that->addDataToDb(url, data);
1820*cdf0e10cSrcweir         that->addToUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1821*cdf0e10cSrcweir     } else { // revoke
1822*cdf0e10cSrcweir         that->removeFromUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1823*cdf0e10cSrcweir         if (!startup) {
1824*cdf0e10cSrcweir             that->componentLiveRemoval(that->readDataFromDb(url));
1825*cdf0e10cSrcweir         }
1826*cdf0e10cSrcweir         that->releaseObject(url);
1827*cdf0e10cSrcweir         that->revokeEntryFromDb(url);
1828*cdf0e10cSrcweir     }
1829*cdf0e10cSrcweir }
1830*cdf0e10cSrcweir 
1831*cdf0e10cSrcweir BackendImpl::ComponentsPackageImpl::ComponentsPackageImpl(
1832*cdf0e10cSrcweir     ::rtl::Reference<PackageRegistryBackend> const & myBackend,
1833*cdf0e10cSrcweir     OUString const & url, OUString const & name,
1834*cdf0e10cSrcweir     Reference<deployment::XPackageTypeInfo> const & xPackageType,
1835*cdf0e10cSrcweir     bool bRemoved, OUString const & identifier)
1836*cdf0e10cSrcweir     : Package( myBackend, url, name, name /* display-name */,
1837*cdf0e10cSrcweir                xPackageType, bRemoved, identifier)
1838*cdf0e10cSrcweir {}
1839*cdf0e10cSrcweir 
1840*cdf0e10cSrcweir } // anon namespace
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
1843*cdf0e10cSrcweir sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
1844*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
1845*cdf0e10cSrcweir     serviceBI,
1846*cdf0e10cSrcweir     IMPLEMENTATION_NAME,
1847*cdf0e10cSrcweir     BACKEND_SERVICE_NAME );
1848*cdf0e10cSrcweir 
1849*cdf0e10cSrcweir } // namespace component
1850*cdf0e10cSrcweir } // namespace backend
1851*cdf0e10cSrcweir } // namespace dp_registry
1852*cdf0e10cSrcweir 
1853*cdf0e10cSrcweir 
1854