summaryrefslogtreecommitdiff
path: root/svtools/source
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2006-10-13 10:27:33 +0000
committerOliver Bolte <obo@openoffice.org>2006-10-13 10:27:33 +0000
commitd3a87b60d56d31c2b58df9b4d7be076e3d063799 (patch)
tree10f06ecfadb854de242fefa40aae2fc03306180d /svtools/source
parent7ce0bfa8bc7d5d75a7e3bfae11e709bd9031ee94 (diff)
INTEGRATION: CWS opofxmlstorage (1.1.2); FILE ADDED
2006/06/30 12:43:37 mav 1.1.2.2: resync to m173: fix warnings 2006/05/15 14:31:59 mav 1.1.2.1: #i65306# hierarchical access
Diffstat (limited to 'svtools/source')
-rw-r--r--svtools/source/fsstor/ostreamcontainer.cxx572
1 files changed, 572 insertions, 0 deletions
diff --git a/svtools/source/fsstor/ostreamcontainer.cxx b/svtools/source/fsstor/ostreamcontainer.cxx
new file mode 100644
index 000000000000..c5970d1e3e2e
--- /dev/null
+++ b/svtools/source/fsstor/ostreamcontainer.cxx
@@ -0,0 +1,572 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: ostreamcontainer.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: obo $ $Date: 2006-10-13 11:27:33 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "ostreamcontainer.hxx"
+
+
+using namespace ::com::sun::star;
+
+//-----------------------------------------------
+OFSStreamContainer::OFSStreamContainer( const uno::Reference < io::XStream >& xStream )
+: m_bDisposed( sal_False )
+, m_bInputClosed( sal_False )
+, m_bOutputClosed( sal_False )
+, m_pListenersContainer( NULL )
+, m_pTypeCollection( NULL )
+{
+ try
+ {
+ m_xStream = xStream;
+ if ( !m_xStream.is() )
+ throw uno::RuntimeException();
+
+ m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY );
+ m_xInputStream = xStream->getInputStream();
+ m_xOutputStream = xStream->getOutputStream();
+ m_xTruncate = uno::Reference< io::XTruncate >( m_xOutputStream, uno::UNO_QUERY );
+ m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >( m_xOutputStream, uno::UNO_QUERY );
+ }
+ catch( uno::Exception& )
+ {
+ m_xStream = uno::Reference< io::XStream >();
+ m_xSeekable = uno::Reference< io::XSeekable >();
+ m_xInputStream = uno::Reference< io::XInputStream >();
+ m_xOutputStream = uno::Reference< io::XOutputStream >();
+ m_xTruncate = uno::Reference< io::XTruncate >();
+ m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >();
+ }
+}
+
+//-----------------------------------------------
+OFSStreamContainer::~OFSStreamContainer()
+{
+ if ( m_pListenersContainer )
+ {
+ delete m_pListenersContainer;
+ m_pListenersContainer = NULL;
+ }
+}
+
+// XInterface
+//-----------------------------------------------
+uno::Any SAL_CALL OFSStreamContainer::queryInterface( const uno::Type& rType )
+ throw( uno::RuntimeException )
+{
+ uno::Any aReturn;
+
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<lang::XTypeProvider*> ( this )
+ , static_cast<io::XStream*> ( this )
+ , static_cast<embed::XExtendedStorageStream*> ( this )
+ , static_cast<lang::XComponent*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+
+ if ( m_xSeekable.is() )
+ {
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<io::XSeekable*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+ }
+
+ if ( m_xInputStream.is() )
+ {
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<io::XInputStream*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+ }
+ if ( m_xOutputStream.is() )
+ {
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<io::XOutputStream*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+ }
+ if ( m_xTruncate.is() )
+ {
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<io::XTruncate*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+ }
+ if ( m_xAsyncOutputMonitor.is() )
+ {
+ aReturn <<= ::cppu::queryInterface
+ ( rType
+ , static_cast<io::XAsyncOutputMonitor*> ( this ) );
+
+ if ( aReturn.hasValue() == sal_True )
+ return aReturn ;
+ }
+
+ return OWeakObject::queryInterface( rType );
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::acquire()
+ throw()
+{
+ OWeakObject::acquire();
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::release()
+ throw()
+{
+ OWeakObject::release();
+}
+
+// XTypeProvider
+//-----------------------------------------------
+uno::Sequence< uno::Type > SAL_CALL OFSStreamContainer::getTypes()
+ throw( uno::RuntimeException )
+{
+ if ( m_pTypeCollection == NULL )
+ {
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_pTypeCollection == NULL )
+ {
+ ::cppu::OTypeCollection aTypeCollection
+ ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
+ , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) );
+
+ if ( m_xSeekable.is() )
+ aTypeCollection = ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ),
+ aTypeCollection.getTypes() );
+ if ( m_xInputStream.is() )
+ aTypeCollection = ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ),
+ aTypeCollection.getTypes() );
+
+ if ( m_xOutputStream.is() )
+ aTypeCollection = ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ),
+ aTypeCollection.getTypes() );
+ if ( m_xTruncate.is() )
+ aTypeCollection = ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ),
+ aTypeCollection.getTypes() );
+ if ( m_xAsyncOutputMonitor.is() )
+ aTypeCollection = ::cppu::OTypeCollection
+ ( ::getCppuType( ( const uno::Reference< io::XAsyncOutputMonitor >* )NULL ),
+ aTypeCollection.getTypes() );
+
+ m_pTypeCollection = new ::cppu::OTypeCollection( aTypeCollection );
+ }
+ }
+ return m_pTypeCollection->getTypes() ;
+}
+
+//-----------------------------------------------
+uno::Sequence< sal_Int8 > SAL_CALL OFSStreamContainer::getImplementationId()
+ throw( uno::RuntimeException )
+{
+ static ::cppu::OImplementationId* pID = NULL ;
+
+ if ( pID == NULL )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+
+ if ( pID == NULL )
+ {
+ static ::cppu::OImplementationId aID( sal_False ) ;
+ pID = &aID ;
+ }
+ }
+
+ return pID->getImplementationId() ;
+}
+
+// XStream
+//-----------------------------------------------
+uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() )
+ throw uno::RuntimeException();
+
+ if ( m_xInputStream.is() )
+ return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ) );
+
+ return uno::Reference< io::XInputStream >();
+}
+
+//-----------------------------------------------
+uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() )
+ throw uno::RuntimeException();
+
+ if ( m_xOutputStream.is() )
+ return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ) );
+
+ return uno::Reference< io::XOutputStream >();
+}
+
+// XComponent
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::dispose()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() )
+ throw uno::RuntimeException();
+
+ if ( m_xInputStream.is() && !m_bInputClosed )
+ {
+ m_xInputStream->closeInput();
+ m_bInputClosed = sal_True;
+ }
+
+ if ( m_xOutputStream.is() && !m_bOutputClosed )
+ {
+ m_xOutputStream->closeOutput();
+ m_bOutputClosed = sal_True;
+ }
+
+ if ( m_pListenersContainer )
+ {
+ lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
+ m_pListenersContainer->disposeAndClear( aSource );
+ }
+
+ m_bDisposed = sal_True;
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_pListenersContainer )
+ m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
+
+ m_pListenersContainer->addInterface( xListener );
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( m_pListenersContainer )
+ m_pListenersContainer->removeInterface( xListener );
+}
+
+
+// XSeekable
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::seek( sal_Int64 location )
+ throw ( lang::IllegalArgumentException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xSeekable.is() )
+ throw uno::RuntimeException();
+
+ m_xSeekable->seek( location );
+}
+
+//-----------------------------------------------
+sal_Int64 SAL_CALL OFSStreamContainer::getPosition()
+ throw ( io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xSeekable.is() )
+ throw uno::RuntimeException();
+
+ return m_xSeekable->getPosition();
+}
+
+//-----------------------------------------------
+sal_Int64 SAL_CALL OFSStreamContainer::getLength()
+ throw ( io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xSeekable.is() )
+ throw uno::RuntimeException();
+
+ return m_xSeekable->getLength();
+}
+
+
+// XInputStream
+//-----------------------------------------------
+sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xInputStream.is() )
+ throw uno::RuntimeException();
+
+ return m_xInputStream->readBytes( aData, nBytesToRead );
+}
+
+//-----------------------------------------------
+sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xInputStream.is() )
+ throw uno::RuntimeException();
+
+ return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xInputStream.is() )
+ throw uno::RuntimeException();
+
+ m_xInputStream->skipBytes( nBytesToSkip );
+}
+
+//-----------------------------------------------
+sal_Int32 SAL_CALL OFSStreamContainer::available()
+ throw( io::NotConnectedException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xInputStream.is() )
+ throw uno::RuntimeException();
+
+ return m_xInputStream->available();
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::closeInput()
+ throw( io::NotConnectedException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xInputStream.is() )
+ throw uno::RuntimeException();
+
+ if ( m_xInputStream.is() )
+ {
+ m_xInputStream->closeInput();
+ m_bInputClosed = sal_True;
+ }
+
+ if ( m_bOutputClosed )
+ dispose();
+}
+
+// XOutputStream
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& aData )
+ throw ( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xOutputStream.is() )
+ throw uno::RuntimeException();
+
+ return m_xOutputStream->writeBytes( aData );
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::flush()
+ throw ( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xOutputStream.is() )
+ throw uno::RuntimeException();
+
+ return m_xOutputStream->flush();
+}
+
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::closeOutput()
+ throw ( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xOutputStream.is() )
+ throw uno::RuntimeException();
+
+ if ( m_xOutputStream.is() )
+ {
+ m_xOutputStream->closeOutput();
+ m_bOutputClosed = sal_True;
+ }
+
+ if ( m_bInputClosed )
+ dispose();
+}
+
+
+// XTruncate
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::truncate()
+ throw ( io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xTruncate.is() )
+ throw uno::RuntimeException();
+
+ m_xTruncate->truncate();
+}
+
+
+// XAsyncOutputMonitor
+//-----------------------------------------------
+void SAL_CALL OFSStreamContainer::waitForCompletion()
+ throw ( io::IOException,
+ uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_bDisposed )
+ throw lang::DisposedException();
+
+ if ( !m_xStream.is() || !m_xAsyncOutputMonitor.is() )
+ throw uno::RuntimeException();
+
+ m_xAsyncOutputMonitor->waitForCompletion();
+}
+
+
+