1*2c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2c696243SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2c696243SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2c696243SAndrew Rist  * distributed with this work for additional information
6*2c696243SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2c696243SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2c696243SAndrew Rist  * "License"); you may not use this file except in compliance
9*2c696243SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2c696243SAndrew Rist  *
11*2c696243SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2c696243SAndrew Rist  *
13*2c696243SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2c696243SAndrew Rist  * software distributed under the License is distributed on an
15*2c696243SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2c696243SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2c696243SAndrew Rist  * specific language governing permissions and limitations
18*2c696243SAndrew Rist  * under the License.
19*2c696243SAndrew Rist  *
20*2c696243SAndrew Rist  *************************************************************/
21*2c696243SAndrew Rist 
22*2c696243SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_scripting.hxx"
26cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
27cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
28cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
29cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <util/util.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "MasterScriptProviderFactory.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::script;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace func_provider
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
MasterScriptProviderFactory(Reference<XComponentContext> const & xComponentContext)43cdf0e10cSrcweir MasterScriptProviderFactory::MasterScriptProviderFactory(
44cdf0e10cSrcweir     Reference< XComponentContext > const & xComponentContext )
45cdf0e10cSrcweir     : m_xComponentContext( xComponentContext )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
~MasterScriptProviderFactory()49cdf0e10cSrcweir MasterScriptProviderFactory::~MasterScriptProviderFactory()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //############################################################################
55cdf0e10cSrcweir // Implementation of XScriptProviderFactory
56cdf0e10cSrcweir //############################################################################
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir Reference< provider::XScriptProvider > SAL_CALL
createScriptProvider(const Any & context)60cdf0e10cSrcweir MasterScriptProviderFactory::createScriptProvider( const Any& context ) throw ( lang::IllegalArgumentException, RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     Reference< provider::XScriptProvider > xMsp( getActiveMSPList() ->getMSPFromAnyContext( context ), UNO_QUERY_THROW );
63cdf0e10cSrcweir     return xMsp;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //############################################################################
67cdf0e10cSrcweir // Helper methods
68cdf0e10cSrcweir //############################################################################
69cdf0e10cSrcweir 
70cdf0e10cSrcweir const rtl::Reference< ActiveMSPList > &
getActiveMSPList() const71cdf0e10cSrcweir MasterScriptProviderFactory::getActiveMSPList() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     if ( !m_MSPList.is() )
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
76cdf0e10cSrcweir         if ( !m_MSPList.is() )
77cdf0e10cSrcweir            m_MSPList = new ActiveMSPList( m_xComponentContext );
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     return m_MSPList;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //############################################################################
83cdf0e10cSrcweir // Namespace global methods for setting up MasterScriptProviderFactory service
84cdf0e10cSrcweir //############################################################################
85cdf0e10cSrcweir 
86cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL
mspf_getSupportedServiceNames()87cdf0e10cSrcweir mspf_getSupportedServiceNames( )
88cdf0e10cSrcweir     SAL_THROW( () )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     ::rtl::OUString str_name = ::rtl::OUString::createFromAscii(
91cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProviderFactory");
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     return Sequence< ::rtl::OUString >( &str_name, 1 );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir ::rtl::OUString SAL_CALL
mspf_getImplementationName()97cdf0e10cSrcweir mspf_getImplementationName( )
98cdf0e10cSrcweir     SAL_THROW( () )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii(
101cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProviderFactory");
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir Reference< XInterface > SAL_CALL
mspf_create(Reference<XComponentContext> const & xComponentContext)105cdf0e10cSrcweir mspf_create( Reference< XComponentContext > const & xComponentContext )
106cdf0e10cSrcweir     SAL_THROW( (Exception) )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     return static_cast< ::cppu::OWeakObject * >(
109cdf0e10cSrcweir         new MasterScriptProviderFactory( xComponentContext ) );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //############################################################################
113cdf0e10cSrcweir // Implementation of XServiceInfo
114cdf0e10cSrcweir //############################################################################
115cdf0e10cSrcweir 
116cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getImplementationName()117cdf0e10cSrcweir MasterScriptProviderFactory::getImplementationName()
118cdf0e10cSrcweir     throw (RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     return mspf_getImplementationName();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL
getSupportedServiceNames()124cdf0e10cSrcweir MasterScriptProviderFactory::getSupportedServiceNames()
125cdf0e10cSrcweir     throw (RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     return mspf_getSupportedServiceNames();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
supportsService(::rtl::OUString const & serviceName)130cdf0e10cSrcweir sal_Bool MasterScriptProviderFactory::supportsService(
131cdf0e10cSrcweir     ::rtl::OUString const & serviceName )
132cdf0e10cSrcweir     throw (RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir //     check();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     Sequence< ::rtl::OUString > supported_services(
137cdf0e10cSrcweir         getSupportedServiceNames() );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     ::rtl::OUString const * ar = supported_services.getConstArray();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     for ( sal_Int32 pos = supported_services.getLength(); pos--; )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         if (ar[ pos ].equals( serviceName ))
144cdf0e10cSrcweir             return true;
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir     return false;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir } // namespace browsenodefactory
150