fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / core / dataaccess / documentcontainer.cxx
blobe38cf993d0b7ac39c12626db10ac720467f3956f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "documentcontainer.hxx"
21 #include "dbastrings.hrc"
22 #include "documentdefinition.hxx"
23 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
24 #include <com/sun/star/ucb/OpenMode.hpp>
25 #include <tools/debug.hxx>
26 #include <connectivity/dbtools.hxx>
27 #include "myucp_resultset.hxx"
28 #include <ucbhelper/cancelcommandexecution.hxx>
29 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
30 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/sdb/ErrorCondition.hpp>
33 #include "datasource.hxx"
34 #include <comphelper/classids.hxx>
35 #include <comphelper/mimeconfighelper.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <connectivity/sqlerror.hxx>
38 #include "core_resource.hxx"
39 #include "core_resource.hrc"
40 #include <comphelper/namedvaluecollection.hxx>
41 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
43 #include <vcl/svapp.hxx>
44 #include <osl/mutex.hxx>
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::embed;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::ucb;
52 using namespace ::com::sun::star::sdbc;
53 using namespace ::com::sun::star::sdb;
54 using namespace ::com::sun::star::io;
55 using namespace ::osl;
56 using namespace ::comphelper;
57 using namespace ::cppu;
59 namespace dbaccess
62 // LocalNameApproval
63 class LocalNameApproval : public IContainerApprove
65 ::connectivity::SQLError m_aErrors;
67 public:
68 LocalNameApproval( const Reference< XComponentContext >& _rxContext )
69 :m_aErrors( _rxContext )
72 virtual ~LocalNameApproval()
76 void SAL_CALL approveElement( const OUString& _rName, const Reference< XInterface >& _rxElement ) SAL_OVERRIDE;
79 void SAL_CALL LocalNameApproval::approveElement( const OUString& _rName, const Reference< XInterface >& /*_rxElement*/ )
81 if ( _rName.indexOf( '/' ) != -1 )
82 throw IllegalArgumentException(
83 m_aErrors.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES ),
84 NULL,
89 // ODocumentContainer
91 ODocumentContainer::ODocumentContainer(const Reference< XComponentContext >& _xORB
92 ,const Reference< XInterface >& _xParentContainer
93 ,const TContentPtr& _pImpl
94 , bool _bFormsContainer
96 :ODefinitionContainer(_xORB,_xParentContainer,_pImpl)
97 ,OPropertyStateContainer(OContentHelper::rBHelper)
98 ,m_bFormsContainer(_bFormsContainer)
100 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
101 &m_pImpl->m_aProps.aTitle, cppu::UnoType<decltype(m_pImpl->m_aProps.aTitle)>::get());
103 setElementApproval( PContainerApprove( new LocalNameApproval ( _xORB ) ) );
106 ODocumentContainer::~ODocumentContainer()
109 if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
111 acquire();
112 dispose();
116 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer,ODefinitionContainer,ODocumentContainer_Base,OPropertyStateContainer)
118 css::uno::Sequence<sal_Int8> ODocumentContainer::getImplementationId()
119 throw (css::uno::RuntimeException, std::exception)
121 return css::uno::Sequence<sal_Int8>();
124 IMPLEMENT_GETTYPES3(ODocumentContainer,ODefinitionContainer,OPropertyStateContainer,ODocumentContainer_Base);
125 IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer, "com.sun.star.comp.dba.ODocumentContainer");
126 IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer);
127 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer)
129 Sequence< OUString > SAL_CALL ODocumentContainer::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
131 Sequence< OUString > aSupported(1);
132 aSupported[0] = m_bFormsContainer ? OUString(SERVICE_NAME_FORM_COLLECTION) : OUString(SERVICE_NAME_REPORT_COLLECTION);
133 return aSupported;
136 OUString ODocumentContainer::determineContentType() const
138 return OUString();
141 Reference< XContent > ODocumentContainer::createObject( const OUString& _rName)
143 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
144 ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( _rName );
145 OSL_ENSURE( aFind != rDefinitions.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
146 if ( aFind->second->m_aProps.bIsFolder )
147 return new ODocumentContainer( m_aContext, *this, aFind->second, m_bFormsContainer );
148 return new ODocumentDefinition( *this, m_aContext, aFind->second, m_bFormsContainer );
151 Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const OUString& aServiceSpecifier ) throw (Exception, RuntimeException, std::exception)
153 return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() );
156 namespace
158 template< class TYPE >
159 void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const OUString& i_rName, TYPE& o_rValue )
161 if ( io_rArguments.has( i_rName ) )
163 io_rArguments.get_ensureType( i_rName, o_rValue );
164 io_rArguments.remove( i_rName );
169 Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const OUString& ServiceSpecifier, const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException, std::exception)
171 Reference< XInterface > xRet;
172 Reference< XContent > xContent;
173 if ( ServiceSpecifier == SERVICE_SDB_DOCUMENTDEFINITION )
175 MutexGuard aGuard(m_aMutex);
177 // extract known arguments
178 OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName;
179 Reference< XCommandProcessor > xCopyFrom;
180 Reference< XConnection > xConnection;
181 bool bAsTemplate( false );
182 Sequence< sal_Int8 > aClassID;
184 ::comphelper::NamedValueCollection aArgs( _aArguments );
185 lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName );
186 lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName );
187 lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL );
188 lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom );
189 lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection );
190 lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate );
191 lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType );
192 lcl_extractAndRemove( aArgs, "DocumentServiceName" , sDocServiceName );
194 // ClassID has two allowed types, so a special treatment here
195 Any aClassIDArg = aArgs.get( "ClassID" );
196 if ( aClassIDArg.hasValue() )
198 if ( !( aClassIDArg >>= aClassID ) )
200 // Extended for usage also with a string
201 OUString sClassIDString;
202 if ( !( aClassIDArg >>= sClassIDString ) )
203 throw IllegalArgumentException( OUString(), *this, 2 );
205 aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString );
208 #if OSL_DEBUG_LEVEL > 0
209 OUString sClassIDString = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID );
210 (void)sClassIDString;
211 #endif
212 aArgs.remove( "ClassID" );
214 // Everything which now is still present in the arguments is passed to the embedded object
215 const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() );
217 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
218 bool bNew = sPersistentName.isEmpty();
219 if ( bNew )
221 static const char sBaseName[] = "Obj";
223 sPersistentName = sBaseName;
224 sPersistentName += OUString::number(rDefinitions.size() + 1);
225 Reference<XNameAccess> xElements(getContainerStorage(),UNO_QUERY);
226 if ( xElements.is() )
227 sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName);
229 const bool bNeedClassID = (0 == aClassID.getLength()) && sURL.isEmpty() ;
230 if ( xCopyFrom.is() )
232 Sequence<Any> aIni(2);
233 aIni[0] <<= getContainerStorage();
234 aIni[1] <<= sPersistentName;
235 Command aCommand;
236 aCommand.Name = "copyTo";
237 aCommand.Argument <<= aIni;
239 xCopyFrom->execute(aCommand,-1,Reference< XCommandEnvironment >());
240 Reference<XPropertySet> xProp(xCopyFrom,UNO_QUERY);
241 if ( xProp.is() && xProp->getPropertySetInfo().is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE) )
242 xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate;
244 // if we do not have an own class ID, see if we can determine one from the copy we just created
245 if ( bNeedClassID )
246 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName, m_aContext, aClassID );
248 else
250 if ( bNeedClassID )
252 if ( !sMediaType.isEmpty() )
253 ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID );
254 else if ( !sDocServiceName.isEmpty() )
256 ::comphelper::MimeConfigurationHelper aConfigHelper( m_aContext );
257 const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) );
258 const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
259 aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
265 ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
266 TContentPtr pElementImpl;
267 if ( bNew || ( aFind == rDefinitions.end() ) )
269 pElementImpl.reset( new OContentHelper_Impl );
270 if ( !bNew )
271 pElementImpl->m_aProps.aTitle = sName;
273 pElementImpl->m_aProps.sPersistentName = sPersistentName;
274 pElementImpl->m_aProps.bAsTemplate = bAsTemplate;
275 pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
277 else
278 pElementImpl = aFind->second;
280 ::rtl::Reference< ODocumentDefinition > pDocDef = new ODocumentDefinition( *this, m_aContext, pElementImpl, m_bFormsContainer );
281 if ( aClassID.getLength() )
283 pDocDef->initialLoad( aClassID, aCreationArgs, xConnection );
285 else
287 OSL_ENSURE( aCreationArgs.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
289 xContent = pDocDef.get();
291 if ( !sURL.isEmpty() )
293 Sequence<Any> aIni(2);
294 aIni[0] <<= sURL;
295 Command aCommand;
296 aCommand.Name = "insert";
297 aCommand.Argument <<= aIni;
298 Reference< XCommandProcessor > xCommandProcessor(xContent,UNO_QUERY);
299 if ( xContent.is() )
301 xCommandProcessor->execute(aCommand,-1,Reference< XCommandEnvironment >());
305 else if ( ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION || SERVICE_NAME_REPORT_COLLECTION == ServiceSpecifier )
307 const Any* pBegin = _aArguments.getConstArray();
308 const Any* pEnd = pBegin + _aArguments.getLength();
309 PropertyValue aValue;
310 OUString sName;
311 Reference<XNameAccess> xCopyFrom;
312 for(;pBegin != pEnd;++pBegin)
314 *pBegin >>= aValue;
315 if ( aValue.Name == PROPERTY_NAME)
317 aValue.Value >>= sName;
319 else if ( aValue.Name == PROPERTY_EMBEDDEDOBJECT)
321 xCopyFrom.set(aValue.Value,UNO_QUERY);
324 OSL_ENSURE(!sName.isEmpty(),"Invalid name for a document container!");
325 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
326 ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
327 TContentPtr pElementImpl;
328 if ( aFind == rDefinitions.end() )
330 pElementImpl.reset(new ODefinitionContainer_Impl);
331 pElementImpl->m_aProps.aTitle = sName;
332 pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
334 else
335 pElementImpl = aFind->second;
336 OSL_ENSURE( pElementImpl ," Invalid entry in map!");
337 xContent = new ODocumentContainer( m_aContext, *this, pElementImpl, ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION );
339 // copy children
340 if ( xCopyFrom.is() )
342 Sequence< OUString> aSeq = xCopyFrom->getElementNames();
343 const OUString* elements = aSeq.getConstArray();
344 const OUString* elementsEnd = elements + aSeq.getLength();
345 Reference<XContent> xObjectToCopy;
347 Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY);
348 OSL_ENSURE(xORB.is(),"No service factory given");
349 if ( xORB.is() )
351 for(;elements != elementsEnd;++elements)
353 xCopyFrom->getByName(*elements) >>= xObjectToCopy;
354 Sequence< Any > aArguments(3);
355 PropertyValue aArgument;
356 // set as folder
357 aArgument.Name = "Name";
358 aArgument.Value <<= *elements;
359 aArguments[0] <<= aArgument;
360 //parent
361 aArgument.Name = "Parent";
362 aArgument.Value <<= xContent;
363 aArguments[1] <<= aArgument;
365 aArgument.Name = PROPERTY_EMBEDDEDOBJECT;
366 aArgument.Value <<= xObjectToCopy;
367 aArguments[2] <<= aArgument;
369 OUString sServiceName;
370 if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() )
372 if ( m_bFormsContainer )
373 sServiceName = SERVICE_NAME_FORM_COLLECTION;
374 else
375 sServiceName = SERVICE_NAME_REPORT_COLLECTION;
377 else
378 sServiceName = SERVICE_SDB_DOCUMENTDEFINITION;
380 Reference<XContent > xNew(xORB->createInstanceWithArguments(sServiceName,aArguments),UNO_QUERY);
381 Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY);
382 if ( xNameContainer.is() )
383 xNameContainer->insertByName(*elements,makeAny(xNew));
388 xRet = xContent;
389 return xRet;
392 Sequence< OUString > SAL_CALL ODocumentContainer::getAvailableServiceNames( ) throw (RuntimeException, std::exception)
394 Sequence< OUString > aSe(3);
395 aSe[0] = SERVICE_SDB_DOCUMENTDEFINITION;
396 aSe[1] = SERVICE_NAME_FORM_COLLECTION;
397 aSe[2] = SERVICE_NAME_REPORT_COLLECTION;
398 return aSe;
401 Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException, std::exception)
403 Any aRet;
404 if ( aCommand.Name == "open" )
406 // open command for a folder content
407 OpenCommandArgument2 aOpenCommand;
408 if ( !( aCommand.Argument >>= aOpenCommand ) )
410 OSL_FAIL( "Wrong argument type!" );
411 ucbhelper::cancelCommandExecution(
412 makeAny( IllegalArgumentException(
413 OUString(),
414 static_cast< cppu::OWeakObject * >( this ),
415 -1 ) ),
416 Environment );
417 // Unreachable
419 bool bOpenFolder =
420 ( ( aOpenCommand.Mode == OpenMode::ALL ) ||
421 ( aOpenCommand.Mode == OpenMode::FOLDERS ) ||
422 ( aOpenCommand.Mode == OpenMode::DOCUMENTS ) );
424 if ( bOpenFolder )
426 // open as folder - return result set
428 Reference< XDynamicResultSet > xSet
429 = new DynamicResultSet( m_aContext,
430 this,
431 aOpenCommand,
432 Environment );
433 aRet <<= xSet;
435 else
437 // Unsupported.
438 ucbhelper::cancelCommandExecution(
439 makeAny( UnsupportedOpenModeException(
440 OUString(),
441 static_cast< cppu::OWeakObject * >( this ),
442 sal_Int16( aOpenCommand.Mode ) ) ),
443 Environment );
444 // Unreachable
447 else if ( aCommand.Name == "insert" )
449 // insert
451 InsertCommandArgument arg;
452 if ( !( aCommand.Argument >>= arg ) )
454 OSL_FAIL( "Wrong argument type!" );
455 ucbhelper::cancelCommandExecution(
456 makeAny( IllegalArgumentException(
457 OUString(),
458 static_cast< cppu::OWeakObject * >( this ),
459 -1 ) ),
460 Environment );
461 // Unreachable
464 else if ( aCommand.Name == "delete" )
466 // delete
467 Sequence< OUString> aSeq = getElementNames();
468 const OUString* pIter = aSeq.getConstArray();
469 const OUString* pEnd = pIter + aSeq.getLength();
470 for(;pIter != pEnd;++pIter)
471 removeByName(*pIter);
473 dispose();
475 else
476 aRet = OContentHelper::execute(aCommand,CommandId,Environment);
477 return aRet;
480 namespace
482 bool lcl_queryContent(const OUString& _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName)
484 sal_Int32 nIndex = 0;
485 OUString sName = _sName.getToken(0,'/',nIndex);
486 bool bRet = _xNameContainer->hasByName(sName);
487 if ( bRet )
489 _rRet = _xNameContainer->getByName(_sSimpleName = sName);
490 while ( nIndex != -1 && bRet )
492 sName = _sName.getToken(0,'/',nIndex);
493 _xNameContainer.set(_rRet,UNO_QUERY);
494 bRet = _xNameContainer.is();
495 if ( bRet )
497 bRet = _xNameContainer->hasByName(sName);
498 _sSimpleName = sName;
499 if ( bRet )
500 _rRet = _xNameContainer->getByName(sName);
504 if ( nIndex == -1 )
505 _sSimpleName = sName; // a content
506 else
507 _xNameContainer.clear(); // a sub folder doesn't exist
508 return bRet;
512 Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const OUString& _sURL
513 , const OUString& /*TargetFrameName*/
514 , sal_Int32 /*SearchFlags*/
515 , const Sequence< PropertyValue >& Arguments ) throw (IOException, IllegalArgumentException, RuntimeException, std::exception)
517 ::SolarMutexGuard aSolarGuard;
519 MutexGuard aGuard(m_aMutex);
520 Reference< XComponent > xComp;
523 Any aContent;
524 Reference< XNameContainer > xNameContainer(this);
525 OUString sName;
526 if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) )
528 OUString sMessage(
529 DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirst("$name$", _sURL));
530 throw IllegalArgumentException( sMessage, *this, 1 );
533 Reference< XCommandProcessor > xContent(aContent,UNO_QUERY);
534 if ( xContent.is() )
536 Command aCommand;
538 ::comphelper::NamedValueCollection aArgs( Arguments );
539 aCommand.Name = aArgs.getOrDefault( "OpenMode", OUString("open") );
540 aArgs.remove( "OpenMode" );
542 OpenCommandArgument2 aOpenCommand;
543 aOpenCommand.Mode = OpenMode::DOCUMENT;
544 aArgs.put( "OpenCommandArgument", aOpenCommand );
546 aCommand.Argument <<= aArgs.getPropertyValues();
547 xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY);
550 catch(const NoSuchElementException&)
552 throw IllegalArgumentException();
554 catch(const WrappedTargetException &e)
556 throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
558 return xComp;
561 Any SAL_CALL ODocumentContainer::getByHierarchicalName( const OUString& _sName ) throw (NoSuchElementException, RuntimeException, std::exception)
563 MutexGuard aGuard(m_aMutex);
564 Any aContent;
565 Reference< XNameContainer > xNameContainer(this);
566 OUString sName;
567 if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
568 return aContent;
569 throw NoSuchElementException(_sName,*this);
572 sal_Bool SAL_CALL ODocumentContainer::hasByHierarchicalName( const OUString& _sName ) throw (RuntimeException, std::exception)
574 MutexGuard aGuard(m_aMutex);
575 Any aContent;
576 Reference< XNameContainer > xNameContainer(this);
577 OUString sName;
578 return lcl_queryContent(_sName,xNameContainer,aContent,sName);
581 // XHierarchicalNameContainer
582 void SAL_CALL ODocumentContainer::insertByHierarchicalName( const OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException, std::exception)
584 Reference< XContent > xContent(_aElement,UNO_QUERY);
585 if ( !xContent.is() )
586 throw IllegalArgumentException();
588 ClearableMutexGuard aGuard(m_aMutex);
589 Any aContent;
590 Reference< XNameContainer > xNameContainer(this);
591 OUString sName;
592 if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
593 throw ElementExistException(_sName,*this);
595 if ( !xNameContainer.is() )
597 sal_Int32 index = sName.getLength();
598 OUString sMessage(
599 DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirst("$folder$",
600 _sName.getToken(0,'/',index)));
601 throw IllegalArgumentException( sMessage, *this, 1 );
604 xNameContainer->insertByName(sName,_aElement);
607 void SAL_CALL ODocumentContainer::removeByHierarchicalName( const OUString& _sName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
609 if ( _sName.isEmpty() )
610 throw NoSuchElementException(_sName,*this);
612 ClearableMutexGuard aGuard(m_aMutex);
613 Any aContent;
614 OUString sName;
615 Reference< XNameContainer > xNameContainer(this);
616 if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
617 throw NoSuchElementException(_sName,*this);
619 xNameContainer->removeByName(sName);
622 // XHierarchicalNameReplace
623 void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
625 Reference< XContent > xContent(_aElement,UNO_QUERY);
626 if ( !xContent.is() )
627 throw IllegalArgumentException();
629 ClearableMutexGuard aGuard(m_aMutex);
630 Any aContent;
631 OUString sName;
632 Reference< XNameContainer > xNameContainer(this);
633 if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
634 throw NoSuchElementException(_sName,*this);
636 xNameContainer->replaceByName(sName,_aElement);
639 OUString SAL_CALL ODocumentContainer::getHierarchicalName() throw (RuntimeException, std::exception)
641 ::osl::MutexGuard aGuard( m_aMutex );
642 return impl_getHierarchicalName( false );
645 OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException, std::exception)
647 OUStringBuffer aBuffer;
648 aBuffer.append( getHierarchicalName() );
649 aBuffer.append( '/' );
650 aBuffer.append( i_rRelativeName );
651 return aBuffer.makeStringAndClear();
654 ::rtl::Reference<OContentHelper> ODocumentContainer::getContent(const OUString& _sName) const
656 ::rtl::Reference<OContentHelper> pContent = NULL;
659 Reference<XUnoTunnel> xUnoTunnel(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, true ), UNO_QUERY );
660 if ( xUnoTunnel.is() )
661 pContent = reinterpret_cast<OContentHelper*>(xUnoTunnel->getSomething(OContentHelper::getUnoTunnelImplementationId()));
663 catch(const Exception&)
666 return pContent;
669 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
671 _rDefault.clear();
674 void SAL_CALL ODocumentContainer::commit( ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
676 MutexGuard aGuard(m_aMutex);
677 Documents::iterator aIter = m_aDocumentMap.begin();
678 Documents::iterator aEnd = m_aDocumentMap.end();
679 for (; aIter != aEnd ; ++aIter)
681 Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
682 if ( xTrans.is() )
683 xTrans->commit();
685 Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
686 if ( xTrans.is() )
687 xTrans->commit();
690 void SAL_CALL ODocumentContainer::revert( ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
692 MutexGuard aGuard(m_aMutex);
693 Documents::iterator aIter = m_aDocumentMap.begin();
694 Documents::iterator aEnd = m_aDocumentMap.end();
695 for (; aIter != aEnd ; ++aIter)
697 Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
698 if ( xTrans.is() )
699 xTrans->revert();
701 Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
702 if ( xTrans.is() )
703 xTrans->revert();
706 Reference< XStorage> ODocumentContainer::getContainerStorage() const
708 return m_pImpl->m_pDataSource
709 ? m_pImpl->m_pDataSource->getStorage( m_bFormsContainer ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT )
710 : Reference< XStorage>();
713 void SAL_CALL ODocumentContainer::removeByName( const OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
715 ResettableMutexGuard aGuard(m_aMutex);
717 // check the arguments
718 if (_rName.isEmpty())
719 throw IllegalArgumentException();
721 if (!checkExistence(_rName))
722 throw NoSuchElementException(_rName,*this);
724 Reference< XCommandProcessor > xContent( implGetByName( _rName, true ), UNO_QUERY );
725 if ( xContent.is() )
727 Command aCommand;
729 aCommand.Name = "delete";
730 xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
733 // do the removal
734 implRemove(_rName);
736 notifyByName( aGuard, _rName, NULL, NULL, E_REMOVED, ContainerListemers );
739 void SAL_CALL ODocumentContainer::rename( const OUString& newName ) throw (SQLException, ElementExistException, RuntimeException, std::exception)
743 osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
744 if ( newName.equals( m_pImpl->m_aProps.aTitle ) )
745 return;
747 sal_Int32 nHandle = PROPERTY_ID_NAME;
748 Any aOld = makeAny(m_pImpl->m_aProps.aTitle);
749 Any aNew = makeAny(newName);
751 aGuard.clear();
752 fire(&nHandle, &aNew, &aOld, 1, sal_True );
753 m_pImpl->m_aProps.aTitle = newName;
754 fire(&nHandle, &aNew, &aOld, 1, sal_False );
756 catch(const PropertyVetoException&)
758 throw ElementExistException(newName,*this);
762 } // namespace dbaccess
764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */