merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / fsstor / oinputstreamcontainer.cxx
blob868ba5758516d6c7a57179b17012cd403dc77aaa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oinputstreamcontainer.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "oinputstreamcontainer.hxx"
35 #include <cppuhelper/typeprovider.hxx>
37 using namespace ::com::sun::star;
39 //-----------------------------------------------
40 OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream )
41 : m_xInputStream( xStream )
42 , m_xSeekable( xStream, uno::UNO_QUERY )
43 , m_bSeekable( sal_False )
44 , m_bDisposed( sal_False )
45 , m_pListenersContainer( NULL )
47 m_bSeekable = m_xSeekable.is();
50 //-----------------------------------------------
51 OFSInputStreamContainer::~OFSInputStreamContainer()
53 if ( m_pListenersContainer )
55 delete m_pListenersContainer;
56 m_pListenersContainer = NULL;
60 //-----------------------------------------------
61 uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
62 throw ( uno::RuntimeException )
64 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
66 if ( pTypeCollection == NULL )
68 ::osl::MutexGuard aGuard( m_aMutex ) ;
70 if ( pTypeCollection == NULL )
72 if ( m_bSeekable )
74 static ::cppu::OTypeCollection aTypeCollection(
75 ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
76 ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ),
77 ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) );
79 pTypeCollection = &aTypeCollection ;
81 else
83 static ::cppu::OTypeCollection aTypeCollection(
84 ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
85 ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) );
87 pTypeCollection = &aTypeCollection ;
92 return pTypeCollection->getTypes() ;
96 //-----------------------------------------------
97 uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
98 throw( uno::RuntimeException )
100 // Attention:
101 // Don't use mutex or guard in this method!!! Is a method of XInterface.
103 uno::Any aReturn;
104 if ( m_bSeekable )
105 aReturn = uno::Any( ::cppu::queryInterface( rType,
106 static_cast< io::XStream* >( this ),
107 static_cast< io::XInputStream* >( this ),
108 static_cast< io::XSeekable* >( this ) ) );
109 else
110 aReturn = uno::Any( ::cppu::queryInterface( rType,
111 static_cast< io::XStream* >( this ),
112 static_cast< io::XInputStream* >( this ) ) );
114 if ( aReturn.hasValue() == sal_True )
115 return aReturn ;
117 return ::cppu::OWeakObject::queryInterface( rType ) ;
120 //-----------------------------------------------
121 void SAL_CALL OFSInputStreamContainer::acquire()
122 throw()
124 ::cppu::OWeakObject::acquire();
127 //-----------------------------------------------
128 void SAL_CALL OFSInputStreamContainer::release()
129 throw()
131 ::cppu::OWeakObject::release();
134 //-----------------------------------------------
135 sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
136 throw ( io::NotConnectedException,
137 io::BufferSizeExceededException,
138 io::IOException,
139 uno::RuntimeException )
141 ::osl::MutexGuard aGuard( m_aMutex );
143 if ( m_bDisposed )
144 throw lang::DisposedException();
146 if ( !m_xInputStream.is() )
147 throw uno::RuntimeException();
149 return m_xInputStream->readBytes( aData, nBytesToRead );
152 //-----------------------------------------------
153 sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
154 throw ( io::NotConnectedException,
155 io::BufferSizeExceededException,
156 io::IOException,
157 uno::RuntimeException )
159 ::osl::MutexGuard aGuard( m_aMutex );
161 if ( m_bDisposed )
162 throw lang::DisposedException();
164 if ( !m_xInputStream.is() )
165 throw uno::RuntimeException();
167 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
170 //-----------------------------------------------
171 void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
172 throw ( io::NotConnectedException,
173 io::BufferSizeExceededException,
174 io::IOException,
175 uno::RuntimeException )
177 ::osl::MutexGuard aGuard( m_aMutex );
179 if ( m_bDisposed )
180 throw lang::DisposedException();
182 if ( !m_xInputStream.is() )
183 throw uno::RuntimeException();
185 m_xInputStream->skipBytes( nBytesToSkip );
188 //-----------------------------------------------
189 sal_Int32 SAL_CALL OFSInputStreamContainer::available( )
190 throw ( io::NotConnectedException,
191 io::IOException,
192 uno::RuntimeException )
194 ::osl::MutexGuard aGuard( m_aMutex );
196 if ( m_bDisposed )
197 throw lang::DisposedException();
199 if ( !m_xInputStream.is() )
200 throw uno::RuntimeException();
202 return m_xInputStream->available();
205 //-----------------------------------------------
206 void SAL_CALL OFSInputStreamContainer::closeInput( )
207 throw ( io::NotConnectedException,
208 io::IOException,
209 uno::RuntimeException )
211 ::osl::MutexGuard aGuard( m_aMutex );
213 if ( m_bDisposed )
214 throw lang::DisposedException();
216 if ( !m_xInputStream.is() )
217 throw uno::RuntimeException();
219 dispose();
222 //-----------------------------------------------
223 uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
224 throw ( uno::RuntimeException )
226 ::osl::MutexGuard aGuard( m_aMutex );
228 if ( m_bDisposed )
229 throw lang::DisposedException();
231 if ( !m_xInputStream.is() )
232 return uno::Reference< io::XInputStream >();
234 return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
237 //-----------------------------------------------
238 uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
239 throw ( uno::RuntimeException )
241 ::osl::MutexGuard aGuard( m_aMutex );
243 if ( m_bDisposed )
244 throw lang::DisposedException();
246 return uno::Reference< io::XOutputStream >();
249 //-----------------------------------------------
250 void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
251 throw ( lang::IllegalArgumentException,
252 io::IOException,
253 uno::RuntimeException )
255 ::osl::MutexGuard aGuard( m_aMutex );
257 if ( m_bDisposed )
258 throw lang::DisposedException();
260 if ( !m_xSeekable.is() )
261 throw uno::RuntimeException();
263 m_xSeekable->seek( location );
266 //-----------------------------------------------
267 sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
268 throw ( io::IOException,
269 uno::RuntimeException)
271 ::osl::MutexGuard aGuard( m_aMutex );
273 if ( m_bDisposed )
274 throw lang::DisposedException();
276 if ( !m_xSeekable.is() )
277 throw uno::RuntimeException();
279 return m_xSeekable->getPosition();
282 //-----------------------------------------------
283 sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
284 throw ( io::IOException,
285 uno::RuntimeException )
287 ::osl::MutexGuard aGuard( m_aMutex );
289 if ( m_bDisposed )
290 throw lang::DisposedException();
292 if ( !m_xSeekable.is() )
293 throw uno::RuntimeException();
295 return m_xSeekable->getLength();
298 //-----------------------------------------------
299 void SAL_CALL OFSInputStreamContainer::dispose( )
300 throw ( uno::RuntimeException )
302 ::osl::MutexGuard aGuard( m_aMutex );
304 if ( m_bDisposed )
305 throw lang::DisposedException();
307 if ( !m_xInputStream.is() )
308 throw uno::RuntimeException();
310 m_xInputStream->closeInput();
312 if ( m_pListenersContainer )
314 lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
315 m_pListenersContainer->disposeAndClear( aSource );
318 m_bDisposed = sal_True;
321 //-----------------------------------------------
322 void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
323 throw ( uno::RuntimeException )
325 ::osl::MutexGuard aGuard( m_aMutex );
327 if ( m_bDisposed )
328 throw lang::DisposedException();
330 if ( !m_pListenersContainer )
331 m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
333 m_pListenersContainer->addInterface( xListener );
336 //-----------------------------------------------
337 void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
338 throw ( uno::RuntimeException )
340 ::osl::MutexGuard aGuard( m_aMutex );
342 if ( m_bDisposed )
343 throw lang::DisposedException();
345 if ( m_pListenersContainer )
346 m_pListenersContainer->removeInterface( xListener );