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 _UCBHELPER_RESULTSETHELPER_HXX
25 #define _UCBHELPER_RESULTSETHELPER_HXX
26 
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/lang/XTypeProvider.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
32 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
33 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
34 #include <cppuhelper/weak.hxx>
35 #include <ucbhelper/macros.hxx>
36 #include <ucbhelper/contenthelper.hxx>
37 #include "ucbhelper/ucbhelperdllapi.h"
38 
39 namespace cppu {
40 	class OInterfaceContainerHelper;
41 }
42 
43 namespace ucbhelper {
44 
45 //=========================================================================
46 
47 #define DYNAMICRESULTSET_SERVICE_NAME "com.sun.star.ucb.DynamicResultSet"
48 
49 //=========================================================================
50 
51 /**
52   * This is an abstract base class for implementations of the service
53   * com.sun.star.ucb.DynamicResultSet, which is the result of the command
54   * "open" executed at a UCB folder content.
55   *
56   * Features of the base class implementation:
57   * - standard interfaces ( XInterface, XTypeProvider, XServiceInfo )
58   *	- all required interfaces for service com::sun::star::ucb::DynamicResultSet
59   */
60 class UCBHELPER_DLLPUBLIC ResultSetImplHelper :
61 				public cppu::OWeakObject,
62 				public com::sun::star::lang::XTypeProvider,
63 				public com::sun::star::lang::XServiceInfo,
64 				public com::sun::star::ucb::XDynamicResultSet
65 {
66 	cppu::OInterfaceContainerHelper* m_pDisposeEventListeners;
67 	sal_Bool						 m_bStatic;
68 	sal_Bool						 m_bInitDone;
69 
70 protected:
71 	osl::Mutex						 					 m_aMutex;
72 	com::sun::star::ucb::OpenCommandArgument2			 m_aCommand;
73 	com::sun::star::uno::Reference<
74 		com::sun::star::lang::XMultiServiceFactory >	 m_xSMgr;
75 	// Resultset #1
76 	com::sun::star::uno::Reference<
77 		com::sun::star::sdbc::XResultSet > 				 m_xResultSet1;
78 	// Resultset #2
79 	com::sun::star::uno::Reference<
80 		com::sun::star::sdbc::XResultSet > 				 m_xResultSet2;
81 	// Resultset changes listener.
82 	com::sun::star::uno::Reference<
83 		com::sun::star::ucb::XDynamicResultSetListener > m_xListener;
84 
85 private:
86 	UCBHELPER_DLLPRIVATE void init( sal_Bool bStatic );
87 
88 	/**
89 	  * Your implementation of this method has to fill the protected member
90 	  * m_xResultSet1. This resultset must implement a complete static
91 	  * resultset ( service com.sun.star.ucb.ContentResultSet ). This method
92 	  * will be called at most once in the life of your implementation object.
93 	  * After this method was called, the type of this resultset will be
94 	  * "static". There is no way to change the type afterwards.
95 	  * If this method gets called the client wants to use your resultset
96 	  * exclusively statically. You may deploy this factum to optimize your
97 	  * implementation (i.e. "switch off" all changes detection code in
98 	  * your implementation).
99 	  * Note that you may use the class ucb::ResultSet to implement the
100 	  * static resultset, that is required here.
101 	  */
102 	UCBHELPER_DLLPRIVATE virtual void initStatic() = 0;
103 
104 	/**
105 	  * Your implementation of this method has to fill the protected members
106 	  * m_xResultSet1 and m_xResultSet2 of this base class. Each of these
107 	  * resultsets must implement a complete static resultset
108 	  * ( service com.sun.star.ucb.ContentResultSet ). This method will be
109 	  * called at most once in the life of your implementation object.
110 	  * After this method was called, the type of this resultset will be
111 	  * "dynamic". There is no way to change the type afterwards.
112 	  * If this method gets called the client wants to use your resultset
113 	  * exclusively dynamically. This means, it is interested in getting
114 	  * notifications on changes of data of the resultset contents. ( These
115 	  * changes are to propagate by your implementation throw the member
116 	  * m_xListener of this base class ).
117 	  * If your implementation cannot detect changes of relevant data, you
118 	  * may fill m_xResultSet1 and m_xResultSet2 with the same static resultset
119 	  * implementation object. This normally will be the same instance you put
120 	  * into m_xResultSet1 when initStatic() is called.
121 	  */
122 	UCBHELPER_DLLPRIVATE virtual void initDynamic() = 0;
123 
124 public:
125 	/**
126 	  * Construtor.
127 	  *
128 	  * @param rxSMgr is a Service Manager.
129 	  */
130 	ResultSetImplHelper(
131 			const com::sun::star::uno::Reference<
132 				com::sun::star::lang::XMultiServiceFactory >& rxSMgr );
133 
134 	/**
135 	  * Construtor.
136 	  *
137 	  * @param rxSMgr is a Service Manager.
138 	  * @param rCommand is the paramter for the open command that produces
139 	  *        this resultset.
140 	  */
141 	ResultSetImplHelper(
142 			const com::sun::star::uno::Reference<
143 				com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
144 			const com::sun::star::ucb::OpenCommandArgument2& rCommand );
145 
146 	/**
147 	  * Destructor.
148 	  */
149 	virtual ~ResultSetImplHelper();
150 
151 	// XInterface
152 	XINTERFACE_DECL()
153 
154 	// XTypeProvider
155 	XTYPEPROVIDER_DECL()
156 
157     // XServiceInfo
158 	XSERVICEINFO_NOFACTORY_DECL()
159 
160 	// XComponent ( base class of XDynamicResultSet )
161     virtual void SAL_CALL
162 	dispose()
163 		throw( com::sun::star::uno::RuntimeException );
164     virtual void SAL_CALL
165 	addEventListener( const com::sun::star::uno::Reference<
166 							com::sun::star::lang::XEventListener >& Listener )
167 		throw( com::sun::star::uno::RuntimeException );
168     virtual void SAL_CALL
169 	removeEventListener( const com::sun::star::uno::Reference<
170 							com::sun::star::lang::XEventListener >& Listener )
171 		throw( com::sun::star::uno::RuntimeException );
172 
173 	// XDynamicResultSet
174     virtual com::sun::star::uno::Reference<
175 				com::sun::star::sdbc::XResultSet > SAL_CALL
176 	getStaticResultSet()
177 		throw( com::sun::star::ucb::ListenerAlreadySetException,
178 		com::sun::star::uno::RuntimeException );
179     virtual void SAL_CALL
180 	setListener( const com::sun::star::uno::Reference<
181 					com::sun::star::ucb::XDynamicResultSetListener >& Listener )
182 		throw( com::sun::star::ucb::ListenerAlreadySetException,
183 			   com::sun::star::uno::RuntimeException );
184 	virtual void SAL_CALL
185 	connectToCache( const com::sun::star::uno::Reference<
186 						com::sun::star::ucb::XDynamicResultSet > & xCache )
187 		throw( com::sun::star::ucb::ListenerAlreadySetException,
188 			   com::sun::star::ucb::AlreadyInitializedException,
189 			   com::sun::star::ucb::ServiceNotFoundException,
190 			   com::sun::star::uno::RuntimeException );
191 
192 	/**
193 	  * The implemetation of this method always returns 0. Override this
194 	  * method, if necassary.
195 	  */
196     virtual sal_Int16 SAL_CALL
197 	getCapabilities()
198 		throw( com::sun::star::uno::RuntimeException );
199 
200 	//////////////////////////////////////////////////////////////////////
201 	// Non-interface methods.
202 	//////////////////////////////////////////////////////////////////////
203 
204 	/**
205 	  * This method returns, whether the resultset is static or dynamic.
206 	  * If neither getStatic() nor getDynamic() was called, the type
207 	  * of the resultset is "dynamic".
208 	  *
209 	  * @return true, if the resultset type is "static". False, otherwise.
210 	  */
isStatic() const211 	sal_Bool isStatic() const { return m_bStatic; }
212 };
213 
214 }
215 
216 #endif /* !_UCBHELPER_RESULTSETHELPER_HXX */
217