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