xref: /aoo41x/main/io/source/stm/odata.cxx (revision 3716f815)
1*3716f815SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3716f815SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3716f815SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3716f815SAndrew Rist  * distributed with this work for additional information
6*3716f815SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3716f815SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3716f815SAndrew Rist  * "License"); you may not use this file except in compliance
9*3716f815SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3716f815SAndrew Rist  *
11*3716f815SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3716f815SAndrew Rist  *
13*3716f815SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3716f815SAndrew Rist  * software distributed under the License is distributed on an
15*3716f815SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3716f815SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3716f815SAndrew Rist  * specific language governing permissions and limitations
18*3716f815SAndrew Rist  * under the License.
19*3716f815SAndrew Rist  *
20*3716f815SAndrew Rist  *************************************************************/
21*3716f815SAndrew Rist 
22*3716f815SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_io.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // streams
29cdf0e10cSrcweir #include <hash_map>
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp>
33cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
35cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
36cdf0e10cSrcweir #include <com/sun/star/io/XMarkableStream.hpp>
37cdf0e10cSrcweir #include <com/sun/star/io/XConnectable.hpp>
38cdf0e10cSrcweir #include <com/sun/star/io/UnexpectedEOFException.hpp>
39cdf0e10cSrcweir #include <com/sun/star/io/WrongFormatException.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <cppuhelper/weak.hxx>      // OWeakObject
43cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
44cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
45cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
46cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <osl/mutex.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <string.h>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace ::cppu;
54cdf0e10cSrcweir using namespace ::osl;
55cdf0e10cSrcweir using namespace ::std;
56cdf0e10cSrcweir using namespace ::rtl;
57cdf0e10cSrcweir using namespace ::com::sun::star::io;
58cdf0e10cSrcweir using namespace ::com::sun::star::uno;
59cdf0e10cSrcweir using namespace ::com::sun::star::lang;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include "factreg.hxx"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace io_stm {
64cdf0e10cSrcweir 
65cdf0e10cSrcweir class ODataInputStream :
66cdf0e10cSrcweir 	public WeakImplHelper4 <
67cdf0e10cSrcweir                               XDataInputStream,
68cdf0e10cSrcweir 	                          XActiveDataSink,
69cdf0e10cSrcweir                               XConnectable,
70cdf0e10cSrcweir 			                  XServiceInfo
71cdf0e10cSrcweir                            >
72cdf0e10cSrcweir {
73cdf0e10cSrcweir public:
ODataInputStream()74cdf0e10cSrcweir 	ODataInputStream( )
75cdf0e10cSrcweir 		: m_bValidStream( sal_False )
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
78cdf0e10cSrcweir 		}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	~ODataInputStream();
81cdf0e10cSrcweir public: // XInputStream
82cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
83cdf0e10cSrcweir     														throw (	NotConnectedException,
84cdf0e10cSrcweir     																	BufferSizeExceededException,
85cdf0e10cSrcweir     																	RuntimeException);
86cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
87cdf0e10cSrcweir     														throw (	NotConnectedException,
88cdf0e10cSrcweir     																	BufferSizeExceededException,
89cdf0e10cSrcweir     																	RuntimeException);
90cdf0e10cSrcweir     virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) 				throw (	NotConnectedException,
91cdf0e10cSrcweir     																	BufferSizeExceededException,
92cdf0e10cSrcweir     																	RuntimeException);
93cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL available(void) 							throw (	NotConnectedException,
94cdf0e10cSrcweir     																	RuntimeException);
95cdf0e10cSrcweir     virtual void SAL_CALL closeInput(void) 							throw (	NotConnectedException,
96cdf0e10cSrcweir     																	RuntimeException);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir public: // XDataInputStream
99cdf0e10cSrcweir     virtual sal_Int8 SAL_CALL readBoolean(void) throw (IOException, RuntimeException);
100cdf0e10cSrcweir     virtual sal_Int8 SAL_CALL readByte(void) throw (IOException, RuntimeException);
101cdf0e10cSrcweir     virtual sal_Unicode SAL_CALL readChar(void) throw (IOException, RuntimeException);
102cdf0e10cSrcweir     virtual sal_Int16 SAL_CALL readShort(void) throw (IOException, RuntimeException);
103cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readLong(void) throw (IOException, RuntimeException);
104cdf0e10cSrcweir     virtual sal_Int64 SAL_CALL readHyper(void) throw (IOException, RuntimeException);
105cdf0e10cSrcweir     virtual float SAL_CALL readFloat(void) throw (IOException, RuntimeException);
106cdf0e10cSrcweir     virtual double SAL_CALL readDouble(void) throw (IOException, RuntimeException);
107cdf0e10cSrcweir     virtual OUString SAL_CALL readUTF(void) throw (IOException, RuntimeException);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir public: // XActiveDataSink
112cdf0e10cSrcweir     virtual void SAL_CALL setInputStream(const Reference< XInputStream > & aStream)
113cdf0e10cSrcweir 		throw (RuntimeException);
114cdf0e10cSrcweir     virtual Reference< XInputStream > SAL_CALL getInputStream(void) throw (RuntimeException);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir public: // XConnectable
117cdf0e10cSrcweir     virtual void SAL_CALL setPredecessor(const Reference < XConnectable >& aPredecessor) throw (RuntimeException);
118cdf0e10cSrcweir     virtual Reference < XConnectable > SAL_CALL getPredecessor(void) throw (RuntimeException);
119cdf0e10cSrcweir     virtual void SAL_CALL setSuccessor(const Reference < XConnectable >& aSuccessor) throw (RuntimeException);
120cdf0e10cSrcweir     virtual Reference < XConnectable > SAL_CALL getSuccessor(void) throw (RuntimeException) ;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir public: // XServiceInfo
124cdf0e10cSrcweir     OUString                     SAL_CALL getImplementationName() throw ();
125cdf0e10cSrcweir     Sequence< OUString >         SAL_CALL getSupportedServiceNames(void) throw ();
126cdf0e10cSrcweir 	sal_Bool                        SAL_CALL supportsService(const OUString& ServiceName) throw ();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir protected:
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	Reference < XConnectable > 	m_pred;
131cdf0e10cSrcweir 	Reference < XConnectable > 	m_succ;
132cdf0e10cSrcweir 	Reference < XInputStream > 	m_input;
133cdf0e10cSrcweir 	sal_Bool m_bValidStream;
134cdf0e10cSrcweir };
135cdf0e10cSrcweir 
~ODataInputStream()136cdf0e10cSrcweir ODataInputStream::~ODataInputStream()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // XInputStream
readBytes(Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)142cdf0e10cSrcweir sal_Int32 ODataInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
143cdf0e10cSrcweir 	throw (	NotConnectedException,
144cdf0e10cSrcweir 			BufferSizeExceededException,
145cdf0e10cSrcweir 			RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir  	sal_Int32 nRead;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir  	if( m_bValidStream )
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir  		nRead = m_input->readBytes( aData , nBytesToRead );
152cdf0e10cSrcweir  	}
153cdf0e10cSrcweir  	else
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir  		throw NotConnectedException( );
156cdf0e10cSrcweir  	}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir  	return nRead;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
readSomeBytes(Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)161cdf0e10cSrcweir sal_Int32 ODataInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
162cdf0e10cSrcweir 	throw (	NotConnectedException,
163cdf0e10cSrcweir 			BufferSizeExceededException,
164cdf0e10cSrcweir 			RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir  	sal_Int32 nRead;
167cdf0e10cSrcweir  	if( m_bValidStream ) {
168cdf0e10cSrcweir  		nRead = m_input->readSomeBytes( aData , nMaxBytesToRead );
169cdf0e10cSrcweir  	}
170cdf0e10cSrcweir  	else {
171cdf0e10cSrcweir  		throw NotConnectedException( );
172cdf0e10cSrcweir  	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir  	return nRead;
175cdf0e10cSrcweir }
skipBytes(sal_Int32 nBytesToSkip)176cdf0e10cSrcweir void ODataInputStream::skipBytes(sal_Int32 nBytesToSkip)
177cdf0e10cSrcweir 	throw (	NotConnectedException,
178cdf0e10cSrcweir 			BufferSizeExceededException,
179cdf0e10cSrcweir 			RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir  	if( m_bValidStream ) {
182cdf0e10cSrcweir  		m_input->skipBytes( nBytesToSkip );
183cdf0e10cSrcweir  	}
184cdf0e10cSrcweir  	else
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir  		throw NotConnectedException( );
187cdf0e10cSrcweir  	}
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
available(void)191cdf0e10cSrcweir sal_Int32 ODataInputStream::available(void)
192cdf0e10cSrcweir 	throw (	NotConnectedException,
193cdf0e10cSrcweir 			RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir  	sal_Int32 nAvail;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir  	if( m_bValidStream )
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir  		nAvail = m_input->available( );
200cdf0e10cSrcweir  	}
201cdf0e10cSrcweir  	else
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir  		throw NotConnectedException( );
204cdf0e10cSrcweir  	}
205cdf0e10cSrcweir  	return nAvail;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
closeInput(void)208cdf0e10cSrcweir void ODataInputStream::closeInput(void )
209cdf0e10cSrcweir 	throw (	NotConnectedException,
210cdf0e10cSrcweir 			RuntimeException)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir  	if( m_bValidStream ) {
213cdf0e10cSrcweir  		m_input->closeInput( );
214cdf0e10cSrcweir  		setInputStream( Reference< XInputStream > () );
215cdf0e10cSrcweir  		setPredecessor( Reference < XConnectable >() );
216cdf0e10cSrcweir  		setSuccessor( Reference < XConnectable >() );
217cdf0e10cSrcweir  		m_bValidStream = sal_False;
218cdf0e10cSrcweir  	}
219cdf0e10cSrcweir  	else
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir  		throw NotConnectedException( );
222cdf0e10cSrcweir  	}
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir //== XDataInputStream ===========================================
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // XDataInputStream
readBoolean(void)231cdf0e10cSrcweir sal_Int8 ODataInputStream::readBoolean(void) throw (IOException, RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	return readByte();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
readByte(void)236cdf0e10cSrcweir sal_Int8 ODataInputStream::readByte(void)	 throw (IOException, RuntimeException)
237cdf0e10cSrcweir {
238cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp(1);
239cdf0e10cSrcweir 	if( 1 != readBytes( aTmp, 1 ) )
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		throw UnexpectedEOFException();
242cdf0e10cSrcweir 	}
243cdf0e10cSrcweir 	return aTmp.getArray()[0];
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
readChar(void)246cdf0e10cSrcweir sal_Unicode ODataInputStream::readChar(void) throw (IOException, RuntimeException)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp(2);
249cdf0e10cSrcweir 	if( 2 != readBytes( aTmp, 2 ) )
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		throw UnexpectedEOFException();
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	const sal_uInt8 * pBytes = ( const sal_uInt8 * )aTmp.getConstArray();
255cdf0e10cSrcweir 	return ((sal_Unicode)pBytes[0] << 8) + pBytes[1];
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
readShort(void)258cdf0e10cSrcweir sal_Int16 ODataInputStream::readShort(void) throw (IOException, RuntimeException)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp(2);
261cdf0e10cSrcweir 	if( 2 != readBytes( aTmp, 2 ) )
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		throw UnexpectedEOFException();
264cdf0e10cSrcweir 	}
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray();
267cdf0e10cSrcweir 	return ((sal_Int16)pBytes[0] << 8) + pBytes[1];
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 
readLong(void)271cdf0e10cSrcweir sal_Int32 ODataInputStream::readLong(void) throw (IOException, RuntimeException)
272cdf0e10cSrcweir {
273cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp(4);
274cdf0e10cSrcweir 	if( 4 != readBytes( aTmp, 4 ) )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		throw UnexpectedEOFException( );
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray();
280cdf0e10cSrcweir 	return ((sal_Int32)pBytes[0] << 24) + ((sal_Int32)pBytes[1] << 16) + ((sal_Int32)pBytes[2] << 8) + pBytes[3];
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
readHyper(void)284cdf0e10cSrcweir sal_Int64 ODataInputStream::readHyper(void) throw (IOException, RuntimeException)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp(8);
287cdf0e10cSrcweir 	if( 8 != readBytes( aTmp, 8 ) )
288cdf0e10cSrcweir 	{
289cdf0e10cSrcweir 		throw UnexpectedEOFException( );
290cdf0e10cSrcweir 	}
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray();
293cdf0e10cSrcweir 	return
294cdf0e10cSrcweir 		(((sal_Int64)pBytes[0]) << 56) +
295cdf0e10cSrcweir 		(((sal_Int64)pBytes[1]) << 48) +
296cdf0e10cSrcweir 		(((sal_Int64)pBytes[2]) << 40) +
297cdf0e10cSrcweir 		(((sal_Int64)pBytes[3]) << 32) +
298cdf0e10cSrcweir 		(((sal_Int64)pBytes[4]) << 24) +
299cdf0e10cSrcweir 		(((sal_Int64)pBytes[5]) << 16) +
300cdf0e10cSrcweir 		(((sal_Int64)pBytes[6]) << 8) +
301cdf0e10cSrcweir 		pBytes[7];
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
readFloat(void)304cdf0e10cSrcweir float ODataInputStream::readFloat(void) throw (IOException, RuntimeException)
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	union { float f; sal_uInt32 n; } a;
307cdf0e10cSrcweir 	a.n = readLong();
308cdf0e10cSrcweir 	return a.f;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
readDouble(void)311cdf0e10cSrcweir double ODataInputStream::readDouble(void) throw (IOException, RuntimeException)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	sal_uInt32 n = 1;
314cdf0e10cSrcweir 	union { double d; struct { sal_uInt32 n1; sal_uInt32 n2; } ad; } a;
315cdf0e10cSrcweir 	if( *(sal_uInt8 *)&n == 1 )
316cdf0e10cSrcweir 	{
317cdf0e10cSrcweir 		// little endian
318cdf0e10cSrcweir 		a.ad.n2 = readLong();
319cdf0e10cSrcweir 		a.ad.n1 = readLong();
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir 	else
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		// big endian
324cdf0e10cSrcweir 		a.ad.n1 = readLong();
325cdf0e10cSrcweir 		a.ad.n2 = readLong();
326cdf0e10cSrcweir 	}
327cdf0e10cSrcweir 	return a.d;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
readUTF(void)330cdf0e10cSrcweir OUString ODataInputStream::readUTF(void) throw (IOException, RuntimeException)
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	sal_uInt16				nShortLen = (sal_uInt16)readShort();
333cdf0e10cSrcweir 	sal_Int32				nUTFLen;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	if( ((sal_uInt16)0xffff) == nShortLen )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		// is interpreted as a sign, that string is longer than 64k
338cdf0e10cSrcweir 		// incompatible to older XDataInputStream-routines, when strings are exactly 64k
339cdf0e10cSrcweir 		nUTFLen = readLong();
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 	else
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		nUTFLen = ( sal_Int32 ) nShortLen;
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	Sequence<sal_Unicode>	aBuffer( nUTFLen );
347cdf0e10cSrcweir 	sal_Unicode *			pStr = aBuffer.getArray();
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	sal_Int32 nCount = 0;
350cdf0e10cSrcweir 	sal_Int32 nStrLen = 0;
351cdf0e10cSrcweir 	while( nCount < nUTFLen )
352cdf0e10cSrcweir 	{
353cdf0e10cSrcweir 	    sal_uInt8 c = (sal_uInt8)readByte();
354cdf0e10cSrcweir 	    sal_uInt8 char2, char3;
355cdf0e10cSrcweir 	    switch( c >> 4 )
356cdf0e10cSrcweir 		{
357cdf0e10cSrcweir 	        case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
358cdf0e10cSrcweir 				// 0xxxxxxx
359cdf0e10cSrcweir 				nCount++;
360cdf0e10cSrcweir 				pStr[nStrLen++] = c;
361cdf0e10cSrcweir 				break;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 	        case 12: case 13:
364cdf0e10cSrcweir 				// 110x xxxx   10xx xxxx
365cdf0e10cSrcweir 				nCount += 2;
366cdf0e10cSrcweir 				if( ! ( nCount <= nUTFLen ) )
367cdf0e10cSrcweir 				{
368cdf0e10cSrcweir 					throw WrongFormatException( );
369cdf0e10cSrcweir 				}
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 				char2 = (sal_uInt8)readByte();
372cdf0e10cSrcweir 				if( ! ( (char2 & 0xC0) == 0x80 ) )
373cdf0e10cSrcweir 				{
374cdf0e10cSrcweir 					throw WrongFormatException( );
375cdf0e10cSrcweir 				}
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 				pStr[nStrLen++] = (sal_Unicode(c & 0x1F) << 6) | (char2 & 0x3F);
378cdf0e10cSrcweir 				break;
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	        case 14:
381cdf0e10cSrcweir 		    // 1110 xxxx  10xx xxxx  10xx xxxx
382cdf0e10cSrcweir 				nCount += 3;
383cdf0e10cSrcweir 				if( !( nCount <= nUTFLen) )
384cdf0e10cSrcweir 				{
385cdf0e10cSrcweir 					throw WrongFormatException( );
386cdf0e10cSrcweir 				}
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 				char2 = (sal_uInt8)readByte();
389cdf0e10cSrcweir 				char3 = (sal_uInt8)readByte();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 				if( (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) ) {
392cdf0e10cSrcweir 					throw WrongFormatException( );
393cdf0e10cSrcweir 				}
394cdf0e10cSrcweir 				pStr[nStrLen++] = (sal_Unicode(c & 0x0F) << 12) |
395cdf0e10cSrcweir 								(sal_Unicode(char2 & 0x3F) << 6) |
396cdf0e10cSrcweir 								(char3 & 0x3F);
397cdf0e10cSrcweir 				break;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	        default:
400cdf0e10cSrcweir 				// 10xx xxxx,  1111 xxxx
401cdf0e10cSrcweir 				throw WrongFormatException();
402cdf0e10cSrcweir 				//throw new UTFDataFormatException();
403cdf0e10cSrcweir 		}
404cdf0e10cSrcweir 	}
405cdf0e10cSrcweir 	return OUString( pStr, nStrLen );
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 
410cdf0e10cSrcweir // XActiveDataSource
setInputStream(const Reference<XInputStream> & aStream)411cdf0e10cSrcweir void ODataInputStream::setInputStream(const Reference< XInputStream > & aStream)
412cdf0e10cSrcweir 	throw (RuntimeException)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	if( m_input != aStream ) {
416cdf0e10cSrcweir 		m_input = aStream;
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 		Reference < XConnectable > pred( m_input , UNO_QUERY );
419cdf0e10cSrcweir 		setPredecessor( pred );
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	m_bValidStream = m_input.is();
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
getInputStream(void)425cdf0e10cSrcweir Reference< XInputStream > ODataInputStream::getInputStream(void) throw (RuntimeException)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	return m_input;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 
432cdf0e10cSrcweir // XDataSink
setSuccessor(const Reference<XConnectable> & r)433cdf0e10cSrcweir void ODataInputStream::setSuccessor( const Reference < XConnectable > &r ) throw (RuntimeException)
434cdf0e10cSrcweir {
435cdf0e10cSrcweir      /// if the references match, nothing needs to be done
436cdf0e10cSrcweir      if( m_succ != r ) {
437cdf0e10cSrcweir          /// store the reference for later use
438cdf0e10cSrcweir          m_succ = r;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir          if( m_succ.is() ) {
441cdf0e10cSrcweir               /// set this instance as the sink !
442cdf0e10cSrcweir               m_succ->setPredecessor( Reference< XConnectable > (
443cdf0e10cSrcweir 				  SAL_STATIC_CAST( XConnectable * , this ) ) );
444cdf0e10cSrcweir          }
445cdf0e10cSrcweir      }
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
getSuccessor()448cdf0e10cSrcweir Reference < XConnectable > ODataInputStream::getSuccessor() throw (RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	return m_succ;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 
454cdf0e10cSrcweir // XDataSource
setPredecessor(const Reference<XConnectable> & r)455cdf0e10cSrcweir void ODataInputStream::setPredecessor( const Reference < XConnectable > &r )
456cdf0e10cSrcweir 	throw (RuntimeException)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir 	if( r != m_pred ) {
459cdf0e10cSrcweir 		m_pred = r;
460cdf0e10cSrcweir 		if( m_pred.is() ) {
461cdf0e10cSrcweir 			m_pred->setSuccessor( Reference< XConnectable > (
462cdf0e10cSrcweir 				SAL_STATIC_CAST( XConnectable * , this ) ) );
463cdf0e10cSrcweir 		}
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir }
getPredecessor()466cdf0e10cSrcweir Reference < XConnectable > ODataInputStream::getPredecessor() throw (RuntimeException)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	return m_pred;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir // XServiceInfo
getImplementationName()472cdf0e10cSrcweir OUString ODataInputStream::getImplementationName() throw ()
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     return ODataInputStream_getImplementationName();
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)478cdf0e10cSrcweir sal_Bool ODataInputStream::supportsService(const OUString& ServiceName) throw ()
479cdf0e10cSrcweir {
480cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
481cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
482cdf0e10cSrcweir 
483cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
484cdf0e10cSrcweir         if( pArray[i] == ServiceName )
485cdf0e10cSrcweir             return sal_True;
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     return sal_False;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)491cdf0e10cSrcweir Sequence< OUString > ODataInputStream::getSupportedServiceNames(void) throw ()
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     return ODataInputStream_getSupportedServiceNames();
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir /***
497cdf0e10cSrcweir *
498cdf0e10cSrcweir * registration information
499cdf0e10cSrcweir *
500cdf0e10cSrcweir *
501cdf0e10cSrcweir ****/
502cdf0e10cSrcweir 
ODataInputStream_CreateInstance(const Reference<XComponentContext> &)503cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODataInputStream_CreateInstance( const Reference < XComponentContext > & ) throw( Exception)
504cdf0e10cSrcweir {
505cdf0e10cSrcweir 	ODataInputStream *p = new ODataInputStream;
506cdf0e10cSrcweir 	return Reference< XInterface > ( (OWeakObject * ) p );
507cdf0e10cSrcweir }
508cdf0e10cSrcweir 
ODataInputStream_getImplementationName()509cdf0e10cSrcweir OUString ODataInputStream_getImplementationName()
510cdf0e10cSrcweir {
511cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.DataInputStream" ) );
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
ODataInputStream_getSupportedServiceNames(void)514cdf0e10cSrcweir Sequence<OUString> ODataInputStream_getSupportedServiceNames(void)
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	Sequence<OUString> aRet(1);
517cdf0e10cSrcweir 	aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.DataInputStream" ) );
518cdf0e10cSrcweir 	return aRet;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 
524cdf0e10cSrcweir class ODataOutputStream :
525cdf0e10cSrcweir 	public WeakImplHelper4 <
526cdf0e10cSrcweir 			 XDataOutputStream,
527cdf0e10cSrcweir 			 XActiveDataSource,
528cdf0e10cSrcweir 			 XConnectable,
529cdf0e10cSrcweir  	         XServiceInfo >
530cdf0e10cSrcweir {
531cdf0e10cSrcweir public:
ODataOutputStream()532cdf0e10cSrcweir 	ODataOutputStream()
533cdf0e10cSrcweir 		: m_bValidStream( sal_False )
534cdf0e10cSrcweir 		{
535cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
536cdf0e10cSrcweir 		}
537cdf0e10cSrcweir 	~ODataOutputStream();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir public: // XOutputStream
540cdf0e10cSrcweir     virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData)
541cdf0e10cSrcweir 		throw (	NotConnectedException,
542cdf0e10cSrcweir 				BufferSizeExceededException,
543cdf0e10cSrcweir 				RuntimeException);
544cdf0e10cSrcweir     virtual void SAL_CALL flush(void)
545cdf0e10cSrcweir 		throw (	NotConnectedException,
546cdf0e10cSrcweir 				BufferSizeExceededException,
547cdf0e10cSrcweir 				RuntimeException);
548cdf0e10cSrcweir     virtual void SAL_CALL closeOutput(void)
549cdf0e10cSrcweir 		throw (	NotConnectedException,
550cdf0e10cSrcweir 				BufferSizeExceededException,
551cdf0e10cSrcweir 				RuntimeException);
552cdf0e10cSrcweir 
553cdf0e10cSrcweir public: // XDataOutputStream
554cdf0e10cSrcweir     virtual void SAL_CALL writeBoolean(sal_Bool Value) throw (IOException, RuntimeException);
555cdf0e10cSrcweir     virtual void SAL_CALL writeByte(sal_Int8 Value) throw (IOException, RuntimeException);
556cdf0e10cSrcweir     virtual void SAL_CALL writeChar(sal_Unicode Value) throw (IOException, RuntimeException);
557cdf0e10cSrcweir     virtual void SAL_CALL writeShort(sal_Int16 Value) throw (IOException, RuntimeException);
558cdf0e10cSrcweir     virtual void SAL_CALL writeLong(sal_Int32 Value) throw (IOException, RuntimeException);
559cdf0e10cSrcweir     virtual void SAL_CALL writeHyper(sal_Int64 Value) throw (IOException, RuntimeException);
560cdf0e10cSrcweir     virtual void SAL_CALL writeFloat(float Value) throw (IOException, RuntimeException);
561cdf0e10cSrcweir     virtual void SAL_CALL writeDouble(double Value) throw (IOException, RuntimeException);
562cdf0e10cSrcweir     virtual void SAL_CALL writeUTF(const OUString& Value) throw (IOException, RuntimeException);
563cdf0e10cSrcweir 
564cdf0e10cSrcweir public: // XActiveDataSource
565cdf0e10cSrcweir     virtual void SAL_CALL setOutputStream(const Reference< XOutputStream > & aStream)
566cdf0e10cSrcweir 		throw (RuntimeException);
567cdf0e10cSrcweir 	virtual Reference < XOutputStream > SAL_CALL getOutputStream(void) throw (RuntimeException);
568cdf0e10cSrcweir 
569cdf0e10cSrcweir public: // XConnectable
570cdf0e10cSrcweir     virtual void SAL_CALL setPredecessor(const Reference < XConnectable >& aPredecessor)
571cdf0e10cSrcweir 		throw (RuntimeException);
572cdf0e10cSrcweir 	virtual Reference < XConnectable > SAL_CALL getPredecessor(void)
573cdf0e10cSrcweir 		throw (RuntimeException);
574cdf0e10cSrcweir 	virtual void SAL_CALL setSuccessor(const Reference < XConnectable >& aSuccessor)
575cdf0e10cSrcweir 		throw (RuntimeException);
576cdf0e10cSrcweir     virtual Reference < XConnectable > SAL_CALL getSuccessor(void)
577cdf0e10cSrcweir 		throw (RuntimeException);
578cdf0e10cSrcweir 
579cdf0e10cSrcweir public: // XServiceInfo
580cdf0e10cSrcweir     OUString                     SAL_CALL getImplementationName() throw ();
581cdf0e10cSrcweir     Sequence< OUString >         SAL_CALL getSupportedServiceNames(void) throw ();
582cdf0e10cSrcweir     sal_Bool                     SAL_CALL supportsService(const OUString& ServiceName) throw ();
583cdf0e10cSrcweir 
584cdf0e10cSrcweir protected:
585cdf0e10cSrcweir 	Reference < XConnectable > 	m_succ;
586cdf0e10cSrcweir 	Reference < XConnectable >	m_pred;
587cdf0e10cSrcweir 	Reference<  XOutputStream > m_output;
588cdf0e10cSrcweir 	sal_Bool m_bValidStream;
589cdf0e10cSrcweir };
590cdf0e10cSrcweir 
~ODataOutputStream()591cdf0e10cSrcweir ODataOutputStream::~ODataOutputStream()
592cdf0e10cSrcweir {
593cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
594cdf0e10cSrcweir }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 
597cdf0e10cSrcweir // XOutputStream
writeBytes(const Sequence<sal_Int8> & aData)598cdf0e10cSrcweir void ODataOutputStream::writeBytes(const Sequence< sal_Int8 >& aData)
599cdf0e10cSrcweir 	throw (	NotConnectedException,
600cdf0e10cSrcweir 			BufferSizeExceededException,
601cdf0e10cSrcweir 			RuntimeException)
602cdf0e10cSrcweir {
603cdf0e10cSrcweir 	if( m_bValidStream )
604cdf0e10cSrcweir 	{
605cdf0e10cSrcweir 		m_output->writeBytes( aData );
606cdf0e10cSrcweir 	}
607cdf0e10cSrcweir 	else {
608cdf0e10cSrcweir 		throw NotConnectedException( );
609cdf0e10cSrcweir 	}
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
flush(void)612cdf0e10cSrcweir void ODataOutputStream::flush(void)
613cdf0e10cSrcweir 	throw (	NotConnectedException,
614cdf0e10cSrcweir 			BufferSizeExceededException,
615cdf0e10cSrcweir 			RuntimeException)
616cdf0e10cSrcweir {
617cdf0e10cSrcweir 	if( m_bValidStream )
618cdf0e10cSrcweir 	{
619cdf0e10cSrcweir 		m_output->flush();
620cdf0e10cSrcweir 	}
621cdf0e10cSrcweir 	else
622cdf0e10cSrcweir 	{
623cdf0e10cSrcweir 		throw NotConnectedException();
624cdf0e10cSrcweir 	}
625cdf0e10cSrcweir 
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 
closeOutput(void)629cdf0e10cSrcweir void ODataOutputStream::closeOutput(void)
630cdf0e10cSrcweir 	throw (	NotConnectedException,
631cdf0e10cSrcweir 			BufferSizeExceededException,
632cdf0e10cSrcweir 			RuntimeException)
633cdf0e10cSrcweir {
634cdf0e10cSrcweir 	if( m_bValidStream )
635cdf0e10cSrcweir 	{
636cdf0e10cSrcweir 		m_output->closeOutput();
637cdf0e10cSrcweir 		setOutputStream( Reference< XOutputStream > () );
638cdf0e10cSrcweir 		setPredecessor( Reference < XConnectable >() );
639cdf0e10cSrcweir 		setSuccessor( Reference < XConnectable >() );
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 	else
642cdf0e10cSrcweir 	{
643cdf0e10cSrcweir 		throw NotConnectedException();
644cdf0e10cSrcweir 	}
645cdf0e10cSrcweir }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir // XDataOutputStream
writeBoolean(sal_Bool Value)648cdf0e10cSrcweir void ODataOutputStream::writeBoolean(sal_Bool Value)
649cdf0e10cSrcweir 	throw (	IOException,
650cdf0e10cSrcweir 			RuntimeException)
651cdf0e10cSrcweir {
652cdf0e10cSrcweir 	if( Value )
653cdf0e10cSrcweir 	{
654cdf0e10cSrcweir 		writeByte( 1 );
655cdf0e10cSrcweir 	}
656cdf0e10cSrcweir 	else
657cdf0e10cSrcweir 	{
658cdf0e10cSrcweir 		writeByte( 0 );
659cdf0e10cSrcweir 	}
660cdf0e10cSrcweir }
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 
writeByte(sal_Int8 Value)663cdf0e10cSrcweir void ODataOutputStream::writeByte(sal_Int8 Value)
664cdf0e10cSrcweir 	throw (	IOException,
665cdf0e10cSrcweir 			RuntimeException)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp( 1 );
668cdf0e10cSrcweir 	aTmp.getArray()[0] = Value;
669cdf0e10cSrcweir 	writeBytes( aTmp );
670cdf0e10cSrcweir }
671cdf0e10cSrcweir 
writeChar(sal_Unicode Value)672cdf0e10cSrcweir void ODataOutputStream::writeChar(sal_Unicode Value)
673cdf0e10cSrcweir 	throw (	IOException,
674cdf0e10cSrcweir 			RuntimeException)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp( 2 );
677cdf0e10cSrcweir 	sal_Int8 * pBytes = ( sal_Int8 * ) aTmp.getArray();
678cdf0e10cSrcweir 	pBytes[0] = sal_Int8(Value >> 8);
679cdf0e10cSrcweir 	pBytes[1] = sal_Int8(Value);
680cdf0e10cSrcweir 	writeBytes( aTmp );
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 
writeShort(sal_Int16 Value)684cdf0e10cSrcweir void ODataOutputStream::writeShort(sal_Int16 Value)
685cdf0e10cSrcweir 	throw (	IOException,
686cdf0e10cSrcweir 			RuntimeException)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp( 2 );
689cdf0e10cSrcweir 	sal_Int8 * pBytes = aTmp.getArray();
690cdf0e10cSrcweir 	pBytes[0] = sal_Int8(Value >> 8);
691cdf0e10cSrcweir 	pBytes[1] = sal_Int8(Value);
692cdf0e10cSrcweir 	writeBytes( aTmp );
693cdf0e10cSrcweir }
694cdf0e10cSrcweir 
writeLong(sal_Int32 Value)695cdf0e10cSrcweir void ODataOutputStream::writeLong(sal_Int32 Value)
696cdf0e10cSrcweir 	throw (	IOException,
697cdf0e10cSrcweir 			RuntimeException)
698cdf0e10cSrcweir {
699cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp( 4 );
700cdf0e10cSrcweir 	sal_Int8 * pBytes = aTmp.getArray();
701cdf0e10cSrcweir 	pBytes[0] = sal_Int8(Value >> 24);
702cdf0e10cSrcweir 	pBytes[1] = sal_Int8(Value >> 16);
703cdf0e10cSrcweir 	pBytes[2] = sal_Int8(Value >> 8);
704cdf0e10cSrcweir 	pBytes[3] = sal_Int8(Value);
705cdf0e10cSrcweir 	writeBytes( aTmp );
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
writeHyper(sal_Int64 Value)708cdf0e10cSrcweir void ODataOutputStream::writeHyper(sal_Int64 Value)
709cdf0e10cSrcweir 	throw (	IOException,
710cdf0e10cSrcweir 			RuntimeException)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir 	Sequence<sal_Int8> aTmp( 8 );
713cdf0e10cSrcweir 	sal_Int8 * pBytes = aTmp.getArray();
714cdf0e10cSrcweir 	pBytes[0] = sal_Int8(Value >> 56);
715cdf0e10cSrcweir 	pBytes[1] = sal_Int8(Value >> 48);
716cdf0e10cSrcweir 	pBytes[2] = sal_Int8(Value >> 40);
717cdf0e10cSrcweir 	pBytes[3] = sal_Int8(Value >> 32);
718cdf0e10cSrcweir 	pBytes[4] = sal_Int8(Value >> 24);
719cdf0e10cSrcweir 	pBytes[5] = sal_Int8(Value >> 16);
720cdf0e10cSrcweir 	pBytes[6] = sal_Int8(Value >> 8);
721cdf0e10cSrcweir 	pBytes[7] = sal_Int8(Value);
722cdf0e10cSrcweir 	writeBytes( aTmp );
723cdf0e10cSrcweir }
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 
writeFloat(float Value)726cdf0e10cSrcweir void ODataOutputStream::writeFloat(float Value)
727cdf0e10cSrcweir 	throw (	IOException,
728cdf0e10cSrcweir 			RuntimeException)
729cdf0e10cSrcweir {
730cdf0e10cSrcweir 	union { float f; sal_uInt32 n; } a;
731cdf0e10cSrcweir 	a.f = Value;
732cdf0e10cSrcweir 	writeLong( a.n );
733cdf0e10cSrcweir }
734cdf0e10cSrcweir 
writeDouble(double Value)735cdf0e10cSrcweir void ODataOutputStream::writeDouble(double Value)
736cdf0e10cSrcweir 	throw (	IOException,
737cdf0e10cSrcweir 			RuntimeException)
738cdf0e10cSrcweir {
739cdf0e10cSrcweir 	sal_uInt32 n = 1;
740cdf0e10cSrcweir 	union { double d; struct { sal_uInt32 n1; sal_uInt32 n2; } ad; } a;
741cdf0e10cSrcweir 	a.d = Value;
742cdf0e10cSrcweir 	if( *(sal_Int8 *)&n == 1 )
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir 		// little endian
745cdf0e10cSrcweir 		writeLong( a.ad.n2 );
746cdf0e10cSrcweir 		writeLong( a.ad.n1 );
747cdf0e10cSrcweir 	}
748cdf0e10cSrcweir 	else
749cdf0e10cSrcweir 	{
750cdf0e10cSrcweir 		// big endian
751cdf0e10cSrcweir 		writeLong( a.ad.n1 );
752cdf0e10cSrcweir 		writeLong( a.ad.n2 );
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
writeUTF(const OUString & Value)756cdf0e10cSrcweir void ODataOutputStream::writeUTF(const OUString& Value)
757cdf0e10cSrcweir 	throw (	IOException,
758cdf0e10cSrcweir 			RuntimeException)
759cdf0e10cSrcweir {
760cdf0e10cSrcweir 	sal_Int32 nStrLen = Value.getLength();
761cdf0e10cSrcweir 	const sal_Unicode * pStr = Value.getStr();
762cdf0e10cSrcweir 	sal_Int32 nUTFLen = 0;
763cdf0e10cSrcweir 	sal_Int32 i;
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	for( i = 0 ; i < nStrLen ; i++ )
766cdf0e10cSrcweir 	{
767cdf0e10cSrcweir 	    sal_uInt16 c = pStr[i];
768cdf0e10cSrcweir 	    if( (c >= 0x0001) && (c <= 0x007F) )
769cdf0e10cSrcweir 		{
770cdf0e10cSrcweir 			nUTFLen++;
771cdf0e10cSrcweir 	    }
772cdf0e10cSrcweir 		else if( c > 0x07FF )
773cdf0e10cSrcweir 		{
774cdf0e10cSrcweir 			nUTFLen += 3;
775cdf0e10cSrcweir 	    }
776cdf0e10cSrcweir 		else
777cdf0e10cSrcweir 		{
778cdf0e10cSrcweir 			nUTFLen += 2;
779cdf0e10cSrcweir 	    }
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 	// compatibility mode for older implementations, where it was not possible
784cdf0e10cSrcweir 	// to write blocks bigger than 64 k. Note that there is a tradeoff. Blocks,
785cdf0e10cSrcweir 	// that are exactly 64k long can not be read by older routines when written
786cdf0e10cSrcweir 	// with these routines and the other way round !!!!!
787cdf0e10cSrcweir 	if( nUTFLen >= 0xFFFF ) {
788cdf0e10cSrcweir 		writeShort( (sal_Int16)-1 );
789cdf0e10cSrcweir 		writeLong( nUTFLen );
790cdf0e10cSrcweir 	}
791cdf0e10cSrcweir 	else {
792cdf0e10cSrcweir 		writeShort( ((sal_uInt16)nUTFLen) );
793cdf0e10cSrcweir 	}
794cdf0e10cSrcweir 	for( i = 0 ; i < nStrLen ; i++ )
795cdf0e10cSrcweir 	{
796cdf0e10cSrcweir 	    sal_uInt16 c = pStr[i];
797cdf0e10cSrcweir 	    if( (c >= 0x0001) && (c <= 0x007F) )
798cdf0e10cSrcweir 		{
799cdf0e10cSrcweir 			writeByte(sal_Int8(c));
800cdf0e10cSrcweir 	    }
801cdf0e10cSrcweir 		else if( c > 0x07FF )
802cdf0e10cSrcweir 		{
803cdf0e10cSrcweir 			writeByte(sal_Int8(0xE0 | ((c >> 12) & 0x0F)));
804cdf0e10cSrcweir 			writeByte(sal_Int8(0x80 | ((c >>  6) & 0x3F)));
805cdf0e10cSrcweir 			writeByte(sal_Int8(0x80 | ((c >>  0) & 0x3F)));
806cdf0e10cSrcweir 			//written += 2;
807cdf0e10cSrcweir 	    }
808cdf0e10cSrcweir 		else
809cdf0e10cSrcweir 		{
810cdf0e10cSrcweir 			writeByte(sal_Int8(0xC0 | ((c >>  6) & 0x1F)));
811cdf0e10cSrcweir 			writeByte(sal_Int8(0x80 | ((c >>  0) & 0x3F)));
812cdf0e10cSrcweir 			//written += 1;
813cdf0e10cSrcweir 	    }
814cdf0e10cSrcweir 	}
815cdf0e10cSrcweir 	//written += strlen + 2;
816cdf0e10cSrcweir }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir // XActiveDataSource
setOutputStream(const Reference<XOutputStream> & aStream)819cdf0e10cSrcweir void ODataOutputStream::setOutputStream(const Reference< XOutputStream > & aStream)
820cdf0e10cSrcweir 	throw (RuntimeException)
821cdf0e10cSrcweir {
822cdf0e10cSrcweir 	if( m_output != aStream ) {
823cdf0e10cSrcweir 		m_output = aStream;
824cdf0e10cSrcweir 		m_bValidStream = m_output.is();
825cdf0e10cSrcweir 
826cdf0e10cSrcweir 		Reference < XConnectable > succ( m_output , UNO_QUERY );
827cdf0e10cSrcweir 		setSuccessor( succ );
828cdf0e10cSrcweir 	}
829cdf0e10cSrcweir }
830cdf0e10cSrcweir 
getOutputStream(void)831cdf0e10cSrcweir Reference< XOutputStream > ODataOutputStream::getOutputStream(void)
832cdf0e10cSrcweir 	throw (RuntimeException)
833cdf0e10cSrcweir {
834cdf0e10cSrcweir 	return m_output;
835cdf0e10cSrcweir }
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 
840cdf0e10cSrcweir // XDataSink
setSuccessor(const Reference<XConnectable> & r)841cdf0e10cSrcweir void ODataOutputStream::setSuccessor( const Reference < XConnectable > &r )
842cdf0e10cSrcweir 	throw (RuntimeException)
843cdf0e10cSrcweir {
844cdf0e10cSrcweir      /// if the references match, nothing needs to be done
845cdf0e10cSrcweir      if( m_succ != r )
846cdf0e10cSrcweir 	 {
847cdf0e10cSrcweir          /// store the reference for later use
848cdf0e10cSrcweir          m_succ = r;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir          if( m_succ.is() )
851cdf0e10cSrcweir 		 {
852cdf0e10cSrcweir               /// set this instance as the sink !
853cdf0e10cSrcweir               m_succ->setPredecessor( Reference < XConnectable > (
854cdf0e10cSrcweir 				  SAL_STATIC_CAST( XConnectable * , this  ) ));
855cdf0e10cSrcweir          }
856cdf0e10cSrcweir      }
857cdf0e10cSrcweir }
getSuccessor()858cdf0e10cSrcweir Reference < XConnectable > ODataOutputStream::getSuccessor()	throw (RuntimeException)
859cdf0e10cSrcweir {
860cdf0e10cSrcweir 	return m_succ;
861cdf0e10cSrcweir }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir 
864cdf0e10cSrcweir // XDataSource
setPredecessor(const Reference<XConnectable> & r)865cdf0e10cSrcweir void ODataOutputStream::setPredecessor( const Reference < XConnectable > &r )	throw (RuntimeException)
866cdf0e10cSrcweir {
867cdf0e10cSrcweir 	if( r != m_pred ) {
868cdf0e10cSrcweir 		m_pred = r;
869cdf0e10cSrcweir 		if( m_pred.is() ) {
870cdf0e10cSrcweir 			m_pred->setSuccessor( Reference< XConnectable > (
871cdf0e10cSrcweir 				SAL_STATIC_CAST( XConnectable * , this  ) ));
872cdf0e10cSrcweir 		}
873cdf0e10cSrcweir 	}
874cdf0e10cSrcweir }
getPredecessor()875cdf0e10cSrcweir Reference < XConnectable > ODataOutputStream::getPredecessor()	throw (RuntimeException)
876cdf0e10cSrcweir {
877cdf0e10cSrcweir 	return m_pred;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 
881cdf0e10cSrcweir 
882cdf0e10cSrcweir // XServiceInfo
getImplementationName()883cdf0e10cSrcweir OUString ODataOutputStream::getImplementationName() throw ()
884cdf0e10cSrcweir {
885cdf0e10cSrcweir     return ODataOutputStream_getImplementationName();
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)889cdf0e10cSrcweir sal_Bool ODataOutputStream::supportsService(const OUString& ServiceName) throw ()
890cdf0e10cSrcweir {
891cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
892cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
893cdf0e10cSrcweir 
894cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
895cdf0e10cSrcweir         if( pArray[i] == ServiceName )
896cdf0e10cSrcweir             return sal_True;
897cdf0e10cSrcweir 
898cdf0e10cSrcweir     return sal_False;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)902cdf0e10cSrcweir Sequence< OUString > ODataOutputStream::getSupportedServiceNames(void) throw ()
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     return ODataOutputStream_getSupportedServiceNames();
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 
ODataOutputStream_CreateInstance(const Reference<XComponentContext> &)910cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODataOutputStream_CreateInstance( const Reference < XComponentContext > & ) throw(Exception)
911cdf0e10cSrcweir {
912cdf0e10cSrcweir 	ODataOutputStream *p = new ODataOutputStream;
913cdf0e10cSrcweir 	Reference< XInterface > xService = *p;
914cdf0e10cSrcweir 	return xService;
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 
ODataOutputStream_getImplementationName()918cdf0e10cSrcweir OUString ODataOutputStream_getImplementationName()
919cdf0e10cSrcweir {
920cdf0e10cSrcweir 	return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.DataOutputStream" ) );
921cdf0e10cSrcweir }
922cdf0e10cSrcweir 
ODataOutputStream_getSupportedServiceNames(void)923cdf0e10cSrcweir Sequence<OUString> ODataOutputStream_getSupportedServiceNames(void)
924cdf0e10cSrcweir {
925cdf0e10cSrcweir 	Sequence<OUString> aRet(1);
926cdf0e10cSrcweir 	aRet.getArray()[0] =  OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.DataOutputStream" ) );
927cdf0e10cSrcweir 	return aRet;
928cdf0e10cSrcweir }
929cdf0e10cSrcweir 
930cdf0e10cSrcweir //--------------------------------------
931cdf0e10cSrcweir struct equalObjectContainer_Impl
932cdf0e10cSrcweir {
operator ()io_stm::equalObjectContainer_Impl933cdf0e10cSrcweir 	sal_Int32 operator()(const Reference< XInterface > & s1,
934cdf0e10cSrcweir 						 const Reference< XInterface > & s2) const
935cdf0e10cSrcweir   	{
936cdf0e10cSrcweir     	return s1 == s2;
937cdf0e10cSrcweir 	}
938cdf0e10cSrcweir };
939cdf0e10cSrcweir 
940cdf0e10cSrcweir //-----------------------------------------------------------------------------
941cdf0e10cSrcweir struct hashObjectContainer_Impl
942cdf0e10cSrcweir {
operator ()io_stm::hashObjectContainer_Impl943cdf0e10cSrcweir 	size_t operator()(const Reference< XInterface > & xRef) const
944cdf0e10cSrcweir 	{
945cdf0e10cSrcweir 		return (size_t)xRef.get();
946cdf0e10cSrcweir 	}
947cdf0e10cSrcweir };
948cdf0e10cSrcweir 
949cdf0e10cSrcweir typedef hash_map
950cdf0e10cSrcweir <
951cdf0e10cSrcweir 	Reference< XInterface >,
952cdf0e10cSrcweir 	sal_Int32,
953cdf0e10cSrcweir 	hashObjectContainer_Impl,
954cdf0e10cSrcweir 	equalObjectContainer_Impl
955cdf0e10cSrcweir > ObjectContainer_Impl;
956cdf0e10cSrcweir 
957cdf0e10cSrcweir /*---------------------------------------------
958cdf0e10cSrcweir *
959cdf0e10cSrcweir *
960cdf0e10cSrcweir *
961cdf0e10cSrcweir *
962cdf0e10cSrcweir *--------------------------------------------*/
963cdf0e10cSrcweir class OObjectOutputStream :
964cdf0e10cSrcweir 			public ODataOutputStream,
965cdf0e10cSrcweir 			public XObjectOutputStream,
966cdf0e10cSrcweir 			public XMarkableStream
967cdf0e10cSrcweir {
968cdf0e10cSrcweir public:
OObjectOutputStream()969cdf0e10cSrcweir 	OObjectOutputStream()
970cdf0e10cSrcweir 		: m_nMaxId(0) ,
971cdf0e10cSrcweir 		  m_bValidMarkable(sal_False)
972cdf0e10cSrcweir 		{
973cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
974cdf0e10cSrcweir 		}
975cdf0e10cSrcweir 
976cdf0e10cSrcweir 	~OObjectOutputStream();
977cdf0e10cSrcweir 
978cdf0e10cSrcweir public:
979cdf0e10cSrcweir         Any             SAL_CALL queryInterface( const Type &type ) throw (::com::sun::star::uno::RuntimeException);
acquire()980cdf0e10cSrcweir         void    SAL_CALL acquire() throw()                                       { ODataOutputStream::acquire(); }
release()981cdf0e10cSrcweir         void    SAL_CALL release() throw()                                       { ODataOutputStream::release(); }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir public:
984cdf0e10cSrcweir 	// XOutputStream
writeBytes(const Sequence<sal_Int8> & aData)985cdf0e10cSrcweir     virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData)
986cdf0e10cSrcweir 		throw (	NotConnectedException,
987cdf0e10cSrcweir 				BufferSizeExceededException,
988cdf0e10cSrcweir 				RuntimeException)
989cdf0e10cSrcweir 		{ ODataOutputStream::writeBytes( aData ); }
990cdf0e10cSrcweir 
flush(void)991cdf0e10cSrcweir     virtual void SAL_CALL flush(void)
992cdf0e10cSrcweir 		throw (	NotConnectedException,
993cdf0e10cSrcweir 				BufferSizeExceededException,
994cdf0e10cSrcweir 				RuntimeException)
995cdf0e10cSrcweir 		{ ODataOutputStream::flush(); }
996cdf0e10cSrcweir 
closeOutput(void)997cdf0e10cSrcweir     virtual void SAL_CALL closeOutput(void)
998cdf0e10cSrcweir 		throw (	NotConnectedException,
999cdf0e10cSrcweir 				BufferSizeExceededException,
1000cdf0e10cSrcweir 				RuntimeException)
1001cdf0e10cSrcweir 		{ ODataOutputStream::closeOutput(); }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir public:
1004cdf0e10cSrcweir 	// XDataOutputStream
writeBoolean(sal_Bool Value)1005cdf0e10cSrcweir     virtual void SAL_CALL writeBoolean(sal_Bool Value) throw (IOException, RuntimeException)
1006cdf0e10cSrcweir     			{ ODataOutputStream::writeBoolean( Value ); }
writeByte(sal_Int8 Value)1007cdf0e10cSrcweir     virtual void SAL_CALL writeByte(sal_Int8 Value) throw (IOException, RuntimeException)
1008cdf0e10cSrcweir     			{ ODataOutputStream::writeByte( Value ); }
writeChar(sal_Unicode Value)1009cdf0e10cSrcweir     virtual void SAL_CALL writeChar(sal_Unicode Value) throw (IOException, RuntimeException)
1010cdf0e10cSrcweir     			{ ODataOutputStream::writeChar( Value ); }
writeShort(sal_Int16 Value)1011cdf0e10cSrcweir     virtual void SAL_CALL writeShort(sal_Int16 Value) throw (IOException, RuntimeException)
1012cdf0e10cSrcweir     			{ ODataOutputStream::writeShort( Value ); }
writeLong(sal_Int32 Value)1013cdf0e10cSrcweir     virtual void SAL_CALL writeLong(sal_Int32 Value) throw (IOException, RuntimeException)
1014cdf0e10cSrcweir     			{ ODataOutputStream::writeLong( Value ); }
writeHyper(sal_Int64 Value)1015cdf0e10cSrcweir     virtual void SAL_CALL writeHyper(sal_Int64 Value) throw (IOException, RuntimeException)
1016cdf0e10cSrcweir     			{ ODataOutputStream::writeHyper( Value ); }
writeFloat(float Value)1017cdf0e10cSrcweir     virtual void SAL_CALL writeFloat(float Value) throw (IOException, RuntimeException)
1018cdf0e10cSrcweir     			{ ODataOutputStream::writeFloat( Value ); }
writeDouble(double Value)1019cdf0e10cSrcweir     virtual void SAL_CALL writeDouble(double Value) throw (IOException, RuntimeException)
1020cdf0e10cSrcweir     			{ ODataOutputStream::writeDouble( Value ); }
writeUTF(const OUString & Value)1021cdf0e10cSrcweir     virtual void SAL_CALL writeUTF(const OUString& Value) throw (IOException, RuntimeException)
1022cdf0e10cSrcweir     			{ ODataOutputStream::writeUTF( Value );}
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 	// XObjectOutputStream
1025cdf0e10cSrcweir         virtual void SAL_CALL writeObject( const Reference< XPersistObject > & r ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir public: // XMarkableStream
1028cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL createMark(void) 				throw (IOException, RuntimeException);
1029cdf0e10cSrcweir     virtual void SAL_CALL deleteMark(sal_Int32 Mark)			throw (IOException, IllegalArgumentException, RuntimeException);
1030cdf0e10cSrcweir     virtual void SAL_CALL jumpToMark(sal_Int32 nMark) 		throw (IOException, IllegalArgumentException, RuntimeException);
1031cdf0e10cSrcweir     virtual void SAL_CALL jumpToFurthest(void) 			throw (IOException, RuntimeException);
1032cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL offsetToMark(sal_Int32 nMark)
1033cdf0e10cSrcweir 		throw (IOException, IllegalArgumentException, RuntimeException);
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir public: //XTypeProvider
1036cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL
1037cdf0e10cSrcweir 	        getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
1038cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
1039cdf0e10cSrcweir             getImplementationId(  ) throw(::com::sun::star::uno::RuntimeException);
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir public: // XServiceInfo
1042cdf0e10cSrcweir     OUString                   SAL_CALL   getImplementationName() throw ();
1043cdf0e10cSrcweir     Sequence< OUString >       SAL_CALL   getSupportedServiceNames(void) throw ();
1044cdf0e10cSrcweir     sal_Bool                   SAL_CALL   supportsService(const OUString& ServiceName) throw ();
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir private:
1047cdf0e10cSrcweir 	void connectToMarkable();
1048cdf0e10cSrcweir private:
1049cdf0e10cSrcweir 	ObjectContainer_Impl	            m_mapObject;
1050cdf0e10cSrcweir 	sal_Int32							m_nMaxId;
1051cdf0e10cSrcweir 	Reference< XMarkableStream > 		m_rMarkable;
1052cdf0e10cSrcweir 	sal_Bool 							m_bValidMarkable;
1053cdf0e10cSrcweir };
1054cdf0e10cSrcweir 
~OObjectOutputStream()1055cdf0e10cSrcweir OObjectOutputStream::~OObjectOutputStream()
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
queryInterface(const Type & aType)1060cdf0e10cSrcweir Any OObjectOutputStream::queryInterface( const Type &aType ) throw (::com::sun::star::uno::RuntimeException)
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
1063cdf0e10cSrcweir 		aType ,
1064cdf0e10cSrcweir 		SAL_STATIC_CAST( XMarkableStream * , this ),
1065cdf0e10cSrcweir 		SAL_STATIC_CAST( XObjectOutputStream * , this ) );
1066cdf0e10cSrcweir 	if( a.hasValue() )
1067cdf0e10cSrcweir 	{
1068cdf0e10cSrcweir 		return a;
1069cdf0e10cSrcweir 	}
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 	return ODataOutputStream::queryInterface( aType );
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir }
writeObject(const Reference<XPersistObject> & xPObj)1074cdf0e10cSrcweir void OObjectOutputStream::writeObject( const Reference< XPersistObject > & xPObj ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 	connectToMarkable();
1078cdf0e10cSrcweir 	sal_Bool bWriteObj = sal_False;
1079cdf0e10cSrcweir 	// create Mark to write length of info
1080cdf0e10cSrcweir 	sal_uInt32 nInfoLenMark = m_rMarkable->createMark();
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir 	// length of the info data (is later rewritten)
1083cdf0e10cSrcweir 	OObjectOutputStream::writeShort( 0 );
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir 	// write the object identifier
1086cdf0e10cSrcweir 	if( xPObj.is() )
1087cdf0e10cSrcweir 	{
1088cdf0e10cSrcweir 		Reference< XInterface > rX( xPObj , UNO_QUERY );
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 		ObjectContainer_Impl::const_iterator aIt
1091cdf0e10cSrcweir 			= m_mapObject.find( rX );
1092cdf0e10cSrcweir 		if( aIt == m_mapObject.end() )
1093cdf0e10cSrcweir 		{
1094cdf0e10cSrcweir 			// insert new object in hash table
1095cdf0e10cSrcweir 			m_mapObject[ rX ] = ++m_nMaxId;
1096cdf0e10cSrcweir 			ODataOutputStream::writeLong( m_nMaxId );
1097cdf0e10cSrcweir 			ODataOutputStream::writeUTF( xPObj->getServiceName() );
1098cdf0e10cSrcweir 			bWriteObj = sal_True;
1099cdf0e10cSrcweir 		}
1100cdf0e10cSrcweir 		else
1101cdf0e10cSrcweir 		{
1102cdf0e10cSrcweir 			ODataOutputStream::writeLong( (*aIt).second );
1103cdf0e10cSrcweir 			OUString aName;
1104cdf0e10cSrcweir 			ODataOutputStream::writeUTF( aName );
1105cdf0e10cSrcweir 		}
1106cdf0e10cSrcweir 	}
1107cdf0e10cSrcweir 	else
1108cdf0e10cSrcweir 	{
1109cdf0e10cSrcweir 		ODataOutputStream::writeLong( 0 );
1110cdf0e10cSrcweir 		OUString aName;
1111cdf0e10cSrcweir 		ODataOutputStream::writeUTF( aName );
1112cdf0e10cSrcweir 	}
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir 	sal_uInt32 nObjLenMark = m_rMarkable->createMark();
1115cdf0e10cSrcweir 	ODataOutputStream::writeLong( 0 );
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 	sal_Int32 nInfoLen = m_rMarkable->offsetToMark( nInfoLenMark );
1118cdf0e10cSrcweir 	m_rMarkable->jumpToMark( nInfoLenMark );
1119cdf0e10cSrcweir 	// write length of the info data
1120cdf0e10cSrcweir 	ODataOutputStream::writeShort( (sal_Int16)nInfoLen );
1121cdf0e10cSrcweir 	// jump to the end of the stream
1122cdf0e10cSrcweir 	m_rMarkable->jumpToFurthest();
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 	if( bWriteObj )
1125cdf0e10cSrcweir 		xPObj->write( Reference< XObjectOutputStream > (
1126cdf0e10cSrcweir 			SAL_STATIC_CAST( XObjectOutputStream * , this ) ) );
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir 	sal_Int32 nObjLen = m_rMarkable->offsetToMark( nObjLenMark ) -4;
1129cdf0e10cSrcweir 	m_rMarkable->jumpToMark( nObjLenMark );
1130cdf0e10cSrcweir 	// write length of the info data
1131cdf0e10cSrcweir 	ODataOutputStream::writeLong( nObjLen );
1132cdf0e10cSrcweir 	// jump to the end of the stream
1133cdf0e10cSrcweir 	m_rMarkable->jumpToFurthest();
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 	m_rMarkable->deleteMark( nObjLenMark );
1136cdf0e10cSrcweir 	m_rMarkable->deleteMark( nInfoLenMark );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 
connectToMarkable(void)1141cdf0e10cSrcweir void OObjectOutputStream::connectToMarkable(void)
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir 	if( ! m_bValidMarkable ) {
1144cdf0e10cSrcweir 		if( ! m_bValidStream )
1145cdf0e10cSrcweir 		{
1146cdf0e10cSrcweir 			throw NotConnectedException();
1147cdf0e10cSrcweir 		}
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 		// find the markable stream !
1150cdf0e10cSrcweir 		Reference< XInterface > rTry(m_output);
1151cdf0e10cSrcweir 		while( sal_True ) {
1152cdf0e10cSrcweir 			if( ! rTry.is() )
1153cdf0e10cSrcweir 			{
1154cdf0e10cSrcweir 				throw NotConnectedException();
1155cdf0e10cSrcweir 			}
1156cdf0e10cSrcweir 			Reference < XMarkableStream > markable( rTry , UNO_QUERY );
1157cdf0e10cSrcweir 			if( markable.is() )
1158cdf0e10cSrcweir 			{
1159cdf0e10cSrcweir 				m_rMarkable = markable;
1160cdf0e10cSrcweir 				break;
1161cdf0e10cSrcweir 			}
1162cdf0e10cSrcweir 			Reference < XActiveDataSource > source( rTry , UNO_QUERY );
1163cdf0e10cSrcweir 			rTry = source;
1164cdf0e10cSrcweir 		}
1165cdf0e10cSrcweir 		m_bValidMarkable = sal_True;
1166cdf0e10cSrcweir 	}
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 
createMark(void)1170cdf0e10cSrcweir sal_Int32 OObjectOutputStream::createMark(void)
1171cdf0e10cSrcweir 	throw (IOException, RuntimeException)
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir 	connectToMarkable();	// throws an exception, if a markable is not connected !
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir 	return m_rMarkable->createMark();
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir 
deleteMark(sal_Int32 Mark)1178cdf0e10cSrcweir void OObjectOutputStream::deleteMark(sal_Int32 Mark)
1179cdf0e10cSrcweir 	throw (IOException, IllegalArgumentException, RuntimeException)
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1182cdf0e10cSrcweir 	{
1183cdf0e10cSrcweir 		throw NotConnectedException();
1184cdf0e10cSrcweir 	}
1185cdf0e10cSrcweir 	m_rMarkable->deleteMark( Mark );
1186cdf0e10cSrcweir }
1187cdf0e10cSrcweir 
jumpToMark(sal_Int32 nMark)1188cdf0e10cSrcweir void OObjectOutputStream::jumpToMark(sal_Int32 nMark)
1189cdf0e10cSrcweir 	throw (IOException, IllegalArgumentException, RuntimeException)
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1192cdf0e10cSrcweir 	{
1193cdf0e10cSrcweir 		throw NotConnectedException();
1194cdf0e10cSrcweir 	}
1195cdf0e10cSrcweir 	m_rMarkable->jumpToMark( nMark );
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir 
jumpToFurthest(void)1199cdf0e10cSrcweir void OObjectOutputStream::jumpToFurthest(void)
1200cdf0e10cSrcweir 	throw (IOException, RuntimeException)
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir 	connectToMarkable();
1203cdf0e10cSrcweir 	m_rMarkable->jumpToFurthest();
1204cdf0e10cSrcweir }
1205cdf0e10cSrcweir 
offsetToMark(sal_Int32 nMark)1206cdf0e10cSrcweir sal_Int32 OObjectOutputStream::offsetToMark(sal_Int32 nMark)
1207cdf0e10cSrcweir 	throw (IOException, IllegalArgumentException, RuntimeException)
1208cdf0e10cSrcweir {
1209cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1210cdf0e10cSrcweir 	{
1211cdf0e10cSrcweir 		throw NotConnectedException();
1212cdf0e10cSrcweir 	}
1213cdf0e10cSrcweir 	return m_rMarkable->offsetToMark( nMark );
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir 
OObjectOutputStream_CreateInstance(const Reference<XComponentContext> &)1219cdf0e10cSrcweir Reference< XInterface > SAL_CALL OObjectOutputStream_CreateInstance( const Reference < XComponentContext > & )
1220cdf0e10cSrcweir 	throw(Exception)
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir 	OObjectOutputStream *p = new OObjectOutputStream;
1223cdf0e10cSrcweir 	return  Reference< XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) );
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir 
OObjectOutputStream_getImplementationName()1226cdf0e10cSrcweir OUString OObjectOutputStream_getImplementationName()
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.ObjectOutputStream" ) );
1229cdf0e10cSrcweir }
1230cdf0e10cSrcweir 
OObjectOutputStream_getSupportedServiceNames(void)1231cdf0e10cSrcweir Sequence<OUString> OObjectOutputStream_getSupportedServiceNames(void)
1232cdf0e10cSrcweir {
1233cdf0e10cSrcweir 	Sequence<OUString> aRet(1);
1234cdf0e10cSrcweir 	aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.ObjectOutputStream" ) );
1235cdf0e10cSrcweir 	return aRet;
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir 
getTypes(void)1238cdf0e10cSrcweir Sequence< Type > SAL_CALL OObjectOutputStream::getTypes(void) throw( RuntimeException )
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir 	static OTypeCollection *pCollection = 0;
1241cdf0e10cSrcweir 	if( ! pCollection )
1242cdf0e10cSrcweir 	{
1243cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
1244cdf0e10cSrcweir 		if( ! pCollection )
1245cdf0e10cSrcweir 		{
1246cdf0e10cSrcweir 			static OTypeCollection collection(
1247cdf0e10cSrcweir 				getCppuType( (Reference< XMarkableStream > * ) 0 ),
1248cdf0e10cSrcweir 				getCppuType( (Reference< XObjectOutputStream > * ) 0 ),
1249cdf0e10cSrcweir 				ODataOutputStream::getTypes() );
1250cdf0e10cSrcweir 			pCollection = &collection;
1251cdf0e10cSrcweir 		}
1252cdf0e10cSrcweir 	}
1253cdf0e10cSrcweir 	return (*pCollection).getTypes();
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir 
getImplementationId()1256cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OObjectOutputStream::getImplementationId(  ) throw( RuntimeException)
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir 	static OImplementationId *pId = 0;
1259cdf0e10cSrcweir 	if( ! pId )
1260cdf0e10cSrcweir 	{
1261cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
1262cdf0e10cSrcweir 		if( ! pId )
1263cdf0e10cSrcweir 		{
1264cdf0e10cSrcweir 			static OImplementationId id( sal_False );
1265cdf0e10cSrcweir 			pId = &id;
1266cdf0e10cSrcweir 		}
1267cdf0e10cSrcweir 	}
1268cdf0e10cSrcweir 	return (*pId).getImplementationId();
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir // XServiceInfo
getImplementationName()1273cdf0e10cSrcweir OUString OObjectOutputStream::getImplementationName() throw ()
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir     return ODataInputStream_getImplementationName();
1276cdf0e10cSrcweir }
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)1279cdf0e10cSrcweir sal_Bool OObjectOutputStream::supportsService(const OUString& ServiceName) throw ()
1280cdf0e10cSrcweir {
1281cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
1282cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1285cdf0e10cSrcweir         if( pArray[i] == ServiceName )
1286cdf0e10cSrcweir             return sal_True;
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir     return sal_False;
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir 
1291cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)1292cdf0e10cSrcweir Sequence< OUString > OObjectOutputStream::getSupportedServiceNames(void) throw ()
1293cdf0e10cSrcweir {
1294cdf0e10cSrcweir 	return OObjectOutputStream_getSupportedServiceNames();
1295cdf0e10cSrcweir }
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir class OObjectInputStream :
1302cdf0e10cSrcweir 	public ODataInputStream,
1303cdf0e10cSrcweir 	public XObjectInputStream,
1304cdf0e10cSrcweir 	public XMarkableStream
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir public:
OObjectInputStream(const Reference<XComponentContext> & r)1307cdf0e10cSrcweir 	OObjectInputStream( const Reference < XComponentContext > &r)
1308cdf0e10cSrcweir 		: m_rSMgr( r->getServiceManager() )
1309cdf0e10cSrcweir 		, m_rCxt( r )
1310cdf0e10cSrcweir 		, m_bValidMarkable(sal_False)
1311cdf0e10cSrcweir 		{
1312cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1313cdf0e10cSrcweir 		}
1314cdf0e10cSrcweir 	~OObjectInputStream();
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir public:
1317cdf0e10cSrcweir         Any             SAL_CALL queryInterface( const Type &type ) throw();
acquire()1318cdf0e10cSrcweir         void    SAL_CALL acquire() throw()                                       { ODataInputStream::acquire(); }
release()1319cdf0e10cSrcweir         void    SAL_CALL release() throw()                                       { ODataInputStream::release(); }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir public: // XInputStream
readBytes(Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)1322cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
1323cdf0e10cSrcweir 		throw (	NotConnectedException,
1324cdf0e10cSrcweir 				BufferSizeExceededException,
1325cdf0e10cSrcweir 				RuntimeException)
1326cdf0e10cSrcweir 		{ return ODataInputStream::readBytes( aData , nBytesToRead ); }
1327cdf0e10cSrcweir 
readSomeBytes(Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)1328cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
1329cdf0e10cSrcweir 		throw (	NotConnectedException,
1330cdf0e10cSrcweir 				BufferSizeExceededException,
1331cdf0e10cSrcweir 				RuntimeException)
1332cdf0e10cSrcweir 		{ return ODataInputStream::readSomeBytes( aData, nMaxBytesToRead ); }
1333cdf0e10cSrcweir 
skipBytes(sal_Int32 nBytesToSkip)1334cdf0e10cSrcweir     virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip)
1335cdf0e10cSrcweir 		throw (	NotConnectedException,
1336cdf0e10cSrcweir 				BufferSizeExceededException,
1337cdf0e10cSrcweir 				RuntimeException)
1338cdf0e10cSrcweir 		{ ODataInputStream::skipBytes( nBytesToSkip ); }
1339cdf0e10cSrcweir 
available(void)1340cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL available(void)
1341cdf0e10cSrcweir 		throw (	NotConnectedException,
1342cdf0e10cSrcweir 				RuntimeException)
1343cdf0e10cSrcweir 		{ return ODataInputStream::available(); }
1344cdf0e10cSrcweir 
closeInput(void)1345cdf0e10cSrcweir     virtual void SAL_CALL closeInput(void)
1346cdf0e10cSrcweir 		throw (	NotConnectedException,
1347cdf0e10cSrcweir 				RuntimeException)
1348cdf0e10cSrcweir 		{ ODataInputStream::closeInput(); }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir public: // XDataInputStream
readBoolean(void)1351cdf0e10cSrcweir     virtual sal_Int8 SAL_CALL readBoolean(void) throw (IOException, RuntimeException)
1352cdf0e10cSrcweir     			{ return ODataInputStream::readBoolean(); }
readByte(void)1353cdf0e10cSrcweir     virtual sal_Int8 SAL_CALL readByte(void) throw (IOException, RuntimeException)
1354cdf0e10cSrcweir     			{ return ODataInputStream::readByte(); }
readChar(void)1355cdf0e10cSrcweir     virtual sal_Unicode SAL_CALL readChar(void) throw (IOException, RuntimeException)
1356cdf0e10cSrcweir     			{ return ODataInputStream::readChar(); }
readShort(void)1357cdf0e10cSrcweir     virtual sal_Int16 SAL_CALL readShort(void) throw (IOException, RuntimeException)
1358cdf0e10cSrcweir     			{ return ODataInputStream::readShort(); }
readLong(void)1359cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readLong(void) throw (IOException, RuntimeException)
1360cdf0e10cSrcweir     			{ return ODataInputStream::readLong(); }
readHyper(void)1361cdf0e10cSrcweir     virtual sal_Int64 SAL_CALL readHyper(void) throw (IOException, RuntimeException)
1362cdf0e10cSrcweir     			{ return ODataInputStream::readHyper(); }
readFloat(void)1363cdf0e10cSrcweir     virtual float SAL_CALL readFloat(void) throw (IOException, RuntimeException)
1364cdf0e10cSrcweir     			{ return ODataInputStream::readFloat(); }
readDouble(void)1365cdf0e10cSrcweir     virtual double SAL_CALL readDouble(void) throw (IOException, RuntimeException)
1366cdf0e10cSrcweir 		{ return ODataInputStream::readDouble(); }
readUTF(void)1367cdf0e10cSrcweir     virtual OUString SAL_CALL readUTF(void) throw (IOException, RuntimeException)
1368cdf0e10cSrcweir     			{ return ODataInputStream::readUTF(); }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir public: // XObjectInputStream
1371cdf0e10cSrcweir         virtual Reference< XPersistObject > SAL_CALL readObject( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir public: // XMarkableStream
1374cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL createMark(void)
1375cdf0e10cSrcweir 		throw (IOException, RuntimeException);
1376cdf0e10cSrcweir 	virtual void SAL_CALL deleteMark(sal_Int32 Mark)			throw (IOException, IllegalArgumentException, RuntimeException);
1377cdf0e10cSrcweir 	virtual void SAL_CALL jumpToMark(sal_Int32 nMark) 		throw (IOException, IllegalArgumentException, RuntimeException);
1378cdf0e10cSrcweir 	virtual void SAL_CALL jumpToFurthest(void) 			throw (IOException, RuntimeException);
1379cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL offsetToMark(sal_Int32 nMark)
1380cdf0e10cSrcweir 		throw (IOException, IllegalArgumentException, RuntimeException);
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir public: //XTypeProvider
1383cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL
1384cdf0e10cSrcweir 	        getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
1385cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
1386cdf0e10cSrcweir             getImplementationId(  ) throw(::com::sun::star::uno::RuntimeException);
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir public: // XServiceInfo
1389cdf0e10cSrcweir     OUString                     SAL_CALL getImplementationName() throw ();
1390cdf0e10cSrcweir 	Sequence< OUString >         SAL_CALL getSupportedServiceNames(void) throw ();
1391cdf0e10cSrcweir     sal_Bool                     SAL_CALL supportsService(const OUString& ServiceName) throw ();
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir private:
1394cdf0e10cSrcweir 	void connectToMarkable();
1395cdf0e10cSrcweir private:
1396cdf0e10cSrcweir 	Reference < XMultiComponentFactory > m_rSMgr;
1397cdf0e10cSrcweir 	Reference < XComponentContext >     m_rCxt;
1398cdf0e10cSrcweir 	sal_Bool 				m_bValidMarkable;
1399cdf0e10cSrcweir 	Reference < XMarkableStream > m_rMarkable;
1400cdf0e10cSrcweir 	vector < Reference<  XPersistObject > > m_aPersistVector;
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir };
1403cdf0e10cSrcweir 
~OObjectInputStream()1404cdf0e10cSrcweir OObjectInputStream::~OObjectInputStream()
1405cdf0e10cSrcweir {
1406cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1407cdf0e10cSrcweir }
1408cdf0e10cSrcweir 
queryInterface(const Type & aType)1409cdf0e10cSrcweir Any OObjectInputStream::queryInterface( const Type &aType ) throw ()
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
1412cdf0e10cSrcweir 		aType ,
1413cdf0e10cSrcweir 		SAL_STATIC_CAST( XMarkableStream * , this ),
1414cdf0e10cSrcweir 		SAL_STATIC_CAST( XObjectInputStream * , this ) );
1415cdf0e10cSrcweir 	if( a.hasValue() )
1416cdf0e10cSrcweir 	{
1417cdf0e10cSrcweir 		return a;
1418cdf0e10cSrcweir 	}
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir 	return ODataInputStream::queryInterface( aType );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir }
1423cdf0e10cSrcweir 
readObject()1424cdf0e10cSrcweir Reference< XPersistObject >  OObjectInputStream::readObject() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1425cdf0e10cSrcweir {
1426cdf0e10cSrcweir 	// check if chain contains a XMarkableStream
1427cdf0e10cSrcweir 	connectToMarkable();
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 	Reference< XPersistObject > xLoadedObj;
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir 	// create Mark to skip newer versions
1432cdf0e10cSrcweir 	sal_uInt32 nMark = m_rMarkable->createMark();
1433cdf0e10cSrcweir 	// length of the data
1434cdf0e10cSrcweir 	sal_Int32 nLen = (sal_uInt16) ODataInputStream::readShort();
1435cdf0e10cSrcweir 	if( nLen < 0xc )
1436cdf0e10cSrcweir 	{
1437cdf0e10cSrcweir 		throw WrongFormatException();
1438cdf0e10cSrcweir 	}
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 	// read the object identifier
1441cdf0e10cSrcweir 	sal_uInt32 nId = readLong();
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 	// the name of the persist model
1444cdf0e10cSrcweir 	// MM ???
1445cdf0e10cSrcweir 	OUString aName = readUTF();
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 	// Read the length of the object
1448cdf0e10cSrcweir 	sal_Int32 nObjLen = readLong();
1449cdf0e10cSrcweir 	if( ( 0 == nId && 0 != nObjLen ) )
1450cdf0e10cSrcweir 	{
1451cdf0e10cSrcweir 		throw WrongFormatException();
1452cdf0e10cSrcweir 	}
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir 	// skip data of new version
1455cdf0e10cSrcweir 	skipBytes( nLen - m_rMarkable->offsetToMark( nMark ) );
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 	sal_Bool bLoadSuccesfull = sal_True;
1458cdf0e10cSrcweir 	if( nId )
1459cdf0e10cSrcweir 	{
1460cdf0e10cSrcweir 		if( aName.getLength() )
1461cdf0e10cSrcweir 		{
1462cdf0e10cSrcweir 			// load the object
1463cdf0e10cSrcweir 			Reference< XInterface > x = m_rSMgr->createInstanceWithContext( aName, m_rCxt );
1464cdf0e10cSrcweir 			xLoadedObj = Reference< XPersistObject >( x, UNO_QUERY );
1465cdf0e10cSrcweir 			if( xLoadedObj.is() )
1466cdf0e10cSrcweir 			{
1467cdf0e10cSrcweir 				sal_uInt32 nSize = m_aPersistVector.size();
1468cdf0e10cSrcweir 				if( nSize <= nId )
1469cdf0e10cSrcweir 				{
1470cdf0e10cSrcweir 					// grow to the right size
1471cdf0e10cSrcweir 					Reference< XPersistObject > xEmpty;
1472cdf0e10cSrcweir 					m_aPersistVector.insert( m_aPersistVector.end(), (long)(nId - nSize + 1), xEmpty );
1473cdf0e10cSrcweir 				}
1474cdf0e10cSrcweir 
1475cdf0e10cSrcweir 				m_aPersistVector[nId] = xLoadedObj;
1476cdf0e10cSrcweir 				xLoadedObj->read( Reference< XObjectInputStream >(
1477cdf0e10cSrcweir 					SAL_STATIC_CAST( XObjectInputStream *, this ) ) );
1478cdf0e10cSrcweir 			}
1479cdf0e10cSrcweir 			else
1480cdf0e10cSrcweir 			{
1481cdf0e10cSrcweir 				// no service with this name could be instantiated
1482cdf0e10cSrcweir 				bLoadSuccesfull = sal_False;
1483cdf0e10cSrcweir 			}
1484cdf0e10cSrcweir 		}
1485cdf0e10cSrcweir 		else {
1486cdf0e10cSrcweir 			if( m_aPersistVector.size() < nId )
1487cdf0e10cSrcweir 			{
1488cdf0e10cSrcweir 				// id unknown, load failure !
1489cdf0e10cSrcweir 				bLoadSuccesfull = sal_False;
1490cdf0e10cSrcweir 			}
1491cdf0e10cSrcweir 			else
1492cdf0e10cSrcweir 			{
1493cdf0e10cSrcweir 				// Object has alread been read,
1494cdf0e10cSrcweir 				xLoadedObj = m_aPersistVector[nId];
1495cdf0e10cSrcweir 			}
1496cdf0e10cSrcweir 		}
1497cdf0e10cSrcweir 	}
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 	// skip to the position behind the object
1500cdf0e10cSrcweir 	skipBytes( nObjLen + nLen - m_rMarkable->offsetToMark( nMark ) );
1501cdf0e10cSrcweir 	m_rMarkable->deleteMark( nMark );
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir 	if( ! bLoadSuccesfull )
1504cdf0e10cSrcweir 	{
1505cdf0e10cSrcweir 		throw WrongFormatException();
1506cdf0e10cSrcweir 	}
1507cdf0e10cSrcweir 	return xLoadedObj;
1508cdf0e10cSrcweir }
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir 
connectToMarkable()1511cdf0e10cSrcweir void OObjectInputStream::connectToMarkable()
1512cdf0e10cSrcweir {
1513cdf0e10cSrcweir 	if( ! m_bValidMarkable ) {
1514cdf0e10cSrcweir 		if( ! m_bValidStream )
1515cdf0e10cSrcweir 		{
1516cdf0e10cSrcweir 			throw NotConnectedException( );
1517cdf0e10cSrcweir 		}
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir 		// find the markable stream !
1520cdf0e10cSrcweir 		Reference< XInterface > rTry(m_input);
1521cdf0e10cSrcweir 		while( sal_True ) {
1522cdf0e10cSrcweir 			if( ! rTry.is() )
1523cdf0e10cSrcweir 			{
1524cdf0e10cSrcweir 				throw NotConnectedException( );
1525cdf0e10cSrcweir 			}
1526cdf0e10cSrcweir 			Reference<  XMarkableStream > markable( rTry , UNO_QUERY );
1527cdf0e10cSrcweir 			if( markable.is() )
1528cdf0e10cSrcweir 			{
1529cdf0e10cSrcweir 				m_rMarkable = markable;
1530cdf0e10cSrcweir 				break;
1531cdf0e10cSrcweir 			}
1532cdf0e10cSrcweir 			Reference < XActiveDataSink > sink( rTry , UNO_QUERY );
1533cdf0e10cSrcweir 			rTry = sink;
1534cdf0e10cSrcweir 		}
1535cdf0e10cSrcweir 		m_bValidMarkable = sal_True;
1536cdf0e10cSrcweir 	}
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir 
createMark(void)1539cdf0e10cSrcweir sal_Int32 OObjectInputStream::createMark(void) 				throw (IOException, RuntimeException)
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir 	connectToMarkable();	// throws an exception, if a markable is not connected !
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir 	return m_rMarkable->createMark();
1544cdf0e10cSrcweir }
1545cdf0e10cSrcweir 
deleteMark(sal_Int32 Mark)1546cdf0e10cSrcweir void OObjectInputStream::deleteMark(sal_Int32 Mark)			throw (IOException, IllegalArgumentException, RuntimeException)
1547cdf0e10cSrcweir {
1548cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1549cdf0e10cSrcweir 	{
1550cdf0e10cSrcweir 		throw NotConnectedException();
1551cdf0e10cSrcweir 	}
1552cdf0e10cSrcweir 	m_rMarkable->deleteMark( Mark );
1553cdf0e10cSrcweir }
1554cdf0e10cSrcweir 
jumpToMark(sal_Int32 nMark)1555cdf0e10cSrcweir void OObjectInputStream::jumpToMark(sal_Int32 nMark) 		throw (IOException, IllegalArgumentException, RuntimeException)
1556cdf0e10cSrcweir {
1557cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1558cdf0e10cSrcweir 	{
1559cdf0e10cSrcweir 		throw NotConnectedException();
1560cdf0e10cSrcweir 	}
1561cdf0e10cSrcweir 	m_rMarkable->jumpToMark( nMark );
1562cdf0e10cSrcweir }
jumpToFurthest(void)1563cdf0e10cSrcweir void OObjectInputStream::jumpToFurthest(void) 			throw (IOException, RuntimeException)
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir 	connectToMarkable();
1566cdf0e10cSrcweir 	m_rMarkable->jumpToFurthest();
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir 
offsetToMark(sal_Int32 nMark)1569cdf0e10cSrcweir sal_Int32 OObjectInputStream::offsetToMark(sal_Int32 nMark)
1570cdf0e10cSrcweir 	throw (IOException, IllegalArgumentException, RuntimeException)
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir 	if( ! m_bValidMarkable )
1573cdf0e10cSrcweir 	{
1574cdf0e10cSrcweir 		throw NotConnectedException();
1575cdf0e10cSrcweir 	}
1576cdf0e10cSrcweir 	return m_rMarkable->offsetToMark( nMark );
1577cdf0e10cSrcweir }
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 
getTypes(void)1580cdf0e10cSrcweir Sequence< Type > SAL_CALL OObjectInputStream::getTypes(void) throw( RuntimeException )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir 	static OTypeCollection *pCollection = 0;
1583cdf0e10cSrcweir 	if( ! pCollection )
1584cdf0e10cSrcweir 	{
1585cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
1586cdf0e10cSrcweir 		if( ! pCollection )
1587cdf0e10cSrcweir 		{
1588cdf0e10cSrcweir 			static OTypeCollection collection(
1589cdf0e10cSrcweir 				getCppuType( (Reference< XMarkableStream > * ) 0 ),
1590cdf0e10cSrcweir 				getCppuType( (Reference< XObjectInputStream > * ) 0 ),
1591cdf0e10cSrcweir 				ODataInputStream::getTypes() );
1592cdf0e10cSrcweir 			pCollection = &collection;
1593cdf0e10cSrcweir 		}
1594cdf0e10cSrcweir 	}
1595cdf0e10cSrcweir 	return (*pCollection).getTypes();
1596cdf0e10cSrcweir }
1597cdf0e10cSrcweir 
getImplementationId()1598cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OObjectInputStream::getImplementationId(  ) throw( RuntimeException)
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir 	static OImplementationId *pId = 0;
1601cdf0e10cSrcweir 	if( ! pId )
1602cdf0e10cSrcweir 	{
1603cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
1604cdf0e10cSrcweir 		if( ! pId )
1605cdf0e10cSrcweir 		{
1606cdf0e10cSrcweir 			static OImplementationId id( sal_False );
1607cdf0e10cSrcweir 			pId = &id;
1608cdf0e10cSrcweir 		}
1609cdf0e10cSrcweir 	}
1610cdf0e10cSrcweir 	return (*pId).getImplementationId();
1611cdf0e10cSrcweir }
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir // XServiceInfo
getImplementationName()1615cdf0e10cSrcweir OUString OObjectInputStream::getImplementationName() throw ()
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir     return OObjectInputStream_getImplementationName();
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)1621cdf0e10cSrcweir sal_Bool OObjectInputStream::supportsService(const OUString& ServiceName) throw ()
1622cdf0e10cSrcweir {
1623cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
1624cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1627cdf0e10cSrcweir         if( pArray[i] == ServiceName )
1628cdf0e10cSrcweir             return sal_True;
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir     return sal_False;
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)1634cdf0e10cSrcweir Sequence< OUString > OObjectInputStream::getSupportedServiceNames(void) throw ()
1635cdf0e10cSrcweir {
1636cdf0e10cSrcweir     return OObjectInputStream_getSupportedServiceNames();
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir 
OObjectInputStream_CreateInstance(const Reference<XComponentContext> & rCtx)1642cdf0e10cSrcweir Reference< XInterface > SAL_CALL OObjectInputStream_CreateInstance( const Reference < XComponentContext > & rCtx ) throw(Exception)
1643cdf0e10cSrcweir {
1644cdf0e10cSrcweir 	OObjectInputStream *p = new OObjectInputStream( rCtx );
1645cdf0e10cSrcweir 	return Reference< XInterface> ( SAL_STATIC_CAST( OWeakObject *, p ) );
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir 
OObjectInputStream_getImplementationName()1648cdf0e10cSrcweir OUString OObjectInputStream_getImplementationName()
1649cdf0e10cSrcweir {
1650cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.ObjectInputStream" ) );
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir 
OObjectInputStream_getSupportedServiceNames(void)1653cdf0e10cSrcweir Sequence<OUString> OObjectInputStream_getSupportedServiceNames(void)
1654cdf0e10cSrcweir {
1655cdf0e10cSrcweir 	Sequence<OUString> aRet(1);
1656cdf0e10cSrcweir 	aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.ObjectInputStream" ) );
1657cdf0e10cSrcweir 	return aRet;
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir }
1661