xref: /trunk/main/scripting/source/runtimemgr/StorageBridge.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scripting.hxx"
26 
27 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
28 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
29 
30 #include "StorageBridge.hxx"
31 #include <util/util.hxx>
32 
33 using namespace ::rtl;
34 using namespace ::osl;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::drafts::com::sun::star::script::framework;
38 
39 namespace scripting_runtimemgr
40 {
41 
42 const char* const SCRIPTIMPLACCESS_SERVICE =
43     "drafts.com.sun.star.script.framework.storage.StorageProxy";
44 const char* const SCRIPTSTORAGEMANAGER_SERVICE =
45     "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
46 const int STORAGEID = 0;
47 const int STORAGEPROXY = 0;
48 
49 
50 //*************************************************************************
51 // StorageBridge Constructor
StorageBridge(const Reference<XComponentContext> & xContext,sal_Int32 sid)52 StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext,
53                               sal_Int32 sid ) : m_xContext( xContext, UNO_SET_THROW ), m_sid( sid )
54 {
55     try
56     {
57         initStorage();
58     }
59     catch ( RuntimeException & re )
60     {
61         OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " );
62         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
63     }
64 }
65 
66 //*************************************************************************
67 void
initStorage()68 StorageBridge::initStorage()
69 {
70     try
71     {
72         Reference< lang::XMultiComponentFactory > xMultiComFac( m_xContext->getServiceManager(), UNO_SET_THROW );
73         Reference< XInterface > temp( m_xContext->getValueByName(
74                     OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW );
75         Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW );
76         Reference< XInterface > xScriptStorage( xScriptStorageManager->getScriptStorage( m_sid ), UNO_SET_THROW );
77         m_xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW );
78     }
79     catch ( RuntimeException & re )
80     {
81         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
82         throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
83     }
84     catch ( Exception & e )
85     {
86         OUString temp = OUSTR( "StorageBridge::StorageBridge: " );
87         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
88     }
89 }
90 //*************************************************************************
91 Sequence< ::rtl::OUString >
getScriptLogicalNames()92 StorageBridge::getScriptLogicalNames()
93 {
94     OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" );
95     Sequence < ::rtl::OUString  > results;
96     try
97     {
98         results = m_xScriptInfoAccess->getScriptLogicalNames();
99     }
100     catch ( Exception e )
101     {
102         OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " );
103         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
104     }
105     return results;
106 }
107 
108 //*************************************************************************
109 Sequence < Reference< storage::XScriptInfo > >
getImplementations(const::rtl::OUString & queryURI)110 StorageBridge::getImplementations( const ::rtl::OUString& queryURI )
111 {
112     OSL_TRACE( "In StorageBridge getImplementations...\n" );
113     Sequence < Reference< storage::XScriptInfo > > results;
114     try
115     {
116         results = m_xScriptInfoAccess->getImplementations( queryURI );
117     }
118     catch ( Exception e )
119     {
120         OUString temp = OUSTR( "StorageBridge::getImplementations: " );
121         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
122     }
123     return results;
124 }
125 }// namespace
126