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() throw ( ::com::sun::star::uno::RuntimeException )
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 throw ( lang::IllegalArgumentException,
94 RuntimeException )
95 {
96 OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" );
97 Sequence < ::rtl::OUString > results;
98 try
99 {
100 results = m_xScriptInfoAccess->getScriptLogicalNames();
101 }
102 catch ( Exception e )
103 {
104 OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " );
105 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
106 }
107 return results;
108 }
109
110 //*************************************************************************
111 Sequence < Reference< storage::XScriptInfo > >
getImplementations(const::rtl::OUString & queryURI)112 StorageBridge::getImplementations( const ::rtl::OUString& queryURI )
113 throw ( lang::IllegalArgumentException, RuntimeException )
114 {
115 OSL_TRACE( "In StorageBridge getImplementations...\n" );
116 Sequence < Reference< storage::XScriptInfo > > results;
117 try
118 {
119 results = m_xScriptInfoAccess->getImplementations( queryURI );
120 }
121 catch ( Exception e )
122 {
123 OUString temp = OUSTR( "StorageBridge::getImplementations: " );
124 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
125 }
126 return results;
127 }
128 }// namespace
129