1*6998d047SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6998d047SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6998d047SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6998d047SAndrew Rist  * distributed with this work for additional information
6*6998d047SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6998d047SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6998d047SAndrew Rist  * "License"); you may not use this file except in compliance
9*6998d047SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6998d047SAndrew Rist  *
11*6998d047SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6998d047SAndrew Rist  *
13*6998d047SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6998d047SAndrew Rist  * software distributed under the License is distributed on an
15*6998d047SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6998d047SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6998d047SAndrew Rist  * specific language governing permissions and limitations
18*6998d047SAndrew Rist  * under the License.
19*6998d047SAndrew Rist  *
20*6998d047SAndrew Rist  *************************************************************/
21*6998d047SAndrew Rist 
22*6998d047SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_
25cdf0e10cSrcweir #define _FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
34cdf0e10cSrcweir #include <com/sun/star/document/XScriptInvocationContext.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProvider.hpp>
39cdf0e10cSrcweir #include <com/sun/star/script/browse/XBrowseNode.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "ProviderCache.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace func_provider
44cdf0e10cSrcweir {
45cdf0e10cSrcweir // for simplification
46cdf0e10cSrcweir #define css ::com::sun::star
47cdf0e10cSrcweir 
48cdf0e10cSrcweir  typedef ::cppu::WeakImplHelper5<
49cdf0e10cSrcweir      css::script::provider::XScriptProvider,
50cdf0e10cSrcweir      css::script::browse::XBrowseNode, css::lang::XServiceInfo,
51cdf0e10cSrcweir      css::lang::XInitialization,
52cdf0e10cSrcweir      css::container::XNameContainer > t_helper;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class MasterScriptProvider :
55cdf0e10cSrcweir             public t_helper
56cdf0e10cSrcweir {
57cdf0e10cSrcweir public:
58cdf0e10cSrcweir     MasterScriptProvider(
59cdf0e10cSrcweir         const css::uno::Reference< css::uno::XComponentContext >
60cdf0e10cSrcweir         & xContext ) throw( css::uno::RuntimeException );
61cdf0e10cSrcweir     ~MasterScriptProvider();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     // XServiceInfo implementation
64cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName( )
65cdf0e10cSrcweir         throw( css::uno::RuntimeException );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     // XBrowseNode implementation
68cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getName()
69cdf0e10cSrcweir         throw ( css::uno::RuntimeException );
70cdf0e10cSrcweir     virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes()
71cdf0e10cSrcweir         throw ( css::uno::RuntimeException );
72cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasChildNodes()
73cdf0e10cSrcweir         throw ( css::uno::RuntimeException );
74cdf0e10cSrcweir     virtual sal_Int16 SAL_CALL getType()
75cdf0e10cSrcweir         throw ( css::uno::RuntimeException );
76cdf0e10cSrcweir     // XNameContainer
77cdf0e10cSrcweir     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ) throw ( css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, css::uno::RuntimeException);
78cdf0e10cSrcweir     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     // XNameReplace
81cdf0e10cSrcweir     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ) throw ( css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException);
82cdf0e10cSrcweir     // XNameAccess
83cdf0e10cSrcweir     virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException);
84cdf0e10cSrcweir     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw ( css::uno::RuntimeException);
85cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     // XElementAccess
88cdf0e10cSrcweir     virtual css::uno::Type SAL_CALL getElementType(  ) throw ( css::uno::RuntimeException);
89cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements(  ) throw ( css::uno::RuntimeException);
90cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
91cdf0e10cSrcweir         throw( css::uno::RuntimeException );
92cdf0e10cSrcweir     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
93cdf0e10cSrcweir         throw( css::uno::RuntimeException );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     // XScriptProvider implementation
96cdf0e10cSrcweir     virtual css::uno::Reference < css::script::provider::XScript > SAL_CALL
97cdf0e10cSrcweir         getScript( const ::rtl::OUString& scriptURI )
98cdf0e10cSrcweir         throw( css::script::provider::ScriptFrameworkErrorException,
99cdf0e10cSrcweir                css::uno::RuntimeException );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /**
102cdf0e10cSrcweir      *  XInitialise implementation
103cdf0e10cSrcweir      *
104cdf0e10cSrcweir      * @param args expected to contain a single ::rtl::OUString
105cdf0e10cSrcweir      * containing the URI
106cdf0e10cSrcweir      */
107cdf0e10cSrcweir     virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any > & args )
108cdf0e10cSrcweir         throw ( css::uno::Exception, css::uno::RuntimeException);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     // Public method to return all Language Providers in this MasterScriptProviders
111cdf0e10cSrcweir     // context.
112cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::script::provider::XScriptProvider > > SAL_CALL
113cdf0e10cSrcweir         getAllProviders() throw ( css::uno::RuntimeException );
114cdf0e10cSrcweir 
isPkgProvider()115cdf0e10cSrcweir     bool isPkgProvider() { return m_bIsPkgMSP; }
getPkgProvider()116cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider > getPkgProvider() { return m_xMSPPkg; }
117cdf0e10cSrcweir     // returns context string for this provider, eg
getContextString()118cdf0e10cSrcweir     ::rtl::OUString getContextString() { return m_sCtxString; }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir private:
121cdf0e10cSrcweir     ::rtl::OUString parseLocationName( const ::rtl::OUString& location );
122cdf0e10cSrcweir     void  createPkgProvider();
123cdf0e10cSrcweir     bool  isValid();
124cdf0e10cSrcweir     ::rtl::OUString getURLForModel();
125cdf0e10cSrcweir     const css::uno::Sequence< ::rtl::OUString >& getProviderNames();
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     ProviderCache* providerCache();
128cdf0e10cSrcweir     /* to obtain other services if needed */
129cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext >              m_xContext;
130cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiComponentFactory >        m_xMgr;
131cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel >                       m_xModel;
132cdf0e10cSrcweir     css::uno::Reference< css::document::XScriptInvocationContext >  m_xInvocationContext;
133cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any >                             m_sAargs;
134cdf0e10cSrcweir     ::rtl::OUString                                                 m_sNodeName;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     // This component supports XInitialization, it can be created
137cdf0e10cSrcweir     // using createInstanceXXX() or createInstanceWithArgumentsXXX using
138cdf0e10cSrcweir     // the service Mangager.
139cdf0e10cSrcweir     // Need to detect proper initialisation and validity
140cdf0e10cSrcweir     // for the object, so m_bIsValid indicates that the object is valid is set in ctor
141cdf0e10cSrcweir     // in case of createInstanceWithArgumentsXXX() called m_bIsValid is set to reset
142cdf0e10cSrcweir     // and then set to true when initialisation is complete
143cdf0e10cSrcweir     bool m_bIsValid;
144cdf0e10cSrcweir     // m_bInitialised ensure initialisation only takes place once.
145cdf0e10cSrcweir     bool m_bInitialised;
146cdf0e10cSrcweir     bool m_bIsPkgMSP;
147cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg;
148cdf0e10cSrcweir     ProviderCache* m_pPCache;
149cdf0e10cSrcweir     osl::Mutex m_mutex;
150cdf0e10cSrcweir     ::rtl::OUString m_sCtxString;
151cdf0e10cSrcweir };
152cdf0e10cSrcweir } // namespace func_provider
153cdf0e10cSrcweir #endif //_FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_
154