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 
27cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
28cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "StorageBridge.hxx"
31cdf0e10cSrcweir #include <util/util.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::rtl;
34cdf0e10cSrcweir using namespace ::osl;
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::drafts::com::sun::star::script::framework;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace scripting_runtimemgr
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir const char* const SCRIPTIMPLACCESS_SERVICE =
43cdf0e10cSrcweir     "drafts.com.sun.star.script.framework.storage.StorageProxy";
44cdf0e10cSrcweir const char* const SCRIPTSTORAGEMANAGER_SERVICE =
45cdf0e10cSrcweir     "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
46cdf0e10cSrcweir const int STORAGEID = 0;
47cdf0e10cSrcweir const int STORAGEPROXY = 0;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //*************************************************************************
51cdf0e10cSrcweir // StorageBridge Constructor
StorageBridge(const Reference<XComponentContext> & xContext,sal_Int32 sid)52cdf0e10cSrcweir StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext,
53cdf0e10cSrcweir                               sal_Int32 sid ) : m_xContext( xContext, UNO_SET_THROW ), m_sid( sid )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     try
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         initStorage();
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir     catch ( RuntimeException & re )
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " );
62cdf0e10cSrcweir         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //*************************************************************************
67cdf0e10cSrcweir void
initStorage()68cdf0e10cSrcweir StorageBridge::initStorage() throw ( ::com::sun::star::uno::RuntimeException )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     try
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         Reference< lang::XMultiComponentFactory > xMultiComFac( m_xContext->getServiceManager(), UNO_SET_THROW );
73cdf0e10cSrcweir         Reference< XInterface > temp( m_xContext->getValueByName(
74cdf0e10cSrcweir                     OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW );
75cdf0e10cSrcweir         Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW );
76cdf0e10cSrcweir         Reference< XInterface > xScriptStorage( xScriptStorageManager->getScriptStorage( m_sid ), UNO_SET_THROW );
77cdf0e10cSrcweir         m_xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW );
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     catch ( RuntimeException & re )
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
82cdf0e10cSrcweir         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir     catch ( Exception & e )
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
87cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir }
90cdf0e10cSrcweir //*************************************************************************
91cdf0e10cSrcweir Sequence< ::rtl::OUString >
getScriptLogicalNames()92cdf0e10cSrcweir StorageBridge::getScriptLogicalNames()
93cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
94cdf0e10cSrcweir         RuntimeException )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" );
97cdf0e10cSrcweir     Sequence < ::rtl::OUString  > results;
98cdf0e10cSrcweir     try
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         results = m_xScriptInfoAccess->getScriptLogicalNames();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir     catch ( Exception e )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " );
105cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir     return results;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //*************************************************************************
111cdf0e10cSrcweir Sequence < Reference< storage::XScriptInfo > >
getImplementations(const::rtl::OUString & queryURI)112cdf0e10cSrcweir StorageBridge::getImplementations( const ::rtl::OUString& queryURI )
113cdf0e10cSrcweir throw ( lang::IllegalArgumentException, RuntimeException )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     OSL_TRACE( "In StorageBridge getImplementations...\n" );
116cdf0e10cSrcweir     Sequence < Reference< storage::XScriptInfo > > results;
117cdf0e10cSrcweir     try
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         results = m_xScriptInfoAccess->getImplementations( queryURI );
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir     catch ( Exception e )
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         OUString temp = OUSTR( "StorageBridge::getImplementations: " );
124cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     return results;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir }// namespace
129