1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentcontainer.cxx,v $
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_dbaccess.hxx"
34 #ifndef _DBA_COREDATAACCESS_DOCUMENTCONTAINER_HXX_
35 #include "documentcontainer.hxx"
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
40 #ifndef _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
41 #include "documentdefinition.hxx"
43 #ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
44 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
46 #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
47 #include <com/sun/star/ucb/OpenMode.hpp>
49 #ifndef _TOOLS_DEBUG_HXX
50 #include <tools/debug.hxx>
52 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
53 #include <connectivity/dbtools.hxx>
55 #ifndef DBA_UCPRESULTSET_HXX
56 #include "myucp_resultset.hxx"
58 #ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX_
59 #include <ucbhelper/cancelcommandexecution.hxx>
61 #ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDOPENMODEEXCEPTION_HPP_
62 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
64 #ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
65 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
67 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
68 #include <com/sun/star/beans/PropertyAttribute.hpp>
70 #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
71 #include <com/sun/star/sdb/ErrorCondition.hpp>
73 #ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
74 #include "datasource.hxx"
76 #include <comphelper/classids.hxx>
77 #ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
78 #include <comphelper/mimeconfighelper.hxx>
80 #ifndef INCLUDED_COMPHELPER_STRING_HXX
81 #include <comphelper/string.hxx>
83 #ifndef CONNECTIVITY_SQLERROR_HXX
84 #include <connectivity/sqlerror.hxx>
86 #include "core_resource.hxx"
87 #include "core_resource.hrc"
89 #include <vcl/svapp.hxx>
90 #include <vos/mutex.hxx>
92 using namespace ::com::sun::star::uno
;
93 using namespace ::com::sun::star::lang
;
94 using namespace ::com::sun::star::embed
;
95 using namespace ::com::sun::star::beans
;
96 using namespace ::com::sun::star::container
;
97 using namespace ::com::sun::star::ucb
;
98 using namespace ::com::sun::star::sdbc
;
99 using namespace ::com::sun::star::sdb
;
100 using namespace ::com::sun::star::io
;
101 using namespace ::osl
;
102 using namespace ::comphelper
;
103 using namespace ::cppu
;
105 //........................................................................
108 //........................................................................
110 //==========================================================================
111 //= LocalNameApproval
112 //==========================================================================
113 class LocalNameApproval
: public IContainerApprove
115 ::connectivity::SQLError m_aErrors
;
118 LocalNameApproval( const Reference
< XMultiServiceFactory
>& _rxFactory
)
119 :m_aErrors( ::comphelper::ComponentContext( _rxFactory
) )
122 virtual ~LocalNameApproval()
126 void SAL_CALL
approveElement( const ::rtl::OUString
& _rName
, const Reference
< XInterface
>& _rxElement
);
129 //--------------------------------------------------------------------------
130 void SAL_CALL
LocalNameApproval::approveElement( const ::rtl::OUString
& _rName
, const Reference
< XInterface
>& /*_rxElement*/ )
132 if ( _rName
.indexOf( '/' ) != -1 )
133 throw IllegalArgumentException(
134 m_aErrors
.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES
),
140 //==========================================================================
141 //= ODocumentContainer
142 //==========================================================================
143 DBG_NAME(ODocumentContainer
)
144 //--------------------------------------------------------------------------
145 ODocumentContainer::ODocumentContainer(const Reference
< XMultiServiceFactory
>& _xORB
146 ,const Reference
< XInterface
>& _xParentContainer
147 ,const TContentPtr
& _pImpl
148 , sal_Bool _bFormsContainer
150 :ODefinitionContainer(_xORB
,_xParentContainer
,_pImpl
)
151 ,OPropertyStateContainer(OContentHelper::rBHelper
)
152 ,m_bFormsContainer(_bFormsContainer
)
154 DBG_CTOR(ODocumentContainer
, NULL
);
155 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
| PropertyAttribute::CONSTRAINED
,
156 &m_pImpl
->m_aProps
.aTitle
, ::getCppuType(&m_pImpl
->m_aProps
.aTitle
));
158 setElementApproval( PContainerApprove( new LocalNameApproval ( _xORB
) ) );
161 //--------------------------------------------------------------------------
162 ODocumentContainer::~ODocumentContainer()
164 DBG_DTOR(ODocumentContainer
, NULL
);
166 if ( !OContentHelper::rBHelper
.bInDispose
&& !OContentHelper::rBHelper
.bDisposed
)
172 // -----------------------------------------------------------------------------
173 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer
,ODefinitionContainer
,ODocumentContainer_Base
,OPropertyStateContainer
)
174 IMPLEMENT_TYPEPROVIDER3(ODocumentContainer
,ODefinitionContainer
,OPropertyStateContainer
,ODocumentContainer_Base
);
175 IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer
, "com.sun.star.comp.dba.ODocumentContainer");
176 IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer
);
177 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer
)
179 Sequence
< ::rtl::OUString
> SAL_CALL
ODocumentContainer::getSupportedServiceNames( ) throw(RuntimeException
)
181 Sequence
< ::rtl::OUString
> aSupported(1);
182 aSupported
[0] = m_bFormsContainer
? SERVICE_NAME_FORM_COLLECTION
: SERVICE_NAME_REPORT_COLLECTION
;
186 // -----------------------------------------------------------------------------
187 ::rtl::OUString
ODocumentContainer::determineContentType() const
189 return ::rtl::OUString();
192 //--------------------------------------------------------------------------
193 Reference
< XContent
> ODocumentContainer::createObject( const ::rtl::OUString
& _rName
)
195 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
196 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( _rName
);
197 OSL_ENSURE( aFind
!= rDefinitions
.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
198 if ( aFind
->second
->m_aProps
.bIsFolder
)
199 return new ODocumentContainer( m_aContext
.getLegacyServiceFactory(), *this, aFind
->second
, m_bFormsContainer
);
200 return new ODocumentDefinition( *this, m_aContext
.getLegacyServiceFactory(), aFind
->second
, m_bFormsContainer
);
202 // -----------------------------------------------------------------------------
203 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstance( const ::rtl::OUString
& aServiceSpecifier
) throw (Exception
, RuntimeException
)
205 return createInstanceWithArguments( aServiceSpecifier
, Sequence
< Any
>() );
207 // -----------------------------------------------------------------------------
208 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstanceWithArguments( const ::rtl::OUString
& ServiceSpecifier
, const Sequence
< Any
>& _aArguments
) throw (Exception
, RuntimeException
)
210 Reference
< XInterface
> xRet
;
211 Reference
< XContent
> xContent
;
212 if ( ServiceSpecifier
== SERVICE_SDB_DOCUMENTDEFINITION
)
214 MutexGuard
aGuard(m_aMutex
);
215 ::rtl::OUString sName
,sPersistentName
,sURL
;
216 Reference
< XCommandProcessor
> xCopyFrom
;
217 Reference
<XConnection
> xConnection
;
218 Sequence
<sal_Int8
> aClassID
;
219 sal_Bool bAsTemplate
= sal_False
;
221 const Any
* pBegin
= _aArguments
.getConstArray();
222 const Any
* pEnd
= pBegin
+ _aArguments
.getLength();
223 PropertyValue aValue
;
224 for(;pBegin
!= pEnd
;++pBegin
)
227 if ( aValue
.Name
.equalsAscii(PROPERTY_NAME
) )
229 aValue
.Value
>>= sName
;
231 else if ( aValue
.Name
.equalsAscii(PROPERTY_PERSISTENT_NAME
) )
233 aValue
.Value
>>= sPersistentName
;
235 else if ( aValue
.Name
.equalsAscii(PROPERTY_EMBEDDEDOBJECT
) )
237 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
239 else if ( aValue
.Name
.equalsAscii(PROPERTY_URL
) )
241 aValue
.Value
>>= sURL
;
243 else if ( aValue
.Name
.equalsAscii(PROPERTY_ACTIVE_CONNECTION
) )
245 xConnection
.set(aValue
.Value
,UNO_QUERY
);
247 else if ( aValue
.Name
.equalsAscii("ClassID") )
249 if (! ( aValue
.Value
>>= aClassID
) )
251 // Extended for usage also with a string
252 ::rtl::OUString suValue
;
253 aValue
.Value
>>= suValue
;
254 aClassID
= ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( suValue
);
257 rtl::OUString suClassID
= ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation(aClassID
);
258 volatile int dummy
= 0;
262 else if ( aValue
.Name
.equalsAscii(PROPERTY_AS_TEMPLATE
) )
264 aValue
.Value
>>= bAsTemplate
;
268 // DBG_ASSERT("unknown property exception");
272 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
274 sal_Bool bNew
= ( 0 == sPersistentName
.getLength() );
277 const static ::rtl::OUString
sBaseName(RTL_CONSTASCII_USTRINGPARAM("Obj"));
278 // -----------------------------------------------------------------------------
279 sPersistentName
= sBaseName
;
280 sPersistentName
+= ::rtl::OUString::valueOf(sal_Int32(rDefinitions
.size() + 1));
281 Reference
<XNameAccess
> xElements(getContainerStorage(),UNO_QUERY
);
282 if ( xElements
.is() )
283 sPersistentName
= ::dbtools::createUniqueName(xElements
,sPersistentName
);
285 if ( xCopyFrom
.is() )
287 Sequence
<Any
> aIni(2);
288 aIni
[0] <<= getContainerStorage();
289 aIni
[1] <<= sPersistentName
;
291 aCommand
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("copyTo"));
292 aCommand
.Argument
<<= aIni
;
294 xCopyFrom
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
295 Reference
<XPropertySet
> xProp(xCopyFrom
,UNO_QUERY
);
296 if ( xProp
.is() && xProp
->getPropertySetInfo().is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE
) )
297 xProp
->getPropertyValue(PROPERTY_AS_TEMPLATE
) >>= bAsTemplate
;
300 if ( ( aClassID
.getLength() == 0 ) && ( 0 == sURL
.getLength() ) )
301 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName
, m_aContext
, aClassID
);
304 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
305 TContentPtr pElementImpl
;
306 if ( bNew
|| ( aFind
== rDefinitions
.end() ) )
308 pElementImpl
.reset( new OContentHelper_Impl
);
310 pElementImpl
->m_aProps
.aTitle
= sName
;
312 pElementImpl
->m_aProps
.sPersistentName
= sPersistentName
;
313 pElementImpl
->m_aProps
.bAsTemplate
= bAsTemplate
;
314 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
317 pElementImpl
= aFind
->second
;
319 xContent
= new ODocumentDefinition( *this, m_aContext
.getLegacyServiceFactory(), pElementImpl
, m_bFormsContainer
, aClassID
, xConnection
);
321 if ( sURL
.getLength() )
323 Sequence
<Any
> aIni(2);
326 aCommand
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("insert"));
327 aCommand
.Argument
<<= aIni
;
328 Reference
< XCommandProcessor
> xCommandProcessor(xContent
,UNO_QUERY
);
331 xCommandProcessor
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
337 else if ( ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
|| SERVICE_NAME_REPORT_COLLECTION
== ServiceSpecifier
)
339 const Any
* pBegin
= _aArguments
.getConstArray();
340 const Any
* pEnd
= pBegin
+ _aArguments
.getLength();
341 PropertyValue aValue
;
342 ::rtl::OUString sName
;
343 Reference
<XNameAccess
> xCopyFrom
;
344 for(;pBegin
!= pEnd
;++pBegin
)
347 if ( aValue
.Name
.equalsAscii(PROPERTY_NAME
) )
349 aValue
.Value
>>= sName
;
351 else if ( aValue
.Name
.equalsAscii(PROPERTY_EMBEDDEDOBJECT
) )
353 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
356 OSL_ENSURE(sName
.getLength(),"Invalid name for a document container!");
357 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
358 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
359 TContentPtr pElementImpl
;
360 if ( aFind
== rDefinitions
.end() )
362 pElementImpl
.reset(new ODefinitionContainer_Impl
);
363 pElementImpl
->m_aProps
.aTitle
= sName
;
364 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
367 pElementImpl
= aFind
->second
;
368 OSL_ENSURE( pElementImpl
," Invalid entry in map!");
369 xContent
= new ODocumentContainer( m_aContext
.getLegacyServiceFactory(), *this, pElementImpl
, ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
);
372 if ( xCopyFrom
.is() )
374 Sequence
< ::rtl::OUString
> aSeq
= xCopyFrom
->getElementNames();
375 const ::rtl::OUString
* elements
= aSeq
.getConstArray();
376 const ::rtl::OUString
* elementsEnd
= elements
+ aSeq
.getLength();
377 Reference
<XContent
> xObjectToCopy
;
379 Reference
<XMultiServiceFactory
> xORB(xContent
,UNO_QUERY
);
380 OSL_ENSURE(xORB
.is(),"No service factory given");
383 for(;elements
!= elementsEnd
;++elements
)
385 xCopyFrom
->getByName(*elements
) >>= xObjectToCopy
;
386 Sequence
< Any
> aArguments(3);
387 PropertyValue aArgument
;
389 aArgument
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
390 aArgument
.Value
<<= *elements
;
391 aArguments
[0] <<= aArgument
;
393 aArgument
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
394 aArgument
.Value
<<= xContent
;
395 aArguments
[1] <<= aArgument
;
397 aArgument
.Name
= PROPERTY_EMBEDDEDOBJECT
;
398 aArgument
.Value
<<= xObjectToCopy
;
399 aArguments
[2] <<= aArgument
;
401 ::rtl::OUString sServiceName
;
402 if ( Reference
< XNameAccess
>( xObjectToCopy
, UNO_QUERY
).is() )
403 if ( m_bFormsContainer
)
404 sServiceName
= SERVICE_NAME_FORM_COLLECTION
;
405 else sServiceName
= SERVICE_NAME_REPORT_COLLECTION
;
407 sServiceName
= SERVICE_SDB_DOCUMENTDEFINITION
;
409 Reference
<XContent
> xNew(xORB
->createInstanceWithArguments(sServiceName
,aArguments
),UNO_QUERY
);
410 Reference
<XNameContainer
> xNameContainer(xContent
,UNO_QUERY
);
411 if ( xNameContainer
.is() )
412 xNameContainer
->insertByName(*elements
,makeAny(xNew
));
420 // -----------------------------------------------------------------------------
421 Sequence
< ::rtl::OUString
> SAL_CALL
ODocumentContainer::getAvailableServiceNames( ) throw (RuntimeException
)
423 Sequence
< ::rtl::OUString
> aSe(3);
424 aSe
[0] = SERVICE_SDB_DOCUMENTDEFINITION
;
425 aSe
[1] = SERVICE_NAME_FORM_COLLECTION
;
426 aSe
[2] = SERVICE_NAME_REPORT_COLLECTION
;
429 // -----------------------------------------------------------------------------
430 Any SAL_CALL
ODocumentContainer::execute( const Command
& aCommand
, sal_Int32 CommandId
, const Reference
< XCommandEnvironment
>& Environment
) throw (Exception
, CommandAbortedException
, RuntimeException
)
433 if ( aCommand
.Name
.compareToAscii( "open" ) == 0 )
435 //////////////////////////////////////////////////////////////////
436 // open command for a folder content
437 //////////////////////////////////////////////////////////////////
438 OpenCommandArgument2 aOpenCommand
;
439 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
441 OSL_ENSURE( sal_False
, "Wrong argument type!" );
442 ucbhelper::cancelCommandExecution(
443 makeAny( IllegalArgumentException(
445 static_cast< cppu::OWeakObject
* >( this ),
450 sal_Bool bOpenFolder
=
451 ( ( aOpenCommand
.Mode
== OpenMode::ALL
) ||
452 ( aOpenCommand
.Mode
== OpenMode::FOLDERS
) ||
453 ( aOpenCommand
.Mode
== OpenMode::DOCUMENTS
) );
457 // open as folder - return result set
459 Reference
< XDynamicResultSet
> xSet
460 = new DynamicResultSet( m_aContext
.getLegacyServiceFactory(),
469 ucbhelper::cancelCommandExecution(
470 makeAny( UnsupportedOpenModeException(
472 static_cast< cppu::OWeakObject
* >( this ),
473 sal_Int16( aOpenCommand
.Mode
) ) ),
478 else if ( aCommand
.Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
480 //////////////////////////////////////////////////////////////////
482 //////////////////////////////////////////////////////////////////
484 InsertCommandArgument arg
;
485 if ( !( aCommand
.Argument
>>= arg
) )
487 OSL_ENSURE( sal_False
, "Wrong argument type!" );
488 ucbhelper::cancelCommandExecution(
489 makeAny( IllegalArgumentException(
491 static_cast< cppu::OWeakObject
* >( this ),
497 else if ( aCommand
.Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
499 //////////////////////////////////////////////////////////////////
501 //////////////////////////////////////////////////////////////////
502 Sequence
< ::rtl::OUString
> aSeq
= getElementNames();
503 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
504 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
505 for(;pIter
!= pEnd
;++pIter
)
506 removeByName(*pIter
);
511 aRet
= OContentHelper::execute(aCommand
,CommandId
,Environment
);
514 // -----------------------------------------------------------------------------
517 sal_Bool
lcl_queryContent(const ::rtl::OUString
& _sName
,Reference
< XNameContainer
>& _xNameContainer
,Any
& _rRet
,::rtl::OUString
& _sSimpleName
)
519 sal_Bool bRet
= sal_False
;
520 sal_Int32 nIndex
= 0;
521 ::rtl::OUString sName
= _sName
.getToken(0,'/',nIndex
);
522 bRet
= _xNameContainer
->hasByName(sName
);
525 _rRet
= _xNameContainer
->getByName(_sSimpleName
= sName
);
526 while ( nIndex
!= -1 )
528 sName
= _sName
.getToken(0,'/',nIndex
);
529 _xNameContainer
.set(_rRet
,UNO_QUERY
);
530 bRet
= _xNameContainer
.is();
533 bRet
= _xNameContainer
->hasByName(sName
);
534 _sSimpleName
= sName
;
536 _rRet
= _xNameContainer
->getByName(sName
);
540 else if ( nIndex
== -1 )
541 _sSimpleName
= sName
; // a content on the root content
545 // -----------------------------------------------------------------------------
546 Reference
< XComponent
> SAL_CALL
ODocumentContainer::loadComponentFromURL( const ::rtl::OUString
& _sURL
547 , const ::rtl::OUString
& /*TargetFrameName*/
548 , sal_Int32
/*SearchFlags*/
549 , const Sequence
< PropertyValue
>& Arguments
) throw (IOException
, IllegalArgumentException
, RuntimeException
)
551 vos::OGuard
aSolarGuard(Application::GetSolarMutex());
553 MutexGuard
aGuard(m_aMutex
);
554 Reference
< XComponent
> xComp
;
558 Reference
< XNameContainer
> xNameContainer(this);
559 ::rtl::OUString sName
;
560 if ( !lcl_queryContent(_sURL
,xNameContainer
,aContent
,sName
) )
562 ::rtl::OUString
sMessage( DBA_RES( RID_STR_NAME_NOT_FOUND
) );
564 ::comphelper::string::searchAndReplaceAsciiI( sMessage
, "$name$", _sURL
);
565 throw IllegalArgumentException( sMessage
, *this, 1 );
568 Reference
< XCommandProcessor
> xContent(aContent
,UNO_QUERY
);
573 static const ::rtl::OUString s_sOpenMode
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenMode"));
574 const PropertyValue
* pIter
= Arguments
.getConstArray();
575 const PropertyValue
* pEnd
= pIter
+ Arguments
.getLength();
576 for( ; pIter
!= pEnd
; ++pIter
)
578 if ( pIter
->Name
== s_sOpenMode
)
580 pIter
->Value
>>= aCommand
.Name
;
584 if ( !aCommand
.Name
.getLength() ) // default mode
585 aCommand
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("open"));
586 OpenCommandArgument2 aOpenCommand
;
587 aOpenCommand
.Mode
= OpenMode::DOCUMENT
;
589 Sequence
< PropertyValue
> aArguments(Arguments
);
590 sal_Int32 nLen
= aArguments
.getLength();
591 aArguments
.realloc(nLen
+ 1);
593 aArguments
[nLen
].Value
<<= aOpenCommand
;
594 aCommand
.Argument
<<= aArguments
;
595 xComp
.set(xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>()),UNO_QUERY
);
598 catch(NoSuchElementException
)
600 throw IllegalArgumentException();
602 catch(WrappedTargetException e
)
604 // throw IllegalArgumentException();
609 // -----------------------------------------------------------------------------
610 Any SAL_CALL
ODocumentContainer::getByHierarchicalName( const ::rtl::OUString
& _sName
) throw (NoSuchElementException
, RuntimeException
)
612 MutexGuard
aGuard(m_aMutex
);
614 Reference
< XNameContainer
> xNameContainer(this);
615 ::rtl::OUString sName
;
616 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
618 throw NoSuchElementException(_sName
,*this);
620 // -----------------------------------------------------------------------------
621 sal_Bool SAL_CALL
ODocumentContainer::hasByHierarchicalName( const ::rtl::OUString
& _sName
) throw (RuntimeException
)
623 MutexGuard
aGuard(m_aMutex
);
625 Reference
< XNameContainer
> xNameContainer(this);
626 ::rtl::OUString sName
;
627 return lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
);
629 // -----------------------------------------------------------------------------
630 // XHierarchicalNameContainer
631 void SAL_CALL
ODocumentContainer::insertByHierarchicalName( const ::rtl::OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
)
633 ClearableMutexGuard
aGuard(m_aMutex
);
635 Reference
< XNameContainer
> xNameContainer(this);
636 ::rtl::OUString sName
;
637 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
638 throw ElementExistException(_sName
,*this);
639 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
640 if ( !xContent
.is() )
641 throw IllegalArgumentException();
643 xNameContainer
->insertByName(sName
,_aElement
);
645 // -----------------------------------------------------------------------------
646 void SAL_CALL
ODocumentContainer::removeByHierarchicalName( const ::rtl::OUString
& _sName
) throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
648 if ( !_sName
.getLength() )
649 throw NoSuchElementException(_sName
,*this);
651 ClearableMutexGuard
aGuard(m_aMutex
);
653 ::rtl::OUString sName
;
654 Reference
< XNameContainer
> xNameContainer(this);
655 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
656 throw NoSuchElementException(_sName
,*this);
658 xNameContainer
->removeByName(sName
);
660 // -----------------------------------------------------------------------------
661 // XHierarchicalNameReplace
662 void SAL_CALL
ODocumentContainer::replaceByHierarchicalName( const ::rtl::OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
664 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
665 if ( !xContent
.is() )
666 throw IllegalArgumentException();
668 ClearableMutexGuard
aGuard(m_aMutex
);
670 ::rtl::OUString sName
;
671 Reference
< XNameContainer
> xNameContainer(this);
672 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
673 throw NoSuchElementException(_sName
,*this);
675 xNameContainer
->replaceByName(sName
,_aElement
);
677 // -----------------------------------------------------------------------------
678 ::rtl::Reference
<OContentHelper
> ODocumentContainer::getContent(const ::rtl::OUString
& _sName
) const
680 ::rtl::Reference
<OContentHelper
> pContent
= NULL
;
683 Reference
<XUnoTunnel
> xUnoTunnel(const_cast<ODocumentContainer
*>(this)->implGetByName( _sName
, sal_True
), UNO_QUERY
);
684 if ( xUnoTunnel
.is() )
685 pContent
= reinterpret_cast<OContentHelper
*>(xUnoTunnel
->getSomething(OContentHelper::getUnoTunnelImplementationId()));
692 // -----------------------------------------------------------------------------
693 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32
/*_nHandle*/, Any
& _rDefault
) const
697 // -----------------------------------------------------------------------------
698 void SAL_CALL
ODocumentContainer::commit( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
700 MutexGuard
aGuard(m_aMutex
);
701 Documents::iterator aIter
= m_aDocumentMap
.begin();
702 Documents::iterator aEnd
= m_aDocumentMap
.end();
703 for (; aIter
!= aEnd
; ++aIter
)
705 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
709 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
713 // -----------------------------------------------------------------------------
714 void SAL_CALL
ODocumentContainer::revert( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
716 MutexGuard
aGuard(m_aMutex
);
717 Documents::iterator aIter
= m_aDocumentMap
.begin();
718 Documents::iterator aEnd
= m_aDocumentMap
.end();
719 for (; aIter
!= aEnd
; ++aIter
)
721 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
725 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
729 // -----------------------------------------------------------------------------
730 Reference
< XStorage
> ODocumentContainer::getContainerStorage() const
732 return m_pImpl
->m_pDataSource
733 ? m_pImpl
->m_pDataSource
->getStorage( ODatabaseModelImpl::getObjectContainerStorageName( m_bFormsContainer
? ODatabaseModelImpl::E_FORM
: ODatabaseModelImpl::E_REPORT
) )
734 : Reference
< XStorage
>();
737 // -----------------------------------------------------------------------------
738 void SAL_CALL
ODocumentContainer::removeByName( const ::rtl::OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
740 ResettableMutexGuard
aGuard(m_aMutex
);
742 // check the arguments
743 if (!_rName
.getLength())
744 throw IllegalArgumentException();
746 if (!checkExistence(_rName
))
747 throw NoSuchElementException(_rName
,*this);
749 Reference
< XCommandProcessor
> xContent( implGetByName( _rName
, sal_True
), UNO_QUERY
);
754 aCommand
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete"));
755 xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>());
761 // disposeComponent(xContent); // no dispose here, the object may be inserted again under a different name
763 notifyByName( aGuard
, _rName
, NULL
, NULL
, E_REMOVED
, ContainerListemers
);
765 // -----------------------------------------------------------------------------
766 // -----------------------------------------------------------------------------
767 void SAL_CALL
ODocumentContainer::rename( const ::rtl::OUString
& newName
) throw (SQLException
, ElementExistException
, RuntimeException
)
771 osl::ClearableGuard
< osl::Mutex
> aGuard(m_aMutex
);
772 if ( newName
.equals( m_pImpl
->m_aProps
.aTitle
) )
775 sal_Int32 nHandle
= PROPERTY_ID_NAME
;
776 Any aOld
= makeAny(m_pImpl
->m_aProps
.aTitle
);
777 Any aNew
= makeAny(newName
);
780 fire(&nHandle
, &aNew
, &aOld
, 1, sal_True
);
781 m_pImpl
->m_aProps
.aTitle
= newName
;
782 fire(&nHandle
, &aNew
, &aOld
, 1, sal_False
);
784 catch(const PropertyVetoException
&)
786 throw ElementExistException(newName
,*this);
790 //........................................................................
791 } // namespace dbaccess
792 //........................................................................