1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DBA_CORE_BOOKMARKCONTAINER_HXX_
29 #define _DBA_CORE_BOOKMARKCONTAINER_HXX_
30 
31 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
32 #include <cppuhelper/interfacecontainer.hxx>
33 #endif
34 #ifndef _CPPUHELPER_IMPLBASE6_HXX_
35 #include <cppuhelper/implbase6.hxx>
36 #endif
37 #ifndef _COMPHELPER_STLTYPES_HXX_
38 #include <comphelper/stl_types.hxx>
39 #endif
40 #ifndef _OSL_MUTEX_HXX_
41 #include <osl/mutex.hxx>
42 #endif
43 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
44 #include <com/sun/star/container/XChild.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
47 #include <com/sun/star/container/XNameContainer.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
50 #include <com/sun/star/container/XContainer.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
53 #include <com/sun/star/container/XEnumerationAccess.hpp>
54 #endif
55 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
56 #include <com/sun/star/container/XIndexAccess.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
59 #include <com/sun/star/lang/XServiceInfo.hpp>
60 #endif
61 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
62 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
65 #include <com/sun/star/beans/XPropertySet.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
68 #include <com/sun/star/lang/DisposedException.hpp>
69 #endif
70 
71 //........................................................................
72 namespace dbaccess
73 {
74 //........................................................................
75 
76 //==========================================================================
77 //= OBookmarkContainer -	base class of collections of database definition
78 //=							documents
79 //==========================================================================
80 typedef ::cppu::WeakImplHelper6	<
81 									::com::sun::star::container::XIndexAccess
82 								,	::com::sun::star::container::XNameContainer
83 								,	::com::sun::star::container::XEnumerationAccess
84 								,	::com::sun::star::container::XContainer
85 								,	::com::sun::star::lang::XServiceInfo
86 								,	::com::sun::star::container::XChild
87 								>	OBookmarkContainer_Base;
88 
89 class OBookmarkContainer
90 			:public OBookmarkContainer_Base
91 {
92 protected:
93 	DECLARE_STL_USTRINGACCESS_MAP(::rtl::OUString, MapString2String);
94 	DECLARE_STL_VECTOR(MapString2StringIterator, MapIteratorVector);
95 
96 	MapString2String		m_aBookmarks;			// the bookmarks itself
97 	MapIteratorVector		m_aBookmarksIndexed;	// for index access to the
98 
99 protected:
100 	::cppu::OWeakObject&	m_rParent;		// for the ref counting
101 	::cppu::OInterfaceContainerHelper
102 							m_aContainerListeners;
103 	::osl::Mutex&			m_rMutex;
104 
105 
106 public:
107 	/** constructs the container.<BR>
108 		after the construction of the object the creator has to call <code>initialize</code>.
109 		@param		_rParent				the parent object which is used for ref counting
110 		@param		_rMutex					the parent's mutex object for access safety
111 	*/
112 	OBookmarkContainer(
113 		::cppu::OWeakObject& _rParent,
114 		::osl::Mutex& _rMutex
115 		);
116 
117 	/** looks like the dtor ...
118 	*/
119 	virtual ~OBookmarkContainer();
120 
121 // ::com::sun::star::uno::XInterface
122     virtual void SAL_CALL acquire(  ) throw();
123     virtual void SAL_CALL release(  ) throw();
124 
125 // ::com::sun::star::lang::XServiceInfo
126 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
127 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
128 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
129 
130 // ::com::sun::star::container::XElementAccess
131 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
132 	virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
133 
134 // ::com::sun::star::container::XEnumerationAccess
135 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
136 
137 // ::com::sun::star::container::XIndexAccess
138 	virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException);
139 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 _nIndex ) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
140 
141 // ::com::sun::star::container::XNameContainer
142     virtual void SAL_CALL insertByName( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
143     virtual void SAL_CALL removeByName( const ::rtl::OUString& _rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
144 
145 // ::com::sun::star::container::XNameReplace
146     virtual void SAL_CALL replaceByName( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
147 
148 // ::com::sun::star::container::XNameAccess
149 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
150 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException);
151 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
152 
153 // ::com::sun::star::container::XContainer
154     virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
155     virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
156 
157 // ::com::sun::star::container::XChild
158     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
159     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
160 
161 // helper
162 	/** tell the container to free all resources. After that it's in a state like after the construction, i.e.
163 		you may call <code>initialize</code> again (maybe with another configuration node).
164 	*/
165 	virtual void	dispose();
166 
167 
168 protected:
169 	/**	checks whether the object is basically alive, i.e. it has been fully initialized (@see initialize) and
170 		not disposed (@see dispose)
171 		@param		_bIntendWriteAccess		determines whether or not the caller intends to modify the configuration.
172 											if sal_True and the configuration is readonly, a runtime exception with
173 											a description string is thrown.
174 	*/
175 	void		checkValid(sal_Bool _bIntendWriteAccess) const throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::DisposedException);
176 
177 	/** quickly checks if there already is an element with a given name. No access to the configuration occures, i.e.
178 		if there is such an object which is not already loaded, it won't be loaded now.
179 		@param		_rName		the object name to check
180 		@return					sal_True if there already exists such an object
181 	*/
182 	inline	sal_Bool	checkExistence(const ::rtl::OUString& _rName);
183 
184 	void	implAppend(
185 		const ::rtl::OUString& _rName,
186 		const ::rtl::OUString& _rDocumentLocation
187 		);
188 
189 	void implRemove(const ::rtl::OUString& _rName);
190 
191 	void implReplace(
192 		const ::rtl::OUString& _rName,
193 		const ::rtl::OUString& _rNewLink);
194 
195 };
196 
197 //--------------------------------------------------------------------------
198 inline	sal_Bool OBookmarkContainer::checkExistence(const ::rtl::OUString& _rName)
199 {
200 	return m_aBookmarks.find(_rName) != m_aBookmarks.end();
201 }
202 
203 //........................................................................
204 }	// namespace dbaccess
205 //........................................................................
206 
207 #endif // _DBA_CORE_BOOKMARKCONTAINER_HXX_
208 
209