Update ooo320-m1
[ooovba.git] / scripting / source / runtimemgr / StorageBridge.cxx
blob158ce5d60182c1481f2af2bc5be80d8921b952a7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StorageBridge.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
34 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
35 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
37 #include "StorageBridge.hxx"
38 #include <util/util.hxx>
40 using namespace ::rtl;
41 using namespace ::osl;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::drafts::com::sun::star::script::framework;
46 namespace scripting_runtimemgr
49 const char* const SCRIPTIMPLACCESS_SERVICE =
50 "drafts.com.sun.star.script.framework.storage.StorageProxy";
51 const char* const SCRIPTSTORAGEMANAGER_SERVICE =
52 "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
53 const int STORAGEID = 0;
54 const int STORAGEPROXY = 0;
57 //*************************************************************************
58 // StorageBridge Constructor
59 StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext,
60 sal_Int32 sid ) : m_xContext( xContext ), m_sid( sid )
62 validateXRef( m_xContext, "StorageBridge::StorageBridge: invalid context" );
63 try
65 initStorage();
67 catch ( RuntimeException & re )
69 OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " );
70 throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
74 //*************************************************************************
75 void
76 StorageBridge::initStorage() throw ( ::com::sun::star::uno::RuntimeException )
78 try
80 Reference< lang::XMultiComponentFactory > xMultiComFac =
81 m_xContext->getServiceManager();
82 validateXRef( xMultiComFac,
83 "StorageBridge::StorageBridge: cannot get multicomponentfactory from multiservice factory" );
84 Reference< XInterface > temp;
86 Any a = m_xContext->getValueByName(
87 OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) );
88 if ( sal_False == ( a >>= temp ) )
90 throw RuntimeException(
91 OUSTR( "StorageBridge::StorageBridge: could not obtain ScriptStorageManager singleton" ),
92 Reference< XInterface >() );
94 validateXRef( temp,
95 "StorageBridge::StorageBridge: cannot get Storage service" );
96 Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW );
97 validateXRef( xScriptStorageManager,
98 "StorageBridge::StorageBridge: cannot get Script Storage Manager service" );
99 Reference< XInterface > xScriptStorage =
100 xScriptStorageManager->getScriptStorage( m_sid );
101 validateXRef( xScriptStorage,
102 "StorageBridge::StorageBridge: cannot get Script Storage service" );
103 m_xScriptInfoAccess =
104 Reference< storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW );
106 catch ( RuntimeException & re )
108 OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
109 throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
111 catch ( Exception & e )
113 OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
114 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
117 //*************************************************************************
118 Sequence< ::rtl::OUString >
119 StorageBridge::getScriptLogicalNames()
120 throw ( lang::IllegalArgumentException,
121 RuntimeException )
123 OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" );
124 Sequence < ::rtl::OUString > results;
127 results = m_xScriptInfoAccess->getScriptLogicalNames();
129 catch ( Exception e )
131 OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " );
132 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
134 return results;
137 //*************************************************************************
138 Sequence < Reference< storage::XScriptInfo > >
139 StorageBridge::getImplementations( const ::rtl::OUString& queryURI )
140 throw ( lang::IllegalArgumentException, RuntimeException )
142 OSL_TRACE( "In StorageBridge getImplementations...\n" );
143 Sequence < Reference< storage::XScriptInfo > > results;
146 results = m_xScriptInfoAccess->getImplementations( queryURI );
148 catch ( Exception e )
150 OUString temp = OUSTR( "StorageBridge::getImplementations: " );
151 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
153 return results;
155 }// namespace