22#include <com/sun/star/container/ElementExistException.hpp>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26#include <com/sun/star/sdbc/SQLException.hpp>
41using namespace ::
cppu;
53 typedef std::multimap< OUString, T , ::comphelper::UStringMixLess> ObjectMap;
54 typedef typename ObjectMap::iterator ObjectIter;
55 typedef typename ObjectMap::value_type ObjectEntry;
62 OHardRefMap(
bool _bCase)
67 virtual bool exists(
const OUString& _sName )
override
69 return m_aNameMap.find(_sName) != m_aNameMap.end();
72 virtual bool empty()
override
74 return m_aNameMap.empty();
79 std::vector< ObjectIter >(m_aElements).swap(m_aElements);
80 ObjectMap(m_aNameMap).swap(m_aNameMap);
83 virtual void swap()
override
85 std::vector< ObjectIter >().swap(m_aElements);
87 OSL_ENSURE( m_aNameMap.empty(),
"swap: what did disposeElements do?" );
88 ObjectMap( m_aNameMap ).swap( m_aNameMap );
96 virtual void clear()
override
102 virtual void insert(
const OUString& _sName,
const ObjectType& _xObject)
override
104 m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sName,_xObject)));
107 virtual void reFill(const ::std::vector< OUString> &_rVector)
override
109 OSL_ENSURE(m_aNameMap.empty(),
"OCollection::reFill: collection isn't empty");
112 for (
auto const& elem : _rVector)
116 virtual bool rename(
const OUString& _sOldName,
const OUString& _sNewName)
override
119 ObjectIter aIter = m_aNameMap.find(_sOldName);
120 if ( aIter != m_aNameMap.end() )
122 typename std::vector< ObjectIter >::iterator aFind = std::find(
m_aElements.begin(),
m_aElements.end(),aIter);
125 (*aFind) = m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sNewName,(*aFind)->second));
126 m_aNameMap.erase(aIter);
134 virtual sal_Int32
size()
override
136 return static_cast<sal_Int32
>(m_aNameMap.size());
141 Sequence< OUString > aNameList(
m_aElements.size());
143 OUString* pStringArray = aNameList.getArray();
144 for(
const auto& rIter : m_aElements)
146 *pStringArray = rIter->first;
153 virtual OUString
getName(sal_Int32 _nIndex)
override
160 OSL_ENSURE(_nIndex >= 0 && _nIndex <
static_cast<sal_Int32
>(
m_aElements.size()),
"Illegal argument!");
161 Reference<XComponent> xComp(m_aElements[_nIndex]->second.get(),UNO_QUERY);
162 ::comphelper::disposeComponent(xComp);
167 m_aNameMap.erase(sName);
172 for (
auto &
name : m_aNameMap)
174 Reference<XComponent> xComp(
name.second.get(),UNO_QUERY);
177 ::comphelper::disposeComponent(xComp);
187 ObjectIter aIter = m_aNameMap.find(
columnName);
188 OSL_ENSURE(aIter != m_aNameMap.end(),
"findColumn:: Illegal name!");
194 OSL_ENSURE(_nIndex >= 0 && _nIndex <
static_cast<sal_Int32
>(
m_aElements.size()),
"Illegal argument!");
205 OSL_ENSURE(_nIndex >= 0 && _nIndex <
static_cast<sal_Int32
>(
m_aElements.size()),
"Illegal argument!");
211 return m_aNameMap.key_comp().isCaseSensitive();
217IObjectCollection::~IObjectCollection() {}
223 , ::
osl::Mutex& _rMutex
224 , const ::
std::vector< OUString> &_rVector
225 ,
bool _bUseIndexOnly
227 :m_aContainerListeners(_rMutex)
228 ,m_aRefreshListeners(_rMutex)
231 ,m_bUseIndexOnly(_bUseIndexOnly)
235 m_pElements.reset(
new OHardRefMap< ObjectType >(_bCase));
239 m_pElements.reset(
new OHardRefMap< WeakReference< XPropertySet> >(_bCase));
241 m_pElements->
reFill(_rVector);
265 std::vector<Type> aOwnTypes;
266 aOwnTypes.reserve(
aTypes.getLength());
268 for(;pBegin != pEnd; ++pBegin)
270 if ( *pBegin != aType )
271 aOwnTypes.push_back(*pBegin);
273 return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size());
303 throw IndexOutOfBoundsException(OUString::number(
Index),
static_cast<XTypeProvider*
>(
this));
319 throw NoSuchElementException( sError,
static_cast< XTypeProvider*
>(
this ) );
338 EventObject aEvt(
static_cast<XTypeProvider*
>(
this));
357 OSL_ENSURE(_xObject.is(),
"OCollection::getNameForObject: Object is NULL!");
366 ::osl::ClearableMutexGuard aGuard(
m_rMutex);
371 throw ElementExistException(
sName,
static_cast<XTypeProvider*
>(
this));
374 if ( !xNewlyCreated.is() )
375 throw RuntimeException();
379 pDescriptor->
setNew(
false );
397 throw NoSuchElementException(elementName,
static_cast<XTypeProvider*
>(
this));
406 throw IndexOutOfBoundsException(OUString::number(
index),
static_cast<XTypeProvider*
>(
this));
413 OUString elementName =
m_pElements->getName(_nIndex);
426 ContainerEvent
aEvent(
static_cast<XContainer*
>(
this),
Any(_sName),
Any(),
Any());
506 OSL_ENSURE(!
m_pElements->exists(_sElementName),
"Element already exists");
513 OSL_ENSURE(
m_pElements->exists(_sOldName),
"Element doesn't exist");
514 OSL_ENSURE(!
m_pElements->exists(_sNewName),
"Element already exists");
515 OSL_ENSURE(!_sNewName.isEmpty(),
"New name must not be empty!");
516 OSL_ENSURE(!_sOldName.isEmpty(),
"Old name must not be empty!");
524 aListenerLoop.
next()->elementReplaced(
aEvent);
537 catch(
const SQLException& e)
547 throw WrappedTargetException(e.Message,
static_cast<XTypeProvider*
>(
this),anyEx);
561 OSL_FAIL(
"createDescriptor() needs to be overridden when used!");
562 throw SQLException();
568 ::comphelper::copyProperties( _descriptor, xNewDescriptor );
569 return xNewDescriptor;
TStyleElements m_aElements
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
bool hasMoreElements() const
css::uno::Reference< ListenerT > const & next()
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceStringWithSubstitution(TranslateId pResId, const char *_pAsciiPatternToReplace, const OUString &_rStringToSubstitute) const
loads a string from the shared resource file, and replaces a given ASCII pattern with a given string
virtual bool rename(const OUString &_sOldName, const OUString &_sNewName)=0
virtual void disposeElements()=0
virtual void setObject(sal_Int32 _nIndex, const ObjectType &_xObject)=0
virtual ObjectType getObject(sal_Int32 _nIndex)=0
virtual sal_Int32 size()=0
virtual OUString getName(sal_Int32 _nIndex)=0
virtual bool isCaseSensitive() const =0
virtual bool exists(const OUString &_sName)=0
virtual void insert(const OUString &_sName, const ObjectType &_xObject)=0
virtual void disposeAndErase(sal_Int32 _nIndex)=0
virtual sal_Int32 findColumn(const OUString &columnName)=0
virtual css::uno::Sequence< OUString > getElementNames()=0
virtual void reFill(const ::std::vector< OUString > &_rVector)=0
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor()
void insertElement(const OUString &_sElementName, const ObjectType &_xElement)
insert a new element into the collection
virtual void SAL_CALL dropByName(const OUString &elementName) override
virtual void SAL_CALL refresh() override
virtual void impl_refresh()=0
virtual ObjectType createObject(const OUString &_rName)=0
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName)
virtual OUString getNameForObject(const ObjectType &_xObject)
returns the name for the object.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
void notifyElementRemoved(const OUString &_sName)
virtual void SAL_CALL release() noexcept override
void dropImpl(sal_Int32 _nIndex, bool _bReallyDrop=true)
ObjectType getObject(sal_Int32 _nIndex)
return the object, if not existent it creates it.
void clear_NoDispose()
clear the name map
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
void reFill(const ::std::vector< OUString > &_rVector)
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
virtual ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor)
appends an object described by a descriptor, under a given name
::cppu::OWeakObject & m_rParent
virtual sal_Int32 SAL_CALL getCount() override
::std::unique_ptr< IObjectCollection > m_pElements
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
void renameObject(const OUString &_sOldName, const OUString &_sNewName)
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
ObjectType cloneDescriptor(const ObjectType &_descriptor)
clones the given descriptor
::comphelper::OInterfaceContainerHelper3< css::util::XRefreshListener > m_aRefreshListeners
virtual sal_Bool SAL_CALL hasElements() override
::comphelper::OInterfaceContainerHelper3< css::container::XContainerListener > m_aContainerListeners
virtual void SAL_CALL appendByDescriptor(const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
css::uno::Type const & get()
css::uno::Reference< css::beans::XPropertySet > ObjectType
Any SAL_CALL getCaughtException()