1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_scripting.hxx"
30 
31 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
32 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
33 
34 #include "StorageBridge.hxx"
35 #include <util/util.hxx>
36 
37 using namespace ::rtl;
38 using namespace ::osl;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::drafts::com::sun::star::script::framework;
42 
43 namespace scripting_runtimemgr
44 {
45 
46 const char* const SCRIPTIMPLACCESS_SERVICE =
47     "drafts.com.sun.star.script.framework.storage.StorageProxy";
48 const char* const SCRIPTSTORAGEMANAGER_SERVICE =
49     "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
50 const int STORAGEID = 0;
51 const int STORAGEPROXY = 0;
52 
53 
54 //*************************************************************************
55 // StorageBridge Constructor
56 StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext,
57                               sal_Int32 sid ) : m_xContext( xContext, UNO_SET_THROW ), m_sid( sid )
58 {
59     try
60     {
61         initStorage();
62     }
63     catch ( RuntimeException & re )
64     {
65         OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " );
66         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
67     }
68 }
69 
70 //*************************************************************************
71 void
72 StorageBridge::initStorage() throw ( ::com::sun::star::uno::RuntimeException )
73 {
74     try
75     {
76         Reference< lang::XMultiComponentFactory > xMultiComFac( m_xContext->getServiceManager(), UNO_SET_THROW );
77         Reference< XInterface > temp( m_xContext->getValueByName(
78                     OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW );
79         Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW );
80         Reference< XInterface > xScriptStorage( xScriptStorageManager->getScriptStorage( m_sid ), UNO_SET_THROW );
81         m_xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW );
82     }
83     catch ( RuntimeException & re )
84     {
85         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
86         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
87     }
88     catch ( Exception & e )
89     {
90         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
91         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
92     }
93 }
94 //*************************************************************************
95 Sequence< ::rtl::OUString >
96 StorageBridge::getScriptLogicalNames()
97 throw ( lang::IllegalArgumentException,
98         RuntimeException )
99 {
100     OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" );
101     Sequence < ::rtl::OUString  > results;
102     try
103     {
104         results = m_xScriptInfoAccess->getScriptLogicalNames();
105     }
106     catch ( Exception e )
107     {
108         OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " );
109         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
110     }
111     return results;
112 }
113 
114 //*************************************************************************
115 Sequence < Reference< storage::XScriptInfo > >
116 StorageBridge::getImplementations( const ::rtl::OUString& queryURI )
117 throw ( lang::IllegalArgumentException, RuntimeException )
118 {
119     OSL_TRACE( "In StorageBridge getImplementations...\n" );
120     Sequence < Reference< storage::XScriptInfo > > results;
121     try
122     {
123         results = m_xScriptInfoAccess->getImplementations( queryURI );
124     }
125     catch ( Exception e )
126     {
127         OUString temp = OUSTR( "StorageBridge::getImplementations: " );
128         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
129     }
130     return results;
131 }
132 }// namespace
133