1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DBA_CORE_BOOKMARKCONTAINER_HXX_
25 #define _DBA_CORE_BOOKMARKCONTAINER_HXX_
26 
27 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
28 #include <cppuhelper/interfacecontainer.hxx>
29 #endif
30 #ifndef _CPPUHELPER_IMPLBASE6_HXX_
31 #include <cppuhelper/implbase6.hxx>
32 #endif
33 #ifndef _COMPHELPER_STLTYPES_HXX_
34 #include <comphelper/stl_types.hxx>
35 #endif
36 #ifndef _OSL_MUTEX_HXX_
37 #include <osl/mutex.hxx>
38 #endif
39 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
40 #include <com/sun/star/container/XChild.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
46 #include <com/sun/star/container/XContainer.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
49 #include <com/sun/star/container/XEnumerationAccess.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
52 #include <com/sun/star/container/XIndexAccess.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
55 #include <com/sun/star/lang/XServiceInfo.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
58 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
61 #include <com/sun/star/beans/XPropertySet.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
64 #include <com/sun/star/lang/DisposedException.hpp>
65 #endif
66 
67 //........................................................................
68 namespace dbaccess
69 {
70 //........................................................................
71 
72 //==========================================================================
73 //= OBookmarkContainer -	base class of collections of database definition
74 //=							documents
75 //==========================================================================
76 typedef ::cppu::WeakImplHelper6	<
77 									::com::sun::star::container::XIndexAccess
78 								,	::com::sun::star::container::XNameContainer
79 								,	::com::sun::star::container::XEnumerationAccess
80 								,	::com::sun::star::container::XContainer
81 								,	::com::sun::star::lang::XServiceInfo
82 								,	::com::sun::star::container::XChild
83 								>	OBookmarkContainer_Base;
84 
85 class OBookmarkContainer
86 			:public OBookmarkContainer_Base
87 {
88 protected:
89 	DECLARE_STL_USTRINGACCESS_MAP(::rtl::OUString, MapString2String);
90 	DECLARE_STL_VECTOR(MapString2StringIterator, MapIteratorVector);
91 
92 	MapString2String		m_aBookmarks;			// the bookmarks itself
93 	MapIteratorVector		m_aBookmarksIndexed;	// for index access to the
94 
95 protected:
96 	::cppu::OWeakObject&	m_rParent;		// for the ref counting
97 	::cppu::OInterfaceContainerHelper
98 							m_aContainerListeners;
99 	::osl::Mutex&			m_rMutex;
100 
101 
102 public:
103 	/** constructs the container.<BR>
104 		after the construction of the object the creator has to call <code>initialize</code>.
105 		@param		_rParent				the parent object which is used for ref counting
106 		@param		_rMutex					the parent's mutex object for access safety
107 	*/
108 	OBookmarkContainer(
109 		::cppu::OWeakObject& _rParent,
110 		::osl::Mutex& _rMutex
111 		);
112 
113 	/** looks like the dtor ...
114 	*/
115 	virtual ~OBookmarkContainer();
116 
117 // ::com::sun::star::uno::XInterface
118     virtual void SAL_CALL acquire(  ) throw();
119     virtual void SAL_CALL release(  ) throw();
120 
121 // ::com::sun::star::lang::XServiceInfo
122 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
123 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
124 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
125 
126 // ::com::sun::star::container::XElementAccess
127 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
128 	virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
129 
130 // ::com::sun::star::container::XEnumerationAccess
131 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
132 
133 // ::com::sun::star::container::XIndexAccess
134 	virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException);
135 	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);
136 
137 // ::com::sun::star::container::XNameContainer
138     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);
139     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);
140 
141 // ::com::sun::star::container::XNameReplace
142     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);
143 
144 // ::com::sun::star::container::XNameAccess
145 	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);
146 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException);
147 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
148 
149 // ::com::sun::star::container::XContainer
150     virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
151     virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
152 
153 // ::com::sun::star::container::XChild
154     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
155     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);
156 
157 // helper
158 	/** tell the container to free all resources. After that it's in a state like after the construction, i.e.
159 		you may call <code>initialize</code> again (maybe with another configuration node).
160 	*/
161 	virtual void	dispose();
162 
163 
164 protected:
165 	/**	checks whether the object is basically alive, i.e. it has been fully initialized (@see initialize) and
166 		not disposed (@see dispose)
167 		@param		_bIntendWriteAccess		determines whether or not the caller intends to modify the configuration.
168 											if sal_True and the configuration is readonly, a runtime exception with
169 											a description string is thrown.
170 	*/
171 	void		checkValid(sal_Bool _bIntendWriteAccess) const throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::DisposedException);
172 
173 	/** quickly checks if there already is an element with a given name. No access to the configuration occures, i.e.
174 		if there is such an object which is not already loaded, it won't be loaded now.
175 		@param		_rName		the object name to check
176 		@return					sal_True if there already exists such an object
177 	*/
178 	inline	sal_Bool	checkExistence(const ::rtl::OUString& _rName);
179 
180 	void	implAppend(
181 		const ::rtl::OUString& _rName,
182 		const ::rtl::OUString& _rDocumentLocation
183 		);
184 
185 	void implRemove(const ::rtl::OUString& _rName);
186 
187 	void implReplace(
188 		const ::rtl::OUString& _rName,
189 		const ::rtl::OUString& _rNewLink);
190 
191 };
192 
193 //--------------------------------------------------------------------------
194 inline	sal_Bool OBookmarkContainer::checkExistence(const ::rtl::OUString& _rName)
195 {
196 	return m_aBookmarks.find(_rName) != m_aBookmarks.end();
197 }
198 
199 //........................................................................
200 }	// namespace dbaccess
201 //........................................................................
202 
203 #endif // _DBA_CORE_BOOKMARKCONTAINER_HXX_
204 
205