Update ooo320-m1
[ooovba.git] / configmgr / source / backend / singlebackendadapter.cxx
blobbcecbe7e5ba7bcc5e4fd5a577c4e3f5e32da44bf
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: singlebackendadapter.cxx,v $
10 * $Revision: 1.14 $
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_configmgr.hxx"
33 #include "singlebackendadapter.hxx"
35 #ifndef CONFIGMGR_API_FACTORY_HXX_
36 #include "confapifactory.hxx"
37 #endif // CONFIGMGR_API_FACTORY_HXX_
38 #include "serviceinfohelper.hxx"
39 #include <com/sun/star/configuration/backend/XMultiLayerStratum.hpp>
40 #include <com/sun/star/configuration/CannotLoadConfigurationException.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 namespace configmgr { namespace backend {
44 //==============================================================================
46 SingleBackendAdapter::SingleBackendAdapter(
47 const uno::Reference<uno::XComponentContext>& xContext)
48 : cppu::WeakComponentImplHelper5< backenduno::XBackend, backenduno::XBackendEntities, backenduno::XSchemaSupplier, lang::XInitialization, lang::XServiceInfo >(mMutex), mFactory(xContext->getServiceManager(),uno::UNO_QUERY) {
50 //------------------------------------------------------------------------------
52 SingleBackendAdapter::~SingleBackendAdapter(void) {}
53 //------------------------------------------------------------------------------
55 void SAL_CALL SingleBackendAdapter::initialize(
56 const uno::Sequence<uno::Any>& aParameters)
57 throw (uno::RuntimeException, uno::Exception) {
59 uno::Any const * const pParams = aParameters.getConstArray();
60 sal_Int32 nCount = aParameters.getLength();
62 for (sal_Int32 ix = 0; ix < nCount; ++ix)
64 if (pParams[ix] >>= mBackend) break;
67 if (!mBackend.is())
69 throw com::sun::star::configuration::CannotLoadConfigurationException(
70 rtl::OUString::createFromAscii("Online SingleBackend Adapter: Cannot operate without real (Single)Backend"),
71 *this);
74 //------------------------------------------------------------------------------
75 static inline rtl::OUString getSingleLayerDummyEntity()
76 { return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")); }
77 //------------------------------------------------------------------------------
78 bool SingleBackendAdapter::checkOkState()
80 if (!mBackend.is())
82 if(rBHelper.bDisposed)
84 throw lang::DisposedException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
85 "SingleBackendAdapter: Backend already disposed")),*this);
87 else
89 throw backenduno::BackendAccessException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
90 "SingleBackendAdapter: Object was never Initialised")),*this,uno::Any() );
93 return true;
96 //------------------------------------------------------------------------------
98 // XBackendEntities
99 rtl::OUString SAL_CALL
100 SingleBackendAdapter::getOwnerEntity( )
101 throw (uno::RuntimeException)
103 if (mBackend.is())
105 uno::Reference< backenduno::XBackendEntities > xEntities( mBackend, uno::UNO_REF_QUERY_THROW );
107 return xEntities->getOwnerEntity();
109 else
111 throw uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
112 "SingleBackendAdapter: Object was never Initialised")),*this);
115 //------------------------------------------------------------------------------
117 rtl::OUString SAL_CALL
118 SingleBackendAdapter::getAdminEntity( )
119 throw (uno::RuntimeException)
121 if (mBackend.is())
123 uno::Reference< backenduno::XBackendEntities > xEntities( mBackend, uno::UNO_REF_QUERY_THROW );
124 return xEntities->getAdminEntity();
126 else
128 throw uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
129 "SingleBackendAdapter: Object was never Initialised")),*this);
132 //------------------------------------------------------------------------------
134 sal_Bool SAL_CALL
135 SingleBackendAdapter::supportsEntity( const rtl::OUString& aEntity )
136 throw (backenduno::BackendAccessException, uno::RuntimeException)
138 if (checkOkState())
140 uno::Reference< backenduno::XBackendEntities > xEntities( mBackend, uno::UNO_REF_QUERY_THROW );
141 return xEntities->supportsEntity(aEntity);
143 return false;
145 //------------------------------------------------------------------------------
147 sal_Bool SAL_CALL
148 SingleBackendAdapter::isEqualEntity( const rtl::OUString& aEntity, const rtl::OUString& aOtherEntity )
149 throw (backenduno::BackendAccessException,
150 lang::IllegalArgumentException,
151 uno::RuntimeException)
153 if (checkOkState())
155 uno::Reference< backenduno::XBackendEntities > xEntities( mBackend, uno::UNO_REF_QUERY_THROW );
156 return xEntities->isEqualEntity(aEntity,aOtherEntity);
158 return false;
160 //------------------------------------------------------------------------------
162 uno::Reference<backenduno::XSchema> SAL_CALL
163 SingleBackendAdapter::getComponentSchema(const rtl::OUString& aComponent)
164 throw (backenduno::BackendAccessException,
165 lang::IllegalArgumentException,
166 uno::RuntimeException)
168 if (checkOkState())
170 return mBackend->getComponentSchema(aComponent) ;
172 return false;
174 //------------------------------------------------------------------------------
176 uno::Sequence<uno::Reference<backenduno::XLayer> > SAL_CALL
177 SingleBackendAdapter::listOwnLayers(const rtl::OUString& aComponent)
178 throw (backenduno::BackendAccessException,
179 lang::IllegalArgumentException,
180 uno::RuntimeException)
182 if (checkOkState())
184 return listLayers(aComponent, this->getOwnerEntity()) ;
186 return false;
188 //------------------------------------------------------------------------------
190 uno::Reference<backenduno::XUpdateHandler> SAL_CALL
191 SingleBackendAdapter::getOwnUpdateHandler(const rtl::OUString& aComponent)
192 throw (backenduno::BackendAccessException,
193 lang::NoSupportException,
194 lang::IllegalArgumentException,
195 uno::RuntimeException)
197 if (checkOkState())
199 return getUpdateHandler(aComponent, this->getOwnerEntity()) ;
201 return false;
203 //------------------------------------------------------------------------------
205 uno::Sequence<uno::Reference<backenduno::XLayer> > SAL_CALL
206 SingleBackendAdapter::listLayers(const rtl::OUString& aComponent,
207 const rtl::OUString& aEntity)
208 throw (backenduno::BackendAccessException,
209 lang::IllegalArgumentException,
210 uno::RuntimeException)
212 if (checkOkState())
214 uno::Reference< backenduno::XMultiLayerStratum > xBackend( mBackend, uno::UNO_REF_QUERY_THROW );
216 uno::Sequence<uno::Reference<backenduno::XLayer> > retCode =
217 xBackend->getLayers(xBackend->listLayerIds(aComponent, aEntity),
218 rtl::OUString()) ;
220 // There might be non-existent layers in the list if there's no
221 // actual data associated to a given layer id. Hence we have to
222 // compress the list.
223 sal_Int32 maxLayer = 0 ;
225 for (sal_Int32 i = 0 ; i < retCode.getLength() ; ++ i)
227 if (retCode [i].is())
229 if (i != maxLayer) { retCode [maxLayer] = retCode [i] ; }
230 ++ maxLayer ;
233 retCode.realloc(maxLayer) ;
234 return retCode ;
236 return false;
238 //------------------------------------------------------------------------------
240 uno::Reference<backenduno::XUpdateHandler> SAL_CALL
241 SingleBackendAdapter::getUpdateHandler(const rtl::OUString& aComponent,
242 const rtl::OUString& aEntity)
243 throw (backenduno::BackendAccessException,
244 lang::NoSupportException,
245 lang::IllegalArgumentException,
246 uno::RuntimeException)
248 if (checkOkState())
250 uno::Reference< backenduno::XMultiLayerStratum > xBackend( mBackend, uno::UNO_REF_QUERY_THROW );
252 uno::Sequence<uno::Any> arguments(1) ;
254 arguments [0] <<= xBackend->getUpdatableLayer(
255 xBackend->getUpdateLayerId(aComponent,
256 aEntity)) ;
257 uno::Reference< uno::XInterface > xHandler;
260 const rtl::OUString kUpdateMerger(RTL_CONSTASCII_USTRINGPARAM(
261 "com.sun.star.configuration.backend.LayerUpdateMerger")) ;
263 xHandler = mFactory->createInstanceWithArguments(kUpdateMerger, arguments);
265 catch (uno::RuntimeException & )
266 {throw;}
267 catch (uno::Exception & e)
269 const rtl::OUString sMessage(RTL_CONSTASCII_USTRINGPARAM(
270 "Configuration SingleBackendAdapter: Cannot create UpdateMerger - error message: ")) ;
271 throw uno::RuntimeException(sMessage.concat(e.Message),*this);
274 return uno::Reference<backenduno::XUpdateHandler>(xHandler, uno::UNO_REF_QUERY_THROW) ;
276 return false;
278 //------------------------------------------------------------------------------
280 static const sal_Char * const kBackendService = "com.sun.star.configuration.backend.Backend" ;
281 static const sal_Char * const kAdapterService = "com.sun.star.configuration.backend.BackendAdapter" ;
282 static const sal_Char * const kOnlineService = "com.sun.star.configuration.backend.OnlineBackend" ;
284 static const sal_Char * const kImplementation =
285 "com.sun.star.comp.configuration.backend.SingleBackendAdapter" ;
287 static sal_Char const * const kServiceNames [] =
289 kOnlineService,
290 kAdapterService,
292 kBackendService,
295 static const ServiceImplementationInfo kServiceInfo =
297 kImplementation,
298 kServiceNames,
299 kServiceNames + 3
302 const ServiceRegistrationInfo *getSingleBackendAdapterServiceInfo()
304 return getRegistrationInfo(&kServiceInfo) ;
307 uno::Reference<uno::XInterface> SAL_CALL
308 instantiateSingleBackendAdapter(const uno::Reference< uno::XComponentContext >& xContext)
310 return *new SingleBackendAdapter(xContext) ;
312 //------------------------------------------------------------------------------
314 rtl::OUString SAL_CALL
315 SingleBackendAdapter::getImplementationName(void)
316 throw (uno::RuntimeException)
318 return ServiceInfoHelper(&kServiceInfo).getImplementationName() ;
320 //------------------------------------------------------------------------------
322 sal_Bool SAL_CALL
323 SingleBackendAdapter::supportsService(const rtl::OUString& aServiceName)
324 throw (uno::RuntimeException)
326 return ServiceInfoHelper(&kServiceInfo).supportsService(aServiceName) ;
328 //------------------------------------------------------------------------------
330 uno::Sequence<rtl::OUString> SAL_CALL
331 SingleBackendAdapter::getSupportedServiceNames(void)
332 throw (uno::RuntimeException)
334 return ServiceInfoHelper(&kServiceInfo).getSupportedServiceNames() ;
336 //------------------------------------------------------------------------------
338 } } // configmgr.backend