12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir #include "dp_sfwk.hrc"
27cdf0e10cSrcweir #include "dp_backend.h"
28cdf0e10cSrcweir #include "dp_ucb.h"
29cdf0e10cSrcweir #include "dp_parceldesc.hxx"
30cdf0e10cSrcweir #include "rtl/uri.hxx"
31cdf0e10cSrcweir #include "ucbhelper/content.hxx"
32cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
33cdf0e10cSrcweir #include "comphelper/servicedecl.hxx"
34cdf0e10cSrcweir #include "svl/inettype.hxx"
35cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
36cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
37cdf0e10cSrcweir #include <memory>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::dp_misc;
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
44cdf0e10cSrcweir using namespace ::com::sun::star::script;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using ::rtl::OUString;
47cdf0e10cSrcweir namespace css = ::com::sun::star;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace dp_registry
50cdf0e10cSrcweir {
51cdf0e10cSrcweir namespace backend
52cdf0e10cSrcweir {
53cdf0e10cSrcweir namespace sfwk
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //==============================================================================
57cdf0e10cSrcweir class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     class PackageImpl : public ::dp_registry::backend::Package
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         BackendImpl * getMyBackend() const;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         Reference< container::XNameContainer > m_xNameCntrPkgHandler;
64cdf0e10cSrcweir         OUString m_descr;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         void initPackageHandler();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         // Package
69cdf0e10cSrcweir         virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
70cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
71cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
72cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
73cdf0e10cSrcweir         virtual void processPackage_(
74cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
75cdf0e10cSrcweir             bool registerPackage,
76cdf0e10cSrcweir             bool startup,
77cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
78cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     public:
81cdf0e10cSrcweir         PackageImpl(
82cdf0e10cSrcweir             ::rtl::Reference<BackendImpl> const & myBackend,
83cdf0e10cSrcweir             OUString const & url, OUString const & libType, bool bRemoved,
84cdf0e10cSrcweir             OUString const & identifier);
85cdf0e10cSrcweir         // XPackage
86cdf0e10cSrcweir         virtual OUString SAL_CALL getDescription() throw (RuntimeException);
87cdf0e10cSrcweir         virtual OUString SAL_CALL getLicenseText() throw (RuntimeException);
88cdf0e10cSrcweir     };
89cdf0e10cSrcweir     friend class PackageImpl;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     // PackageRegistryBackend
92cdf0e10cSrcweir     virtual Reference<deployment::XPackage> bindPackage_(
93cdf0e10cSrcweir         OUString const & url, OUString const & mediaType,
94cdf0e10cSrcweir         sal_Bool bRemoved, OUString const & identifier,
95cdf0e10cSrcweir         Reference<XCommandEnvironment> const & xCmdEnv );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xTypeInfo;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir     BackendImpl(
102cdf0e10cSrcweir         Sequence<Any> const & args,
103cdf0e10cSrcweir         Reference<XComponentContext> const & xComponentContext );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // XPackageRegistry
106cdf0e10cSrcweir     virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
107cdf0e10cSrcweir     getSupportedPackageTypes() throw (RuntimeException);
108cdf0e10cSrcweir     virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
109cdf0e10cSrcweir         throw (deployment::DeploymentException,
110cdf0e10cSrcweir                uno::RuntimeException);
111cdf0e10cSrcweir };
112cdf0e10cSrcweir 
getMyBackend() const113cdf0e10cSrcweir BackendImpl * BackendImpl::PackageImpl::getMyBackend() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
116cdf0e10cSrcweir     if (NULL == pBackend)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         //May throw a DisposedException
119cdf0e10cSrcweir         check();
120cdf0e10cSrcweir         //We should never get here...
121cdf0e10cSrcweir         throw RuntimeException(
122cdf0e10cSrcweir             OUSTR("Failed to get the BackendImpl"),
123cdf0e10cSrcweir             static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir     return pBackend;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir //______________________________________________________________________________
getDescription()128cdf0e10cSrcweir OUString BackendImpl::PackageImpl::getDescription() throw (RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     if (m_descr.getLength() == 0)
131cdf0e10cSrcweir         return Package::getDescription();
132cdf0e10cSrcweir     else
133cdf0e10cSrcweir         return m_descr;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //______________________________________________________________________________
getLicenseText()137cdf0e10cSrcweir OUString BackendImpl::PackageImpl::getLicenseText() throw (RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     return Package::getDescription();
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //______________________________________________________________________________
PackageImpl(::rtl::Reference<BackendImpl> const & myBackend,OUString const & url,OUString const & libType,bool bRemoved,OUString const & identifier)143cdf0e10cSrcweir BackendImpl::PackageImpl::PackageImpl(
144cdf0e10cSrcweir     ::rtl::Reference<BackendImpl> const & myBackend,
145cdf0e10cSrcweir     OUString const & url, OUString const & libType, bool bRemoved,
146cdf0e10cSrcweir     OUString const & identifier)
147cdf0e10cSrcweir     : Package( myBackend.get(), url, OUString(), OUString(),
148cdf0e10cSrcweir                myBackend->m_xTypeInfo, bRemoved, identifier),
149cdf0e10cSrcweir       m_descr(libType)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     initPackageHandler();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     sal_Int32 segmEnd = url.getLength();
154cdf0e10cSrcweir     if (url.getLength() > 0 && url[ url.getLength() - 1 ] == '/')
155cdf0e10cSrcweir         --segmEnd;
156cdf0e10cSrcweir     sal_Int32 segmStart = (url.lastIndexOf( '/', segmEnd ) + 1);
157cdf0e10cSrcweir     if (segmStart < 0)
158cdf0e10cSrcweir         segmStart = 0;
159cdf0e10cSrcweir     // name and display name default the same:
160cdf0e10cSrcweir     m_displayName = ::rtl::Uri::decode(
161cdf0e10cSrcweir         url.copy( segmStart, segmEnd - segmStart ),
162cdf0e10cSrcweir         rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
163cdf0e10cSrcweir     m_name = m_displayName;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     dp_misc::TRACE(OUSTR("PakageImpl displayName is ") + m_displayName);
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir //______________________________________________________________________________
BackendImpl(Sequence<Any> const & args,Reference<XComponentContext> const & xComponentContext)169cdf0e10cSrcweir BackendImpl::BackendImpl(
170cdf0e10cSrcweir     Sequence<Any> const & args,
171cdf0e10cSrcweir     Reference<XComponentContext> const & xComponentContext )
172cdf0e10cSrcweir     : PackageRegistryBackend( args, xComponentContext ),
173cdf0e10cSrcweir       m_xTypeInfo( new Package::TypeInfo(
174cdf0e10cSrcweir                        OUSTR("application/vnd.sun.star.framework-script"),
175cdf0e10cSrcweir                        OUString() /* no file filter */,
176cdf0e10cSrcweir                        OUSTR("Scripting Framework Script Library"),
177cdf0e10cSrcweir                        RID_IMG_SCRIPTLIB, RID_IMG_SCRIPTLIB_HC ) )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     if (! transientMode())
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir /*
182cdf0e10cSrcweir         if (office_is_running())
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             Reference<XComponentContext> xContext( getComponentContext() );
185cdf0e10cSrcweir             m_xScriptLibs.set(
186cdf0e10cSrcweir                 xContext->getServiceManager()->createInstanceWithContext(
187cdf0e10cSrcweir                     OUSTR("com.sun.star."
188cdf0e10cSrcweir                           "script.ApplicationScriptLibraryContainer"),
189cdf0e10cSrcweir                     xContext ), UNO_QUERY_THROW );
190cdf0e10cSrcweir             m_xDialogLibs.set(
191cdf0e10cSrcweir                 xContext->getServiceManager()->createInstanceWithContext(
192cdf0e10cSrcweir                     OUSTR("com.sun.star."
193cdf0e10cSrcweir                           "script.ApplicationDialogLibraryContainer"),
194cdf0e10cSrcweir                     xContext ), UNO_QUERY_THROW );
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir         else
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             OUString basic_path(
199cdf0e10cSrcweir                 m_eContext == CONTEXT_USER
200*910823aeSJürgen Schmidt                 ? OUSTR("vnd.sun.star.expand:${$OOO_BASE_DIR/program/"
201cdf0e10cSrcweir                         SAL_CONFIGFILE("bootstrap")
202cdf0e10cSrcweir                         ":UserInstallation}/user/basic")
203*910823aeSJürgen Schmidt                 : OUSTR("vnd.sun.star.expand:${$OOO_BASE_DIR/program/"
204cdf0e10cSrcweir                         SAL_CONFIGFILE("bootstrap")
205cdf0e10cSrcweir                         ":BaseInstallation}/share/basic") );
206cdf0e10cSrcweir             m_basic_script_libs.reset(
207cdf0e10cSrcweir                 new LibraryContainer(
208cdf0e10cSrcweir                     makeURL( basic_path, OUSTR("script.xlc") ),
209cdf0e10cSrcweir                     getMutex(),
210cdf0e10cSrcweir                     getComponentContext() ) );
211cdf0e10cSrcweir             m_dialog_libs.reset(
212cdf0e10cSrcweir                 new LibraryContainer(
213cdf0e10cSrcweir                     makeURL( basic_path, OUSTR("dialog.xlc") ),
214cdf0e10cSrcweir                     getMutex(),
215cdf0e10cSrcweir                     getComponentContext() ) );
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir */
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // XPackageRegistry
224cdf0e10cSrcweir //______________________________________________________________________________
225cdf0e10cSrcweir Sequence< Reference<deployment::XPackageTypeInfo> >
getSupportedPackageTypes()226cdf0e10cSrcweir BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     return Sequence< Reference<deployment::XPackageTypeInfo> >(&m_xTypeInfo, 1);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
packageRemoved(OUString const &,OUString const &)231cdf0e10cSrcweir void BackendImpl::packageRemoved(OUString const & /*url*/, OUString const & /*mediaType*/)
232cdf0e10cSrcweir         throw (deployment::DeploymentException,
233cdf0e10cSrcweir                uno::RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir // PackageRegistryBackend
238cdf0e10cSrcweir //______________________________________________________________________________
bindPackage_(OUString const & url,OUString const & mediaType_,sal_Bool bRemoved,OUString const & identifier,Reference<XCommandEnvironment> const & xCmdEnv)239cdf0e10cSrcweir Reference<deployment::XPackage> BackendImpl::bindPackage_(
240cdf0e10cSrcweir     OUString const & url, OUString const & mediaType_, sal_Bool bRemoved,
241cdf0e10cSrcweir     OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     OUString mediaType( mediaType_ );
244cdf0e10cSrcweir     if (mediaType.getLength() == 0)
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         // detect media-type:
247cdf0e10cSrcweir         ::ucbhelper::Content ucbContent;
248cdf0e10cSrcweir         if (create_ucb_content( &ucbContent, url, xCmdEnv ) &&
249cdf0e10cSrcweir             ucbContent.isFolder())
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             // probe for parcel-descriptor.xml:
252cdf0e10cSrcweir             if (create_ucb_content(
253cdf0e10cSrcweir                     0, makeURL( url, OUSTR("parcel-descriptor.xml") ),
254cdf0e10cSrcweir                     xCmdEnv, false /* no throw */ ))
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 mediaType = OUSTR("application/vnd.sun.star.framework-script");
257cdf0e10cSrcweir             }
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         if (mediaType.getLength() == 0)
260cdf0e10cSrcweir             throw lang::IllegalArgumentException(
261cdf0e10cSrcweir                 StrCannotDetectMediaType::get() + url,
262cdf0e10cSrcweir                 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     String type, subType;
266cdf0e10cSrcweir     INetContentTypeParameterList params;
267cdf0e10cSrcweir     if (INetContentTypes::parse( mediaType, type, subType, &params ))
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         if (type.EqualsIgnoreCaseAscii("application"))
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.framework-script"))
272cdf0e10cSrcweir             {
273cdf0e10cSrcweir                 OUString lang = OUString::createFromAscii("Script");
274cdf0e10cSrcweir                 OUString sParcelDescURL = makeURL(
275cdf0e10cSrcweir                     url, OUSTR("parcel-descriptor.xml") );
276cdf0e10cSrcweir 
277cdf0e10cSrcweir                 ::ucbhelper::Content ucb_content;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir                 if (create_ucb_content( &ucb_content, sParcelDescURL,
280cdf0e10cSrcweir                         xCmdEnv, false /* no throw */ ))
281cdf0e10cSrcweir                 {
282cdf0e10cSrcweir                     ParcelDescDocHandler* pHandler =
283cdf0e10cSrcweir                         new ParcelDescDocHandler();
284cdf0e10cSrcweir                     Reference< xml::sax::XDocumentHandler >
285cdf0e10cSrcweir                         xDocHandler = pHandler;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir                     Reference<XComponentContext>
288cdf0e10cSrcweir                         xContext( getComponentContext() );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir                     Reference< xml::sax::XParser > xParser(
291cdf0e10cSrcweir                       xContext->getServiceManager()->createInstanceWithContext(
292cdf0e10cSrcweir                             OUSTR("com.sun.star.xml.sax.Parser"), xContext ),
293cdf0e10cSrcweir                                 UNO_QUERY_THROW );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir                     xParser->setDocumentHandler( xDocHandler );
296cdf0e10cSrcweir                     xml::sax::InputSource source;
297cdf0e10cSrcweir                     source.aInputStream = ucb_content.openStream();
298cdf0e10cSrcweir                     source.sSystemId = ucb_content.getURL();
299cdf0e10cSrcweir                     xParser->parseStream( source );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir                     if ( pHandler->isParsed() )
302cdf0e10cSrcweir                     {
303cdf0e10cSrcweir                         lang = pHandler->getParcelLanguage();
304cdf0e10cSrcweir                     }
305cdf0e10cSrcweir                 }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir                 OUString sfwkLibType = getResourceString( RID_STR_SFWK_LIB );
308cdf0e10cSrcweir                 // replace %MACRONAME placeholder with language name
309cdf0e10cSrcweir                 OUString MACRONAME( OUSTR("%MACROLANG" ) );
310cdf0e10cSrcweir                 sal_Int32 startOfReplace = sfwkLibType.indexOf( MACRONAME );
311cdf0e10cSrcweir                 sal_Int32 charsToReplace = MACRONAME.getLength();
312cdf0e10cSrcweir                 sfwkLibType = sfwkLibType.replaceAt( startOfReplace, charsToReplace, lang );
313cdf0e10cSrcweir                 dp_misc::TRACE("******************************\n");
314cdf0e10cSrcweir                 dp_misc::TRACE(OUSTR(" BackEnd detected lang = ") + lang + OUSTR("\n"));
315cdf0e10cSrcweir                 dp_misc::TRACE(OUSTR(" for url ") + sParcelDescURL + OUSTR("\n") );
316cdf0e10cSrcweir                 dp_misc::TRACE("******************************\n");
317cdf0e10cSrcweir                 return new PackageImpl( this, url, sfwkLibType, bRemoved, identifier);
318cdf0e10cSrcweir             }
319cdf0e10cSrcweir         }
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir     throw lang::IllegalArgumentException(
322cdf0e10cSrcweir         StrUnsupportedMediaType::get() + mediaType,
323cdf0e10cSrcweir         static_cast<OWeakObject *>(this),
324cdf0e10cSrcweir         static_cast<sal_Int16>(-1) );
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir //##############################################################################
328cdf0e10cSrcweir 
initPackageHandler()329cdf0e10cSrcweir void BackendImpl::PackageImpl:: initPackageHandler()
330cdf0e10cSrcweir {
331cdf0e10cSrcweir     if (m_xNameCntrPkgHandler.is())
332cdf0e10cSrcweir         return;
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
335cdf0e10cSrcweir     Any aContext;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     if ( that->m_eContext == CONTEXT_USER )
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         aContext  <<= OUSTR("user");
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_SHARED )
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         aContext  <<= OUSTR("share");
344cdf0e10cSrcweir     }
345cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_BUNDLED )
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         aContext  <<= OUSTR("bundled");
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_BUNDLED_PREREG )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         aContext  <<= OUSTR("bundled_prereg");
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     else
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         OSL_ASSERT( 0 );
357cdf0e10cSrcweir         // NOT supported at the momemtn // TODO
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     Reference< provider::XScriptProviderFactory > xFac(
361cdf0e10cSrcweir         that->getComponentContext()->getValueByName(
362cdf0e10cSrcweir             OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     if ( xFac.is() )
365cdf0e10cSrcweir     {
366cdf0e10cSrcweir         Reference< container::XNameContainer > xName( xFac->createScriptProvider( aContext ), UNO_QUERY );
367cdf0e10cSrcweir         if ( xName.is() )
368cdf0e10cSrcweir         {
369cdf0e10cSrcweir             m_xNameCntrPkgHandler.set( xName );
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir     // TODO what happens if above fails??
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir // Package
376cdf0e10cSrcweir //______________________________________________________________________________
377cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> >
isRegistered_(::osl::ResettableMutexGuard &,::rtl::Reference<AbortChannel> const &,Reference<XCommandEnvironment> const &)378cdf0e10cSrcweir BackendImpl::PackageImpl::isRegistered_(
379cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
380cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
381cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     return beans::Optional< beans::Ambiguous<sal_Bool> >(
384cdf0e10cSrcweir         true /* IsPresent */,
385cdf0e10cSrcweir         beans::Ambiguous<sal_Bool>(
386cdf0e10cSrcweir             m_xNameCntrPkgHandler.is() && m_xNameCntrPkgHandler->hasByName(
387cdf0e10cSrcweir                 m_url ),
388cdf0e10cSrcweir             false /* IsAmbiguous */ ) );
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir //______________________________________________________________________________
processPackage_(::osl::ResettableMutexGuard &,bool doRegisterPackage,bool,::rtl::Reference<AbortChannel> const &,Reference<XCommandEnvironment> const &)392cdf0e10cSrcweir void BackendImpl::PackageImpl::processPackage_(
393cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
394cdf0e10cSrcweir     bool doRegisterPackage,
395cdf0e10cSrcweir     bool /* startup */,
396cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
397cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     if ( !m_xNameCntrPkgHandler.is() )
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         dp_misc::TRACE("no package handler!!!!\n");
402cdf0e10cSrcweir         throw RuntimeException( OUSTR("No package Handler " ),
403cdf0e10cSrcweir             Reference< XInterface >() );
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     if (doRegisterPackage)
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         // will throw if it fails
409cdf0e10cSrcweir         m_xNameCntrPkgHandler->insertByName( m_url, makeAny( Reference< XPackage >(this) ) );
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     }
412cdf0e10cSrcweir     else // revokePackage()
413cdf0e10cSrcweir     {
414cdf0e10cSrcweir         m_xNameCntrPkgHandler->removeByName( m_url );
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
419cdf0e10cSrcweir sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
420cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
421cdf0e10cSrcweir     serviceBI,
422cdf0e10cSrcweir     "com.sun.star.comp.deployment.sfwk.PackageRegistryBackend",
423cdf0e10cSrcweir     BACKEND_SERVICE_NAME );
424cdf0e10cSrcweir 
425cdf0e10cSrcweir } // namespace sfwk
426cdf0e10cSrcweir } // namespace backend
427cdf0e10cSrcweir } // namespace dp_registry
428cdf0e10cSrcweir 
429