1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
63 class LocalNameApproval
: public IContainerApprove
65 ::connectivity::SQLError m_aErrors
;
68 explicit LocalNameApproval( const Reference
< XComponentContext
>& _rxContext
)
69 :m_aErrors( _rxContext
)
72 virtual ~LocalNameApproval() override
76 void SAL_CALL
approveElement( const OUString
& _rName
, const Reference
< XInterface
>& _rxElement
) 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
),
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
)
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
);
136 OUString
ODocumentContainer::determineContentType() const
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
>() );
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
;
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();
221 sPersistentName
= "Obj" + OUString::number(rDefinitions
.size() + 1);
222 Reference
<XNameAccess
> xElements(getContainerStorage(),UNO_QUERY
);
223 if ( xElements
.is() )
224 sPersistentName
= ::dbtools::createUniqueName(xElements
,sPersistentName
);
226 const bool bNeedClassID
= (0 == aClassID
.getLength()) && sURL
.isEmpty() ;
227 if ( xCopyFrom
.is() )
229 Sequence
<Any
> aIni(2);
230 aIni
[0] <<= getContainerStorage();
231 aIni
[1] <<= sPersistentName
;
233 aCommand
.Name
= "copyTo";
234 aCommand
.Argument
<<= aIni
;
236 xCopyFrom
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
237 Reference
<XPropertySet
> xProp(xCopyFrom
,UNO_QUERY
);
238 if ( xProp
.is() && xProp
->getPropertySetInfo().is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE
) )
239 xProp
->getPropertyValue(PROPERTY_AS_TEMPLATE
) >>= bAsTemplate
;
241 // if we do not have an own class ID, see if we can determine one from the copy we just created
243 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName
, m_aContext
, aClassID
);
249 if ( !sMediaType
.isEmpty() )
250 ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType
, m_aContext
, aClassID
);
251 else if ( !sDocServiceName
.isEmpty() )
253 ::comphelper::MimeConfigurationHelper
aConfigHelper( m_aContext
);
254 const Sequence
< NamedValue
> aProps( aConfigHelper
.GetObjectPropsByDocumentName( sDocServiceName
) );
255 const ::comphelper::NamedValueCollection
aMediaTypeProps( aProps
);
256 aClassID
= aMediaTypeProps
.getOrDefault( "ClassID", Sequence
< sal_Int8
>() );
262 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
263 TContentPtr pElementImpl
;
264 if ( bNew
|| ( aFind
== rDefinitions
.end() ) )
266 pElementImpl
.reset( new OContentHelper_Impl
);
268 pElementImpl
->m_aProps
.aTitle
= sName
;
270 pElementImpl
->m_aProps
.sPersistentName
= sPersistentName
;
271 pElementImpl
->m_aProps
.bAsTemplate
= bAsTemplate
;
272 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
275 pElementImpl
= aFind
->second
;
277 ::rtl::Reference
< ODocumentDefinition
> pDocDef
= new ODocumentDefinition( *this, m_aContext
, pElementImpl
, m_bFormsContainer
);
278 if ( aClassID
.getLength() )
280 pDocDef
->initialLoad( aClassID
, aCreationArgs
, xConnection
);
284 OSL_ENSURE( aCreationArgs
.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
286 xContent
= pDocDef
.get();
288 if ( !sURL
.isEmpty() )
290 Sequence
<Any
> aIni(2);
293 aCommand
.Name
= "insert";
294 aCommand
.Argument
<<= aIni
;
295 Reference
< XCommandProcessor
> xCommandProcessor(xContent
,UNO_QUERY
);
298 xCommandProcessor
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
302 else if ( ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
|| SERVICE_NAME_REPORT_COLLECTION
== ServiceSpecifier
)
304 const Any
* pBegin
= _aArguments
.getConstArray();
305 const Any
* pEnd
= pBegin
+ _aArguments
.getLength();
306 PropertyValue aValue
;
308 Reference
<XNameAccess
> xCopyFrom
;
309 for(;pBegin
!= pEnd
;++pBegin
)
312 if ( aValue
.Name
== PROPERTY_NAME
)
314 aValue
.Value
>>= sName
;
316 else if ( aValue
.Name
== PROPERTY_EMBEDDEDOBJECT
)
318 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
321 OSL_ENSURE(!sName
.isEmpty(),"Invalid name for a document container!");
322 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
323 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
324 TContentPtr pElementImpl
;
325 if ( aFind
== rDefinitions
.end() )
327 pElementImpl
.reset(new ODefinitionContainer_Impl
);
328 pElementImpl
->m_aProps
.aTitle
= sName
;
329 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
332 pElementImpl
= aFind
->second
;
333 OSL_ENSURE( pElementImpl
," Invalid entry in map!");
334 xContent
= new ODocumentContainer( m_aContext
, *this, pElementImpl
, ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
);
337 if ( xCopyFrom
.is() )
339 Sequence
< OUString
> aSeq
= xCopyFrom
->getElementNames();
340 const OUString
* elements
= aSeq
.getConstArray();
341 const OUString
* elementsEnd
= elements
+ aSeq
.getLength();
342 Reference
<XContent
> xObjectToCopy
;
344 Reference
<XMultiServiceFactory
> xORB(xContent
,UNO_QUERY
);
345 OSL_ENSURE(xORB
.is(),"No service factory given");
348 for(;elements
!= elementsEnd
;++elements
)
350 xCopyFrom
->getByName(*elements
) >>= xObjectToCopy
;
351 Sequence
< Any
> aArguments(3);
352 PropertyValue aArgument
;
354 aArgument
.Name
= "Name";
355 aArgument
.Value
<<= *elements
;
356 aArguments
[0] <<= aArgument
;
358 aArgument
.Name
= "Parent";
359 aArgument
.Value
<<= xContent
;
360 aArguments
[1] <<= aArgument
;
362 aArgument
.Name
= PROPERTY_EMBEDDEDOBJECT
;
363 aArgument
.Value
<<= xObjectToCopy
;
364 aArguments
[2] <<= aArgument
;
366 OUString sServiceName
;
367 if ( Reference
< XNameAccess
>( xObjectToCopy
, UNO_QUERY
).is() )
369 if ( m_bFormsContainer
)
370 sServiceName
= SERVICE_NAME_FORM_COLLECTION
;
372 sServiceName
= SERVICE_NAME_REPORT_COLLECTION
;
375 sServiceName
= SERVICE_SDB_DOCUMENTDEFINITION
;
377 Reference
<XContent
> xNew(xORB
->createInstanceWithArguments(sServiceName
,aArguments
),UNO_QUERY
);
378 Reference
<XNameContainer
> xNameContainer(xContent
,UNO_QUERY
);
379 if ( xNameContainer
.is() )
380 xNameContainer
->insertByName(*elements
,makeAny(xNew
));
389 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getAvailableServiceNames( ) throw (RuntimeException
, std::exception
)
391 Sequence
< OUString
> aSe(3);
392 aSe
[0] = SERVICE_SDB_DOCUMENTDEFINITION
;
393 aSe
[1] = SERVICE_NAME_FORM_COLLECTION
;
394 aSe
[2] = SERVICE_NAME_REPORT_COLLECTION
;
398 Any SAL_CALL
ODocumentContainer::execute( const Command
& aCommand
, sal_Int32 CommandId
, const Reference
< XCommandEnvironment
>& Environment
) throw (Exception
, CommandAbortedException
, RuntimeException
, std::exception
)
401 if ( aCommand
.Name
== "open" )
403 // open command for a folder content
404 OpenCommandArgument2 aOpenCommand
;
405 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
407 OSL_FAIL( "Wrong argument type!" );
408 ucbhelper::cancelCommandExecution(
409 makeAny( IllegalArgumentException(
411 static_cast< cppu::OWeakObject
* >( this ),
417 ( ( aOpenCommand
.Mode
== OpenMode::ALL
) ||
418 ( aOpenCommand
.Mode
== OpenMode::FOLDERS
) ||
419 ( aOpenCommand
.Mode
== OpenMode::DOCUMENTS
) );
423 // open as folder - return result set
425 Reference
< XDynamicResultSet
> xSet
426 = new DynamicResultSet( m_aContext
,
435 ucbhelper::cancelCommandExecution(
436 makeAny( UnsupportedOpenModeException(
438 static_cast< cppu::OWeakObject
* >( this ),
439 sal_Int16( aOpenCommand
.Mode
) ) ),
444 else if ( aCommand
.Name
== "insert" )
448 InsertCommandArgument arg
;
449 if ( !( aCommand
.Argument
>>= arg
) )
451 OSL_FAIL( "Wrong argument type!" );
452 ucbhelper::cancelCommandExecution(
453 makeAny( IllegalArgumentException(
455 static_cast< cppu::OWeakObject
* >( this ),
461 else if ( aCommand
.Name
== "delete" )
464 Sequence
< OUString
> aSeq
= getElementNames();
465 const OUString
* pIter
= aSeq
.getConstArray();
466 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
467 for(;pIter
!= pEnd
;++pIter
)
468 removeByName(*pIter
);
473 aRet
= OContentHelper::execute(aCommand
,CommandId
,Environment
);
479 bool lcl_queryContent(const OUString
& _sName
,Reference
< XNameContainer
>& _xNameContainer
,Any
& _rRet
,OUString
& _sSimpleName
)
481 sal_Int32 nIndex
= 0;
482 OUString sName
= _sName
.getToken(0,'/',nIndex
);
483 bool bRet
= _xNameContainer
->hasByName(sName
);
486 _rRet
= _xNameContainer
->getByName(_sSimpleName
= sName
);
487 while ( nIndex
!= -1 && bRet
)
489 sName
= _sName
.getToken(0,'/',nIndex
);
490 _xNameContainer
.set(_rRet
,UNO_QUERY
);
491 bRet
= _xNameContainer
.is();
494 bRet
= _xNameContainer
->hasByName(sName
);
495 _sSimpleName
= sName
;
497 _rRet
= _xNameContainer
->getByName(sName
);
502 _sSimpleName
= sName
; // a content
504 _xNameContainer
.clear(); // a sub folder doesn't exist
509 Reference
< XComponent
> SAL_CALL
ODocumentContainer::loadComponentFromURL( const OUString
& _sURL
510 , const OUString
& /*TargetFrameName*/
511 , sal_Int32
/*SearchFlags*/
512 , const Sequence
< PropertyValue
>& Arguments
) throw (IOException
, IllegalArgumentException
, RuntimeException
, std::exception
)
514 ::SolarMutexGuard aSolarGuard
;
516 MutexGuard
aGuard(m_aMutex
);
517 Reference
< XComponent
> xComp
;
521 Reference
< XNameContainer
> xNameContainer(this);
523 if ( !lcl_queryContent(_sURL
,xNameContainer
,aContent
,sName
) )
526 DBA_RES(RID_STR_NAME_NOT_FOUND
).replaceFirst("$name$", _sURL
));
527 throw IllegalArgumentException( sMessage
, *this, 1 );
530 Reference
< XCommandProcessor
> xContent(aContent
,UNO_QUERY
);
535 ::comphelper::NamedValueCollection
aArgs( Arguments
);
536 aCommand
.Name
= aArgs
.getOrDefault( "OpenMode", OUString("open") );
537 aArgs
.remove( "OpenMode" );
539 OpenCommandArgument2 aOpenCommand
;
540 aOpenCommand
.Mode
= OpenMode::DOCUMENT
;
541 aArgs
.put( "OpenCommandArgument", aOpenCommand
);
543 aCommand
.Argument
<<= aArgs
.getPropertyValues();
544 xComp
.set(xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>()),UNO_QUERY
);
547 catch(const NoSuchElementException
&)
549 throw IllegalArgumentException();
551 catch(const WrappedTargetException
&e
)
553 throw WrappedTargetRuntimeException(e
.Message
, e
.Context
, e
.TargetException
);
558 Any SAL_CALL
ODocumentContainer::getByHierarchicalName( const OUString
& _sName
) throw (NoSuchElementException
, RuntimeException
, std::exception
)
560 MutexGuard
aGuard(m_aMutex
);
562 Reference
< XNameContainer
> xNameContainer(this);
564 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
566 throw NoSuchElementException(_sName
,*this);
569 sal_Bool SAL_CALL
ODocumentContainer::hasByHierarchicalName( const OUString
& _sName
) throw (RuntimeException
, std::exception
)
571 MutexGuard
aGuard(m_aMutex
);
573 Reference
< XNameContainer
> xNameContainer(this);
575 return lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
);
578 // XHierarchicalNameContainer
579 void SAL_CALL
ODocumentContainer::insertByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
, std::exception
)
581 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
582 if ( !xContent
.is() )
583 throw IllegalArgumentException();
585 ClearableMutexGuard
aGuard(m_aMutex
);
587 Reference
< XNameContainer
> xNameContainer(this);
589 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
590 throw ElementExistException(_sName
,*this);
592 if ( !xNameContainer
.is() )
594 sal_Int32 index
= sName
.getLength();
596 DBA_RES(RID_STR_NO_SUB_FOLDER
).replaceFirst("$folder$",
597 _sName
.getToken(0,'/',index
)));
598 throw IllegalArgumentException( sMessage
, *this, 1 );
601 xNameContainer
->insertByName(sName
,_aElement
);
604 void SAL_CALL
ODocumentContainer::removeByHierarchicalName( const OUString
& _sName
) throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
606 if ( _sName
.isEmpty() )
607 throw NoSuchElementException(_sName
,*this);
609 ClearableMutexGuard
aGuard(m_aMutex
);
612 Reference
< XNameContainer
> xNameContainer(this);
613 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
614 throw NoSuchElementException(_sName
,*this);
616 xNameContainer
->removeByName(sName
);
619 // XHierarchicalNameReplace
620 void SAL_CALL
ODocumentContainer::replaceByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
622 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
623 if ( !xContent
.is() )
624 throw IllegalArgumentException();
626 ClearableMutexGuard
aGuard(m_aMutex
);
629 Reference
< XNameContainer
> xNameContainer(this);
630 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
631 throw NoSuchElementException(_sName
,*this);
633 xNameContainer
->replaceByName(sName
,_aElement
);
636 OUString SAL_CALL
ODocumentContainer::getHierarchicalName() throw (RuntimeException
, std::exception
)
638 ::osl::MutexGuard
aGuard( m_aMutex
);
639 return impl_getHierarchicalName( false );
642 OUString SAL_CALL
ODocumentContainer::composeHierarchicalName( const OUString
& i_rRelativeName
) throw (IllegalArgumentException
, NoSupportException
, RuntimeException
, std::exception
)
644 OUString aBuffer
= getHierarchicalName() + "/" + i_rRelativeName
;
648 ::rtl::Reference
<OContentHelper
> ODocumentContainer::getContent(const OUString
& _sName
) const
650 ::rtl::Reference
<OContentHelper
> pContent
= nullptr;
653 Reference
<XUnoTunnel
> xUnoTunnel(const_cast<ODocumentContainer
*>(this)->implGetByName( _sName
, true ), UNO_QUERY
);
654 if ( xUnoTunnel
.is() )
655 pContent
= reinterpret_cast<OContentHelper
*>(xUnoTunnel
->getSomething(OContentHelper::getUnoTunnelImplementationId()));
657 catch(const Exception
&)
663 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32
/*_nHandle*/, Any
& _rDefault
) const
668 void SAL_CALL
ODocumentContainer::commit( ) throw (css::io::IOException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
)
670 MutexGuard
aGuard(m_aMutex
);
671 Documents::const_iterator aIter
= m_aDocumentMap
.begin();
672 Documents::const_iterator aEnd
= m_aDocumentMap
.end();
673 for (; aIter
!= aEnd
; ++aIter
)
675 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
679 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
684 void SAL_CALL
ODocumentContainer::revert( ) throw (css::io::IOException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
)
686 MutexGuard
aGuard(m_aMutex
);
687 Documents::const_iterator aIter
= m_aDocumentMap
.begin();
688 Documents::const_iterator aEnd
= m_aDocumentMap
.end();
689 for (; aIter
!= aEnd
; ++aIter
)
691 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
695 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
700 Reference
< XStorage
> ODocumentContainer::getContainerStorage() const
702 return m_pImpl
->m_pDataSource
703 ? m_pImpl
->m_pDataSource
->getStorage( m_bFormsContainer
? ODatabaseModelImpl::E_FORM
: ODatabaseModelImpl::E_REPORT
)
704 : Reference
< XStorage
>();
707 void SAL_CALL
ODocumentContainer::removeByName( const OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
709 ResettableMutexGuard
aGuard(m_aMutex
);
711 // check the arguments
712 if (_rName
.isEmpty())
713 throw IllegalArgumentException();
715 if (!checkExistence(_rName
))
716 throw NoSuchElementException(_rName
,*this);
718 Reference
< XCommandProcessor
> xContent( implGetByName( _rName
, true ), UNO_QUERY
);
723 aCommand
.Name
= "delete";
724 xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>());
730 notifyByName( aGuard
, _rName
, nullptr, nullptr, E_REMOVED
, ContainerListemers
);
733 void SAL_CALL
ODocumentContainer::rename( const OUString
& newName
) throw (SQLException
, ElementExistException
, RuntimeException
, std::exception
)
737 osl::ClearableGuard
< osl::Mutex
> aGuard(m_aMutex
);
738 if ( newName
.equals( m_pImpl
->m_aProps
.aTitle
) )
741 sal_Int32 nHandle
= PROPERTY_ID_NAME
;
742 Any aOld
= makeAny(m_pImpl
->m_aProps
.aTitle
);
743 Any aNew
= makeAny(newName
);
746 fire(&nHandle
, &aNew
, &aOld
, 1, true );
747 m_pImpl
->m_aProps
.aTitle
= newName
;
748 fire(&nHandle
, &aNew
, &aOld
, 1, false );
750 catch(const PropertyVetoException
&)
752 throw ElementExistException(newName
,*this);
756 } // namespace dbaccess
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */