21#include <core_resource.hxx>
27#include <osl/diagnose.h>
30#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
31#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/sdb/ErrorCondition.hpp>
47using namespace ::
cppu;
56 NamedDefinitions::const_iterator aPos =
find( _pDefinition );
66 [&_pDefinition] (
const NamedDefinitions::value_type& namedDef) {
67 return namedDef.second == _pDefinition;
76 [&_pDefinition] (
const NamedDefinitions::value_type& namedDef) {
77 return namedDef.second == _pDefinition;
84 ,
const Reference< XInterface >& _xParentContainer
91 ,m_bInPropertyChange(false)
92 ,m_bCheckSlash(_bCheckSlash)
95 m_pImpl->m_aProps.bIsDocument =
false;
96 m_pImpl->m_aProps.bIsFolder =
true;
99 for (
auto const& definition : rDefinitions)
101 m_aDocumentMap.emplace(definition.first, Documents::mapped_type() ).first );
112 EventObject aEvt(*
this);
119 Reference<XContent> xProp = elem.second;
123 ::comphelper::disposeComponent(xProp);
140 return ::comphelper::concatSequences(
141 OContentHelper::getTypes( ),
149 return css::uno::Sequence<sal_Int8>();
155 return "com.sun.star.sdb.ODefinitionContainer";
160 return {
"com.sun.star.sdb.DefinitionContainer",
"com.sun.star.ucb.Content" };
166 ResettableMutexGuard aGuard(
m_aMutex);
169 Reference< XContent > xNewElement(aElement,UNO_QUERY);
179 ResettableMutexGuard aGuard(
m_aMutex);
182 if (_rName.isEmpty())
183 throw IllegalArgumentException();
186 throw NoSuchElementException(_rName,*
this);
203 ResettableMutexGuard aGuard(
m_aMutex);
208 Reference< XContent > xNewElement(aElement,UNO_QUERY);
225 catch (
const NoSuchElementException&)
229 catch (
const WrappedTargetException&)
236 throw css::lang::WrappedTargetException(
237 "wrapped Exception " + e.Message,
238 css::uno::Reference<css::uno::XInterface>(),
a);
244 typedef Reference< XVeto > ( SAL_CALL XContainerApproveListener::*ContainerApprovalMethod )(
const ContainerEvent& );
246 struct RaiseExceptionFromVeto
253 explicit RaiseExceptionFromVeto( ContainerApprovalMethod _pMethod,
const ContainerEvent& _rEvent )
259 void operator()(
const Reference< XContainerApproveListener >& Listener )
const
265 Any eVetoDetails = xVeto->getDetails();
267 IllegalArgumentException aIllegalArgumentError;
268 if ( eVetoDetails >>= aIllegalArgumentError )
269 throw aIllegalArgumentError;
271 WrappedTargetException aWrappedError;
272 if ( eVetoDetails >>= aWrappedError )
275 throw WrappedTargetException( xVeto->getReason(), Listener, eVetoDetails );
281 const Reference< XContent >& _xNewElement,
const Reference< XContent >& _xOldElement,
290 ContainerEvent
aEvent( *
this,
Any( _rName ),
Any( _xNewElement ),
Any( _xOldElement ) );
293 switch ( _eOperation )
297 rContainer.
forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
298 RaiseExceptionFromVeto( &XContainerApproveListener::approveInsertElement,
aEvent ) );
304 rContainer.
forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
305 RaiseExceptionFromVeto( &XContainerApproveListener::approveReplaceElement,
aEvent ) );
311 rContainer.
forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
312 RaiseExceptionFromVeto( &XContainerApproveListener::approveRemoveElement,
aEvent ) );
324 if (_rxListener.is())
330 if (_rxListener.is())
362 return new ::comphelper::OEnumerationByIndex(
static_cast<XIndexAccess*
>(
this));
377 throw IndexOutOfBoundsException();
380 Reference<XContent> xProp = aPos->second;
385 aPos->second = Documents::mapped_type();
403 throw NoSuchElementException(_rName,*
this);
405 Reference< XContent > xProp = aMapPos->second;
407 if (_bReadIfNecessary && !xProp.is())
413 aMapPos->second = xProp;
425 OUString* pNames = aNames.getArray();
428 *pNames = elem.first;
445 Reference< XContent > xSource(_rSource.Source, UNO_QUERY);
449 if ( xSource == elem.second.get() )
453 elem.second = Documents::mapped_type();
475 bool lcl_ensureName(
const Reference< XContent >& _rxContent,
const OUString& _rName )
477 if ( !_rxContent.is() )
484 Reference< XPropertySet > xProps( _rxContent, UNO_QUERY );
487 OUString sCurrentName;
488 OSL_VERIFY( xProps->getPropertyValue(
PROPERTY_NAME ) >>= sCurrentName );
489 if ( sCurrentName == _rName )
493 catch(
const Exception& )
495 TOOLS_WARN_EXCEPTION(
"dbaccess",
"lcl_ensureName: caught an exception while obtaining the current name!" );
499 Reference< XRename > xRename( _rxContent, UNO_QUERY );
500 OSL_ENSURE( xRename.is(),
"lcl_ensureName: invalid content (not renameable)!" );
505 xRename->rename( _rName );
508 catch(
const Exception& )
521 Reference<XChild> xChild(_rxNewObject,UNO_QUERY);
523 xChild->setParent(
static_cast<OWeakObject*
>(
this));
527 if ( aFind == rDefinitions.
end() )
534 lcl_ensureName( _rxNewObject, _rName );
540 rDefinitions.
erase( pImpl );
541 pImpl->m_aProps.aTitle = _rName;
542 rDefinitions.
insert( _rName, pImpl );
549 if ( _rxNewObject.is() )
554 OSL_FAIL(
"ODefinitionContainer::implAppend: caught something !");
560 OSL_ENSURE(
checkExistence(_rName),
"ODefinitionContainer::implReplace : invalid name !");
564 aFind->second = _rxNewObject;
571 if ( _sName.isEmpty() )
572 throw IllegalArgumentException(
573 DBA_RES( RID_STR_NAME_MUST_NOT_BE_EMPTY ),
578 throw IllegalArgumentException(
583 if ( !_rxObject.is() )
584 throw IllegalArgumentException(
585 DBA_RES( RID_STR_NO_NULL_OBJECTS_IN_CONTAINER ),
590 if ( rDefinitions.
find( _sName ) != rDefinitions.
end() )
591 throw ElementExistException(
592 DBA_RES( RID_STR_NAME_ALREADY_USED ),
596 if ( !pContent.is() )
597 throw IllegalArgumentException(
598 DBA_RES( RID_STR_OBJECT_CONTAINER_MISMATCH ),
602 if ( rDefinitions.
find( pContent->getImpl() ) != rDefinitions.
end() )
603 throw ElementExistException(
604 DBA_RES( RID_STR_OBJECT_ALREADY_CONTAINED ),
611 if( evt.PropertyName !=
PROPERTY_NAME && evt.PropertyName !=
"Title" )
619 OUString sNewName,sOldName;
620 evt.OldValue >>= sOldName;
621 evt.NewValue >>= sNewName;
622 Reference<XContent> xContent( evt.Source, UNO_QUERY );
630 throw css::lang::WrappedTargetRuntimeException(
ex.Message,
644 aEvent.NewValue >>= sNewName;
646 throw PropertyVetoException();
652 OSL_ENSURE(_xNewObject.is(),
"ODefinitionContainer::addObjectListener: Object is null!");
653 Reference<XPropertySet> xProp(_xNewObject,UNO_QUERY);
663 Reference<XPropertySet> xProp(_xNewObject,UNO_QUERY);
void forEach(FuncT const &func)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 getLength() const
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
OUString getErrorMessage(const ErrorCondition _eCondition) const
mutable::osl::Mutex m_aMutex
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
css::uno::Type const & get()
void notifyDataSourceModified()
virtual void SAL_CALL disposing() override
const ::connectivity::SQLError m_aErrorHelper
NamedDefinitions m_aDefinitions
NamedDefinitions::iterator iterator
void insert(const OUString &_rName, TContentPtr _pDefinition)
const_iterator end() const
NamedDefinitions::const_iterator const_iterator
const_iterator find(const OUString &_rName) const
void erase(const OUString &_rName)
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL addContainerApproveListener(const css::uno::Reference< css::container::XContainerApproveListener > &Listener) override
const ODefinitionContainer_Impl & getDefinitions() const
void implReplace(const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_rxNewObject)
remove an object in the container.
void implAppend(const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_rxNewObject)
append a new object to the container.
virtual css::uno::Reference< css::ucb::XContent > createObject(const OUString &_rName)=0
create an object from its persistent data within the configuration.
void removeObjectListener(const css::uno::Reference< css::ucb::XContent > &_xNewObject)
ODefinitionContainer(const css::uno::Reference< css::uno::XComponentContext > &_xORB, const css::uno::Reference< css::uno::XInterface > &_xParentContainer, const TContentPtr &_pImpl, bool _bCheckSlash=true)
constructs the container.
virtual void SAL_CALL replaceByName(const OUString &_rName, const css::uno::Any &aElement) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL vetoableChange(const css::beans::PropertyChangeEvent &aEvent) override
::comphelper::OInterfaceContainerHelper2 m_aApproveListeners
::comphelper::OInterfaceContainerHelper2 m_aContainerListeners
virtual sal_Int32 SAL_CALL getCount() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
void approveNewObject(const OUString &_sName, const css::uno::Reference< css::ucb::XContent > &_rxObject) const
approve that the object given may be inserted into the container.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~ODefinitionContainer() override
void notifyByName(::osl::ResettableMutexGuard &_rGuard, const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_xNewElement, const css::uno::Reference< css::ucb::XContent > &xOldElement, ContainerOperation _eOperation, ListenerType _eType)
notifies our container/approve listeners
virtual void SAL_CALL insertByName(const OUString &_rName, const css::uno::Any &aElement) override
virtual void SAL_CALL disposing() override
void implRemove(const OUString &_rName)
remove all references to an object from the container.
virtual void SAL_CALL removeContainerApproveListener(const css::uno::Reference< css::container::XContainerApproveListener > &Listener) override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 _nIndex) override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
void addObjectListener(const css::uno::Reference< css::ucb::XContent > &_xNewObject)
virtual void SAL_CALL removeByName(const OUString &_rName) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
css::uno::Reference< css::ucb::XContent > implGetByName(const OUString &_rName, bool _bCreateIfNecessary)
get the object specified by the given name.
std::vector< Documents::iterator > m_aDocuments
virtual bool checkExistence(const OUString &_rName)
quickly checks if there already is an element with a given name.
bool impl_haveAnyListeners_nothrow() const
virtual css::uno::Type SAL_CALL getElementType() override
const ContainerEvent & m_rEvent
ContainerApprovalMethod m_pMethod
#define TOOLS_WARN_EXCEPTION(area, stream)
void disposeComponent(css::uno::Reference< TYPE > &_rxComp)
Any SAL_CALL getCaughtException()
std::shared_ptr< OContentHelper_Impl > TContentPtr
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
IMPLEMENT_FORWARD_XINTERFACE2(OStatement, OStatementBase, OStatement_IFACE)
constexpr OUStringLiteral PROPERTY_NAME(u"Name")