merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / importsvc.cxx
blob0e20097e1e5de81fe6d4deb6251cb206b98446e6
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: importsvc.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_configmgr.hxx"
34 #include "importsvc.hxx"
35 #include "importmergehandler.hxx"
36 #include "backendfactory.hxx"
38 #ifndef CONFIGMGR_API_FACTORY_HXX_
39 #include "confapifactory.hxx"
40 #endif
41 #include <com/sun/star/beans/NamedValue.hpp>
42 // -----------------------------------------------------------------------------
44 namespace configmgr
46 // -----------------------------------------------------------------------------
47 namespace backend
49 // -----------------------------------------------------------------------------
50 namespace uno = ::com::sun::star::uno;
51 namespace lang = ::com::sun::star::lang;
52 namespace beans = ::com::sun::star::beans;
53 namespace backenduno = ::com::sun::star::configuration::backend;
54 // -----------------------------------------------------------------------------
55 // -----------------------------------------------------------------------------
57 sal_Char const * const aMergeImporterServices[] =
59 "com.sun.star.configuration.backend.MergeImporter",
61 "com.sun.star.configuration.backend.Importer",
64 const ServiceImplementationInfo aMergeImporterSI =
66 "com.sun.star.comp.configuration.backend.MergeImporter",
67 aMergeImporterServices, aMergeImporterServices + 2
69 // -----------------------------------------------------------------------------
71 const ServiceRegistrationInfo* getMergeImportServiceInfo()
72 { return getRegistrationInfo(& aMergeImporterSI); }
73 // -----------------------------------------------------------------------------
75 MergeImportService::MergeImportService(uno::Reference< uno::XComponentContext > const & _xContext)
76 : ImportService(_xContext, &aMergeImporterSI)
79 // -----------------------------------------------------------------------------
81 uno::Reference< uno::XInterface > SAL_CALL instantiateMergeImporter
82 ( uno::Reference< uno::XComponentContext > const& xContext )
84 return * new MergeImportService( xContext );
86 // -----------------------------------------------------------------------------
88 uno::Reference< backenduno::XLayerHandler > MergeImportService::createImportHandler(uno::Reference< backenduno::XBackend > const & xBackend, rtl::OUString const & aEntity)
90 if (!xBackend.is())
92 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("configmgr::backend::ImportService: Trying to import without a backend. No default backend could be created") );
93 throw lang::NullPointerException(sMessage,*this);
96 uno::Reference< backenduno::XLayerHandler > aHandler( new ImportMergeHandler(xBackend, ImportMergeHandler::merge, aEntity, m_bSendNotification) );
98 return aHandler;
100 // -----------------------------------------------------------------------------
101 // -----------------------------------------------------------------------------
103 sal_Char const * const aCopyImporterServices[] =
105 "com.sun.star.configuration.backend.CopyImporter",
107 "com.sun.star.configuration.backend.Importer",
110 const ServiceImplementationInfo aCopyImporterSI =
112 "com.sun.star.comp.configuration.backend.CopyImporter",
113 aCopyImporterServices, aCopyImporterServices + 2
115 // -----------------------------------------------------------------------------
117 const ServiceRegistrationInfo* getCopyImportServiceInfo()
118 { return getRegistrationInfo(& aCopyImporterSI); }
119 // -----------------------------------------------------------------------------
121 CopyImportService::CopyImportService(uno::Reference< uno::XComponentContext > const & _xContext)
122 : ImportService(_xContext, &aCopyImporterSI)
125 // -----------------------------------------------------------------------------
127 uno::Reference< uno::XInterface > SAL_CALL instantiateCopyImporter
128 ( uno::Reference< uno::XComponentContext > const& xContext )
130 return * new CopyImportService( xContext );
132 // -----------------------------------------------------------------------------
134 uno::Reference< backenduno::XLayerHandler > CopyImportService::createImportHandler(uno::Reference< backenduno::XBackend > const & xBackend, rtl::OUString const & aEntity)
136 if (!xBackend.is())
138 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("configmgr::backend::ImportService: Trying to import without a backend. No default backend could be created") );
139 throw lang::NullPointerException(sMessage,*this);
142 ImportMergeHandler::Mode aMode = m_bOverwrite ? ImportMergeHandler::copy : ImportMergeHandler::no_overwrite;
143 uno::Reference< backenduno::XLayerHandler > aHandler( new ImportMergeHandler(xBackend,aMode,aEntity) );
145 return aHandler;
147 // -----------------------------------------------------------------------------
149 sal_Bool CopyImportService::setImplementationProperty(rtl::OUString const & aName, uno::Any const & aValue)
151 if (aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Overwrite")))
153 return (aValue >>= m_bOverwrite);
156 return ImportService::setImplementationProperty(aName,aValue);
158 // -----------------------------------------------------------------------------
159 // -----------------------------------------------------------------------------
160 // -----------------------------------------------------------------------------
162 ImportService::ImportService(uno::Reference< uno::XComponentContext > const & _xContext, ServiceInfoHelper const & aSvcInfo )
163 : m_bSendNotification(false)
164 , m_aMutex()
165 , m_xContext(_xContext)
166 , m_xDestinationBackend()
167 , m_aServiceInfo(aSvcInfo)
169 if (!m_xContext.is())
171 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration Importer: Unexpected NULL context"));
172 throw lang::NullPointerException(sMessage,NULL);
175 // -----------------------------------------------------------------------------
177 ImportService::~ImportService()
179 // -----------------------------------------------------------------------------
181 uno::Reference< backenduno::XBackend > ImportService::createDefaultBackend() const
183 return BackendFactory::instance( m_xContext ).getUnoBackend();
185 // -----------------------------------------------------------------------------
187 sal_Bool ImportService::setImplementationProperty(rtl::OUString const & aName, uno::Any const & aValue)
189 if (aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Notify")))
191 return (aValue >>= m_bSendNotification);
194 return false;
196 // -----------------------------------------------------------------------------
198 // XInitialize
200 void SAL_CALL
201 ImportService::initialize( const uno::Sequence< uno::Any >& aArguments )
202 throw (uno::Exception, uno::RuntimeException)
204 sal_Int16 const nCount = static_cast<sal_Int16>(aArguments.getLength());
206 if (sal_Int32(nCount) != aArguments.getLength())
208 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Too many arguments to initialize a Configuration Importer"));
209 throw lang::IllegalArgumentException(sMessage,*this,0);
212 for (sal_Int16 i = 0; i < nCount; ++i)
214 beans::NamedValue aExtraArg;
215 if (aArguments[i] >>= aExtraArg)
217 OSL_VERIFY( setImplementationProperty(aExtraArg.Name, aExtraArg.Value) );
219 continue;
222 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Cannot use argument to initialize a Configuration Importer"
223 "- NamedValue expected"));
224 throw lang::IllegalArgumentException(sMessage,*this,i+1);
228 // -----------------------------------------------------------------------------
230 // XLayerImporter
232 uno::Reference< backenduno::XBackend > SAL_CALL
233 ImportService::getTargetBackend( )
234 throw (uno::RuntimeException)
236 uno::Reference< backenduno::XBackend > xRet;
238 osl::MutexGuard aGuard(m_aMutex);
239 xRet = m_xDestinationBackend;
242 if (!xRet.is())
244 xRet = createDefaultBackend();
246 osl::MutexGuard aGuard(m_aMutex);
247 if (!m_xDestinationBackend.is())
248 m_xDestinationBackend = xRet;
250 return xRet;
252 // -----------------------------------------------------------------------------
254 void SAL_CALL
255 ImportService::setTargetBackend( const uno::Reference< backenduno::XBackend >& aBackend )
256 throw (lang::NullPointerException, uno::RuntimeException)
258 if (!aBackend.is())
260 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("configmgr::backend::ImportService: Trying to set a NULL backend") );
261 throw lang::NullPointerException(sMessage,*this);
264 osl::MutexGuard aGuard(m_aMutex);
265 m_xDestinationBackend = aBackend;
267 // -----------------------------------------------------------------------------
269 void SAL_CALL
270 ImportService::importLayer( const uno::Reference< backenduno::XLayer >& aLayer )
271 throw ( backenduno::MalformedDataException,
272 lang::WrappedTargetException, lang::IllegalArgumentException,
273 lang::NullPointerException, uno::RuntimeException)
275 if (!aLayer.is())
277 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("configmgr::backend::ImportService: Trying to import a NULL layer") );
278 throw lang::NullPointerException(sMessage,*this);
281 uno::Reference< backenduno::XLayerHandler > aInputHandler = createImportHandler( getTargetBackend() );
282 aLayer->readData( aInputHandler );
285 // -----------------------------------------------------------------------------
287 void SAL_CALL
288 ImportService::importLayerForEntity( const uno::Reference< backenduno::XLayer >& aLayer, const rtl::OUString& aEntity )
289 throw ( backenduno::MalformedDataException,
290 lang::WrappedTargetException, lang::IllegalArgumentException,
291 lang::NullPointerException, uno::RuntimeException)
293 if (!aLayer.is())
295 rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("configmgr::backend::ImportService: Trying to import a NULL layer") );
296 throw lang::NullPointerException(sMessage,*this);
299 uno::Reference< backenduno::XLayerHandler > aInputHandler = createImportHandler( getTargetBackend(), aEntity );
300 aLayer->readData( aInputHandler );
302 // -----------------------------------------------------------------------------
304 // XServiceInfo
306 rtl::OUString SAL_CALL
307 ImportService::getImplementationName( )
308 throw (uno::RuntimeException)
310 return getServiceInfo().getImplementationName( );
312 // -----------------------------------------------------------------------------
315 sal_Bool SAL_CALL
316 ImportService::supportsService( const rtl::OUString& ServiceName )
317 throw (uno::RuntimeException)
319 return getServiceInfo().supportsService( ServiceName );
321 // -----------------------------------------------------------------------------
324 uno::Sequence< ::rtl::OUString > SAL_CALL
325 ImportService::getSupportedServiceNames( )
326 throw (uno::RuntimeException)
328 return getServiceInfo().getSupportedServiceNames( );
330 // -----------------------------------------------------------------------------
332 // -----------------------------------------------------------------------------
333 // -----------------------------------------------------------------------------
334 } // namespace
336 // -----------------------------------------------------------------------------
337 } // namespace