xref: /aoo41x/main/bean/com/sun/star/comp/beans/OOoBean.java (revision d4cc1e8c)
1*d4cc1e8cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d4cc1e8cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d4cc1e8cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d4cc1e8cSAndrew Rist  * distributed with this work for additional information
6*d4cc1e8cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d4cc1e8cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d4cc1e8cSAndrew Rist  * "License"); you may not use this file except in compliance
9*d4cc1e8cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d4cc1e8cSAndrew Rist  *
11*d4cc1e8cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d4cc1e8cSAndrew Rist  *
13*d4cc1e8cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d4cc1e8cSAndrew Rist  * software distributed under the License is distributed on an
15*d4cc1e8cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d4cc1e8cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d4cc1e8cSAndrew Rist  * specific language governing permissions and limitations
18*d4cc1e8cSAndrew Rist  * under the License.
19*d4cc1e8cSAndrew Rist  *
20*d4cc1e8cSAndrew Rist  *************************************************************/
21*d4cc1e8cSAndrew Rist 
22*d4cc1e8cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.beans;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // @requirement FUNC.PERF.LRN/0.6
29cdf0e10cSrcweir // @requirement FUNC.PERF.LOC/0.6
30cdf0e10cSrcweir // @requirement FUNC.PERF.FIX/0.6
31cdf0e10cSrcweir /** This is the basic JavaBean for all OOo application modules.
32cdf0e10cSrcweir 
33cdf0e10cSrcweir     @requirement FUNC.RES.OTH/0.2
34cdf0e10cSrcweir     	No other resources are needed yet.
35cdf0e10cSrcweir 
36cdf0e10cSrcweir     @since OOo 2.0.0
37cdf0e10cSrcweir  */
38cdf0e10cSrcweir public class OOoBean
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	// @requirement FUNC.BEAN.VIEW/0.4
41cdf0e10cSrcweir 	extends java.awt.Container
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 	implements
44cdf0e10cSrcweir 		// @requirement FUNC.PER/0.2
45cdf0e10cSrcweir 		java.io.Externalizable
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	// timeout values (milli secs)
48cdf0e10cSrcweir 	int nOOoStartTimeOut = 60000;
49cdf0e10cSrcweir 	int nOOoCallTimeOut =   3000;
50cdf0e10cSrcweir 	int nOOoCheckCycle =    1000;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	// This member contains the connection to an OOo instance if established.
53cdf0e10cSrcweir 	private transient OfficeConnection		iConnection;
54cdf0e10cSrcweir 	private transient EventListener			xConnectionListener;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	// @requirement FUNC.BEAN.VIEW/0.4
57cdf0e10cSrcweir 	// @requirement FUNC.BEAN.EDIT/0.4
58cdf0e10cSrcweir 	// This member contains the OOo window
59cdf0e10cSrcweir 	// if a connection is established.
60cdf0e10cSrcweir 	// It is a child of the OOoBean canvas.
61cdf0e10cSrcweir 	private OfficeWindow xFrameWindow;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	// application environment
64cdf0e10cSrcweir 	private transient com.sun.star.lang.XMultiServiceFactory xServiceFactory;
65cdf0e10cSrcweir 	private transient com.sun.star.frame.XDesktop xDesktop;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	// document and frame
68cdf0e10cSrcweir 	private transient Frame aFrame;
69cdf0e10cSrcweir 	private transient Controller aController;
70cdf0e10cSrcweir 	private transient OfficeDocument aDocument;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	// slot command execution environment
73cdf0e10cSrcweir 	private transient com.sun.star.frame.XDispatchProvider xDispatcher;
74cdf0e10cSrcweir 	private transient com.sun.star.util.XURLTransformer xURLTransformer;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	// properties
77cdf0e10cSrcweir 	private boolean bIgnoreVisibility = false; // to show even if already visible
78cdf0e10cSrcweir     private boolean bMenuBarVisible = true;
79cdf0e10cSrcweir     private boolean bStandardBarVisible = true;
80cdf0e10cSrcweir     private boolean bToolBarVisible = true;
81cdf0e10cSrcweir     private boolean bStatusBarVisible = true;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// debugging method
dbgPrint( String aMessage )85cdf0e10cSrcweir 	private void dbgPrint( String aMessage )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		// System.err.println( "OOoBean: " + aMessage );
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	// @requirement FUNC.PER/0.2
91cdf0e10cSrcweir 	/** @internal
92cdf0e10cSrcweir      *  @deprecated
93cdf0e10cSrcweir 	 */
writeExternal( java.io.ObjectOutput aObjOut )94cdf0e10cSrcweir 	public void writeExternal( java.io.ObjectOutput aObjOut )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		// TBD
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	// @requirement FUNC.PER/0.2
100cdf0e10cSrcweir 	/** @internal
101cdf0e10cSrcweir      *  @deprecated
102cdf0e10cSrcweir 	 */
readExternal( java.io.ObjectInput aObjIn )103cdf0e10cSrcweir 	public void readExternal( java.io.ObjectInput aObjIn )
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		// TBD
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	/** Generic constructor of the OOoBean.
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	    Neither a connection is established nor any document loaded.
111cdf0e10cSrcweir 	 */
OOoBean()112cdf0e10cSrcweir 	public OOoBean()
113cdf0e10cSrcweir 	{}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir    	// @requirement FUNC.CON.MULT/0.3
116cdf0e10cSrcweir 	/** Constructor for an OOoBean which uses a specific office connection.
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	    The connection must be established but no document is loaded.
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	    @throws NoConnectionException
121cdf0e10cSrcweir 	    	if the connection is not established.
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         @deprecated Clients could use the getOOoConnection to obtain an OfficeConnection
124cdf0e10cSrcweir         and use it as argument in a constructor for another OOoBean instance. Calling
125cdf0e10cSrcweir         the dispose method of the OfficeConnection or the OOoBean's stopOOoConnection
126cdf0e10cSrcweir         method would make all instances of OOoBean stop working.
127cdf0e10cSrcweir 	 */
OOoBean( OfficeConnection iConnection )128cdf0e10cSrcweir 	public OOoBean( OfficeConnection iConnection )
129cdf0e10cSrcweir 		throws NoConnectionException
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		try { setOOoConnection( iConnection ); }
132cdf0e10cSrcweir 		catch ( HasConnectionException aExc )
133cdf0e10cSrcweir 		{ /* impossible here */ }
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	/** Sets the timeout for methods which launch OOo in milli seconds.
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		This method does not need a connection to an OOo instance.
139cdf0e10cSrcweir 	 */
setOOoStartTimeOut( int nMilliSecs )140cdf0e10cSrcweir 	public void setOOoStartTimeOut( int nMilliSecs )
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir 		nOOoStartTimeOut = nMilliSecs;
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	/** Sets the timeout for normal OOO methods calls in milli seconds.
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 		This method does not need a connection to an OOo instance.
148cdf0e10cSrcweir 	 */
setOOoCallTimeOut( int nMilliSecs )149cdf0e10cSrcweir 	public void setOOoCallTimeOut( int nMilliSecs )
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		nOOoCallTimeOut = nMilliSecs;
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	/** Sets the period length in milli seconds to check the OOo connection.
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		This method does not need a connection to an OOo instance.
157cdf0e10cSrcweir 	 */
setOOoCheckCycle( int nMilliSecs )158cdf0e10cSrcweir 	public void setOOoCheckCycle( int nMilliSecs )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		nOOoCheckCycle = nMilliSecs;
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	/** Sets the a connection to an OOo instance.
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	    @internal
166cdf0e10cSrcweir 	 */
setOOoConnection( OfficeConnection iNewConnection )167cdf0e10cSrcweir 	private synchronized void setOOoConnection( OfficeConnection iNewConnection )
168cdf0e10cSrcweir 		throws	HasConnectionException, NoConnectionException
169cdf0e10cSrcweir 	{
170cdf0e10cSrcweir 		// the connection cannot be exchanged
171cdf0e10cSrcweir 		if ( iConnection != null )
172cdf0e10cSrcweir 			throw new HasConnectionException();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 		// is there a real connection, not just the proxy?
175cdf0e10cSrcweir 		com.sun.star.uno.XComponentContext xComponentContext = null;
176cdf0e10cSrcweir 		try { xComponentContext = iNewConnection.getComponentContext(); }
177cdf0e10cSrcweir 		catch ( java.lang.Throwable aExc )
178cdf0e10cSrcweir 		{ throw new NoConnectionException(); }
179cdf0e10cSrcweir 		if ( xComponentContext == null )
180cdf0e10cSrcweir 			throw new NoConnectionException();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		// set the connection
183cdf0e10cSrcweir 		iConnection = iNewConnection;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		// get notified when connection dies
186cdf0e10cSrcweir 		if ( xConnectionListener != null )
187cdf0e10cSrcweir 			xConnectionListener.end();
188cdf0e10cSrcweir 		xConnectionListener = this.new EventListener("setOOoConnection");
189cdf0e10cSrcweir 	}
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	// @requirement FUNC.CON.STRT/0.4
192cdf0e10cSrcweir 	/** Starts a connection to an OOo instance which is lauched if not running.
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		@throws HasConnectionException
195cdf0e10cSrcweir 			if a connection was already established.
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		@throws NoConnectionException
198cdf0e10cSrcweir 			if the specified connection cannot be established
199cdf0e10cSrcweir 	 */
startOOoConnection( String aConnectionURL )200cdf0e10cSrcweir 	public void startOOoConnection( String aConnectionURL )
201cdf0e10cSrcweir 		throws	java.net.MalformedURLException,
202cdf0e10cSrcweir 			HasConnectionException,
203cdf0e10cSrcweir 			NoConnectionException
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		// create a new connection from the given connection URL
206cdf0e10cSrcweir 		LocalOfficeConnection aConnection = new LocalOfficeConnection();
207cdf0e10cSrcweir 		aConnection.setUnoUrl( aConnectionURL );
208cdf0e10cSrcweir 		setOOoConnection( aConnection );
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	// @requirement FUNC.CON.CHK/0.7
212cdf0e10cSrcweir 	/** Returns true if this OOoBean is connected to an OOo instance,
213cdf0e10cSrcweir 	    false otherwise.
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         @deprecated This method is not useful in a multithreaded environment. Then
216cdf0e10cSrcweir         all threads accessing the instance would have to be synchronized in order to
217cdf0e10cSrcweir         make is method work. It is better
218cdf0e10cSrcweir         to call OOoBean's methods and be prepared to catch a NoConnectionException.
219cdf0e10cSrcweir 	 */
isOOoConnected()220cdf0e10cSrcweir 	public boolean isOOoConnected()
221cdf0e10cSrcweir 	{
222cdf0e10cSrcweir 		return iConnection != null;
223cdf0e10cSrcweir 	}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	// @requirement FUNC.CON.STOP/0.4
226cdf0e10cSrcweir 	/** Disconnects from the connected OOo instance.
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 		If there was no connection yet or anymore, this method can be called
229cdf0e10cSrcweir 		anyway.
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         When the OOoBean is displayed in an applet by a web browser, then this
232cdf0e10cSrcweir         method must be called from within java.applet.Applet.stop.
233cdf0e10cSrcweir 	 */
stopOOoConnection()234cdf0e10cSrcweir 	public synchronized void stopOOoConnection()
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir 		// clear OOo document, frame etc.
237cdf0e10cSrcweir 		clear();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		// cut the connection
240cdf0e10cSrcweir 		OfficeConnection iExConnection = iConnection;
241cdf0e10cSrcweir 		if ( iConnection != null )
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			if ( xConnectionListener != null )
244cdf0e10cSrcweir 			{
245cdf0e10cSrcweir 				xConnectionListener.end();
246cdf0e10cSrcweir 			}
247cdf0e10cSrcweir 			iConnection = null;
248cdf0e10cSrcweir 			iExConnection.dispose();
249cdf0e10cSrcweir 		}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	}
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	// @requirement FUNC.CON.STOP/0.4 (via XComponent.dispose())
254cdf0e10cSrcweir    	// @requirement FUNC.CON.NTFY/0.4 (via XComponent.addEventListener())
255cdf0e10cSrcweir 	/** Returns the a connection to an OOo instance.
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	    If no connection exists, a default connection will be created. An OfficeConnection
258cdf0e10cSrcweir         can be used to register listeners of type com.sun.star.lang.EventListener,
259cdf0e10cSrcweir         which are notified when the connection to the
260cdf0e10cSrcweir         office dies. One should not call the dispose method, because this may result
261cdf0e10cSrcweir         in receiving com.sun.star.lang.DisposedExceptions when calling
262cdf0e10cSrcweir         {@link #stopOOoConnection stopOOoConnection} or other API methods. If other instances share the
263cdf0e10cSrcweir         same connection then they will stop function properly, because they loose their
264cdf0e10cSrcweir         connection as well. The recommended way to end the connection is
265cdf0e10cSrcweir         calling {@link #stopOOoConnection stopOOoConnection}.
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		@throws NoConnectionException
268cdf0e10cSrcweir 			if no connection can be established
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	 */
getOOoConnection()271cdf0e10cSrcweir 	public synchronized OfficeConnection getOOoConnection()
272cdf0e10cSrcweir 		throws NoConnectionException
273cdf0e10cSrcweir 	{
274cdf0e10cSrcweir 		if ( iConnection == null )
275cdf0e10cSrcweir 		{
276cdf0e10cSrcweir 			try { setOOoConnection( new LocalOfficeConnection() ); }
277cdf0e10cSrcweir 			catch ( HasConnectionException aExc )
278cdf0e10cSrcweir 			{ /* impossible here */ }
279cdf0e10cSrcweir 		}
280cdf0e10cSrcweir 		if ( iConnection.getComponentContext() == null )
281cdf0e10cSrcweir 			throw new NoConnectionException();
282cdf0e10cSrcweir 		return iConnection;
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	/**	Returns the service factory used by this OOoBean instance.
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 		@throws NoConnectionException
288cdf0e10cSrcweir 			if no connection is established and no default connection can be established.
289cdf0e10cSrcweir 	 */
getMultiServiceFactory()290cdf0e10cSrcweir 	public synchronized com.sun.star.lang.XMultiServiceFactory getMultiServiceFactory()
291cdf0e10cSrcweir 		throws NoConnectionException
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir 		if ( xServiceFactory == null )
294cdf0e10cSrcweir 		{
295cdf0e10cSrcweir 			// avoid concurrent access from multiple threads
296cdf0e10cSrcweir 			final OfficeConnection iConn = getOOoConnection();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 			Thread aConnectorThread = new Thread() {
299cdf0e10cSrcweir 				public void run()
300cdf0e10cSrcweir 				{
301cdf0e10cSrcweir 					com.sun.star.lang.XMultiComponentFactory aFactory =
302cdf0e10cSrcweir 						iConn.getComponentContext().getServiceManager();
303cdf0e10cSrcweir 					xServiceFactory	= (com.sun.star.lang.XMultiServiceFactory)
304cdf0e10cSrcweir 						UnoRuntime.queryInterface(
305cdf0e10cSrcweir 							com.sun.star.lang.XMultiServiceFactory.class, aFactory );
306cdf0e10cSrcweir 				}
307cdf0e10cSrcweir 			};
308cdf0e10cSrcweir 			aConnectorThread.start();
309cdf0e10cSrcweir 			try { aConnectorThread.join(nOOoStartTimeOut); }
310cdf0e10cSrcweir 			catch ( java.lang.InterruptedException aExc )
311cdf0e10cSrcweir 			{ throw new NoConnectionException(); }
312cdf0e10cSrcweir 			if ( xServiceFactory == null )
313cdf0e10cSrcweir 				throw new NoConnectionException();
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		return xServiceFactory;
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	/** Returns the XDesktop interface of the OOo instance used by this OOoBean.
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 		@throws NoConnectionException
322cdf0e10cSrcweir 			if no connection is established and no default connection can be established.
323cdf0e10cSrcweir 	 */
getOOoDesktop()324cdf0e10cSrcweir 	public synchronized com.sun.star.frame.XDesktop getOOoDesktop()
325cdf0e10cSrcweir 		throws NoConnectionException
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		if ( xDesktop == null )
328cdf0e10cSrcweir 		{
329cdf0e10cSrcweir 			try
330cdf0e10cSrcweir 			{
331cdf0e10cSrcweir 				Object aObject = getMultiServiceFactory().createInstance( "com.sun.star.frame.Desktop");
332cdf0e10cSrcweir 				xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface(
333cdf0e10cSrcweir 						com.sun.star.frame.XDesktop.class, aObject );
334cdf0e10cSrcweir 			}
335cdf0e10cSrcweir 			catch ( com.sun.star.uno.Exception aExc )
336cdf0e10cSrcweir 			{} // TBD: what if no connection exists?
337cdf0e10cSrcweir 		}
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 		return xDesktop;
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	/** Resets this bean to an empty document.
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 	   If a document is loaded and the content modified,
345cdf0e10cSrcweir 	   the changes are dismissed.  Otherwise nothing happens.
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 	   This method is intended to be overridden in derived classes.
348cdf0e10cSrcweir        This implementation simply calls clear.
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	   @param bClearStateToo
351cdf0e10cSrcweir 	   	Not only the document content but also the state of the bean,
352cdf0e10cSrcweir 		like visibility of child components is cleared.
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         @deprecated There is currently no way to dismiss changes, except for loading
355cdf0e10cSrcweir         of the unchanged initial document. Furthermore it is unclear how derived classes
356cdf0e10cSrcweir         handle this and what exactly their state is (e.g. what members make up their state).
357cdf0e10cSrcweir         Calling this method on a derived class requires knowledge about their implementation.
358cdf0e10cSrcweir         Therefore a deriving class should declare their own clearDocument if needed. Clients
359cdf0e10cSrcweir         should call the clearDocument of the deriving class or {@link #clear} which discards
360cdf0e10cSrcweir         the currently displayed document.
361cdf0e10cSrcweir 	 */
clearDocument( boolean bClearStateToo )362cdf0e10cSrcweir 	public synchronized void clearDocument( boolean bClearStateToo )
363cdf0e10cSrcweir 		throws
364cdf0e10cSrcweir 			com.sun.star.util.CloseVetoException,
365cdf0e10cSrcweir 			NoConnectionException
366cdf0e10cSrcweir 	{
367cdf0e10cSrcweir 		// TBD
368cdf0e10cSrcweir         clear();
369cdf0e10cSrcweir 	}
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	/** Resets the OOoBean to an empty status.
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	    Any loaded document is unloaded, no matter whether it is modified or not.
374cdf0e10cSrcweir 	    After calling this method, the OOoBean has no office document and no frame
375cdf0e10cSrcweir 	    anymore.  The connection will stay, though.
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 		This method works with or without an established connection.
378cdf0e10cSrcweir 	 */
clear()379cdf0e10cSrcweir 	public synchronized void clear()
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir 		dbgPrint( "clear()" );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 		try
384cdf0e10cSrcweir 		{
385cdf0e10cSrcweir 			CallWatchThread aCallWatchThread =
386cdf0e10cSrcweir 				new CallWatchThread( nOOoCallTimeOut, "clear" );
387cdf0e10cSrcweir             //By closing the frame we avoid that dialogs are displayed, for example when
388cdf0e10cSrcweir             //the document is modified.
389cdf0e10cSrcweir         	com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
390cdf0e10cSrcweir     			UnoRuntime.queryInterface( com.sun.star.util.XCloseable.class, aFrame );
391cdf0e10cSrcweir         	if ( xCloseable != null )
392cdf0e10cSrcweir             {
393cdf0e10cSrcweir                 try
394cdf0e10cSrcweir                 {
395cdf0e10cSrcweir                     xCloseable.close(true);
396cdf0e10cSrcweir                 }
397cdf0e10cSrcweir                 catch (com.sun.star.util.CloseVetoException exc)
398cdf0e10cSrcweir                 { // a print job may be running
399cdf0e10cSrcweir                 }
400cdf0e10cSrcweir             }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 			aDocument = null;
403cdf0e10cSrcweir 			xDispatcher = null;
404cdf0e10cSrcweir 			aFrame = null;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 			// clear xFrameWindow
407cdf0e10cSrcweir 			if ( xFrameWindow != null )
408cdf0e10cSrcweir 			{
409cdf0e10cSrcweir 				try { releaseSystemWindow(); }
410cdf0e10cSrcweir 				catch ( NoConnectionException aExc )
411cdf0e10cSrcweir 				{} // ignore
412cdf0e10cSrcweir 				catch ( SystemWindowException aExc )
413cdf0e10cSrcweir 				{} // ignore
414cdf0e10cSrcweir 				remove( xFrameWindow.getAWTComponent() );
415cdf0e10cSrcweir 				xFrameWindow = null;
416cdf0e10cSrcweir 			}
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 			// clear xURTTransformer
419cdf0e10cSrcweir 			if ( xURLTransformer != null )
420cdf0e10cSrcweir 			{
421cdf0e10cSrcweir 				try
422cdf0e10cSrcweir 				{
423cdf0e10cSrcweir 					com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent)
424cdf0e10cSrcweir 						UnoRuntime.queryInterface(
425cdf0e10cSrcweir 							com.sun.star.lang.XComponent.class, xURLTransformer );
426cdf0e10cSrcweir 					if ( xComp != null )
427cdf0e10cSrcweir 						xComp.dispose();
428cdf0e10cSrcweir 				}
429cdf0e10cSrcweir 				catch ( java.lang.Throwable aExc )
430cdf0e10cSrcweir 				{} // ignore
431cdf0e10cSrcweir 				xURLTransformer = null;
432cdf0e10cSrcweir 			}
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 			xDesktop = null;
435cdf0e10cSrcweir 			xServiceFactory = null;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 			aCallWatchThread.cancel();
438cdf0e10cSrcweir 		}
439cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
440cdf0e10cSrcweir 		{ /* can be ignored */ }
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	// @requirement FUNC.PAR.LWP/0.4
444cdf0e10cSrcweir 	/** This method causes the office window to be displayed.
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	    If no document is loaded and the instance is added to a Java container that
447cdf0e10cSrcweir         is showing, then this method needs not to be called. If later one of the methods
448cdf0e10cSrcweir         {@link #loadFromURL loadFromURL}, {@link #loadFromStream loadFromStream1},
449cdf0e10cSrcweir         or {@link #loadFromByteArray loadFromByteArray}
450cdf0e10cSrcweir         is called, then the document is automatically displayed.
451cdf0e10cSrcweir 
452cdf0e10cSrcweir         Should one of the load methods have been called before the Java container
453cdf0e10cSrcweir         was showing, then this method needs to be called after the container window
454cdf0e10cSrcweir         was made visible (java.lang.Component.setVisible(true)).
455cdf0e10cSrcweir         <p>
456cdf0e10cSrcweir         Another scenario is that a OOoBean contains a document and is removed
457cdf0e10cSrcweir         from a Java container and later added again. Then aquireSystemWindow needs
458cdf0e10cSrcweir         to be called after the container window is displayed.
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	    @throws SystemWindowException
461cdf0e10cSrcweir 	    	if no system window can be aquired.
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	    @throws NoConnectionException
464cdf0e10cSrcweir 	    	if the connection is not established.
465cdf0e10cSrcweir 	 */
aquireSystemWindow()466cdf0e10cSrcweir 	public synchronized void aquireSystemWindow()
467cdf0e10cSrcweir 		throws
468cdf0e10cSrcweir 			SystemWindowException,
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
471cdf0e10cSrcweir 			NoConnectionException
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		if ( iConnection == null )
474cdf0e10cSrcweir 			throw new NoConnectionException();
475cdf0e10cSrcweir 		if ( !isShowing() )
476cdf0e10cSrcweir 			throw new SystemWindowException();
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 		if ( xFrameWindow != null )
479cdf0e10cSrcweir 			xFrameWindow.getAWTComponent().setVisible(true);
480cdf0e10cSrcweir 		doLayout();
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	// @requirement FUNC.PAR.RWL/0.4
484cdf0e10cSrcweir 	// @estimation 16h
485cdf0e10cSrcweir 	/** This method must be called when the OOoBean before the
486cdf0e10cSrcweir 	    sytem window may be released by it's parent AWT/Swing component.
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	    This is the case when java.awt.Component.isDisplayable() returns
489cdf0e10cSrcweir 	    true.  This is definitely the case when the OOoBean is removed
490cdf0e10cSrcweir 	    from it's parent container.
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	    @throws SystemWindowException
493cdf0e10cSrcweir 	    	if system window is not aquired.
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	    @throws NoConnectionException
496cdf0e10cSrcweir 	    	if the connection is not established.
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         @deprecated When Component.removeNotify of the parent window of the actual
499cdf0e10cSrcweir         office window is called, then the actions are performed for which this method
500cdf0e10cSrcweir         needed to be called previously.
501cdf0e10cSrcweir 	 */
releaseSystemWindow()502cdf0e10cSrcweir 	public synchronized void releaseSystemWindow()
503cdf0e10cSrcweir 		throws
504cdf0e10cSrcweir 			SystemWindowException,
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
507cdf0e10cSrcweir 			NoConnectionException
508cdf0e10cSrcweir 	{
509cdf0e10cSrcweir 		if ( iConnection == null )
510cdf0e10cSrcweir 			throw new NoConnectionException();
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 		try { xFrameWindow.getAWTComponent().setVisible(false); }
513cdf0e10cSrcweir 		catch ( com.sun.star.lang.DisposedException aExc )
514cdf0e10cSrcweir 		{ throw new NoConnectionException(); }
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir 
517cdf0e10cSrcweir    	// @requirement FUNC.BEAN.LOAD/0.4
518cdf0e10cSrcweir    	// @requirement FUNC.CON.AUTO/0.3
519cdf0e10cSrcweir 	/** Loads the bean from the given URL.
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 	    If a document is already loaded and the content modified,
522cdf0e10cSrcweir 	    the changes are dismissed.
523cdf0e10cSrcweir 
524cdf0e10cSrcweir 	    If no connection exists, a default connection is established.
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	    @throws IllegalArgumentException
527cdf0e10cSrcweir 	    	if either of the arguments is out of the specified range.
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 	    @throws java.io.IOException
530cdf0e10cSrcweir 	    	if an IO error occurs reading the ressource specified by the URL.
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 	    @throws com.sun.star.lang.NoConnectionException
533cdf0e10cSrcweir 	    	if no connection can be established.
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         @throws com.sun.star.util.CloseVetoException
536cdf0e10cSrcweir             if the currently displayed document cannot be closed because it is
537cdf0e10cSrcweir             still be used, for example it is printed.
538cdf0e10cSrcweir 	 */
loadFromURL( final String aURL, final com.sun.star.beans.PropertyValue aArguments[] )539cdf0e10cSrcweir 	public void loadFromURL(
540cdf0e10cSrcweir 			final String aURL,
541cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
542cdf0e10cSrcweir 		throws
543cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
544cdf0e10cSrcweir 			NoConnectionException,
545cdf0e10cSrcweir 			java.io.IOException,
546cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException,
547cdf0e10cSrcweir             com.sun.star.util.CloseVetoException
548cdf0e10cSrcweir 	{
549cdf0e10cSrcweir 		dbgPrint( "loadFromURL()" );
550cdf0e10cSrcweir  		// try loading
551cdf0e10cSrcweir 		try
552cdf0e10cSrcweir 		{
553cdf0e10cSrcweir 			boolean bLoaded = false;
554cdf0e10cSrcweir 			while ( !bLoaded )
555cdf0e10cSrcweir 			{
556cdf0e10cSrcweir 				// watch loading in a thread with a timeout (if OOo hangs)
557cdf0e10cSrcweir 				CallWatchThread aCallWatchThread =
558cdf0e10cSrcweir 					new CallWatchThread( nOOoStartTimeOut, "loadFromURL" );
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 				try
561cdf0e10cSrcweir 				{
562cdf0e10cSrcweir 					// get window from OOo on demand
563cdf0e10cSrcweir 					if ( xFrameWindow == null )
564cdf0e10cSrcweir 					{
565cdf0e10cSrcweir 						// Establish the connection by request of the ServiceFactory.
566cdf0e10cSrcweir 						getMultiServiceFactory();
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 						// remove existing child windows
569cdf0e10cSrcweir 						removeAll();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 						// Create the OfficeWindow.
572cdf0e10cSrcweir 						xFrameWindow = getOOoConnection().createOfficeWindow(OOoBean.this);
573cdf0e10cSrcweir 						add( xFrameWindow.getAWTComponent() );
574cdf0e10cSrcweir 					}
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 					// create the document frame from UNO window.
577cdf0e10cSrcweir 					if ( aFrame == null )
578cdf0e10cSrcweir 					{
579cdf0e10cSrcweir 						// create the frame
580cdf0e10cSrcweir 						com.sun.star.awt.XWindow xWindow =
581cdf0e10cSrcweir 							(com.sun.star.awt.XWindow) UnoRuntime.queryInterface(
582cdf0e10cSrcweir 							com.sun.star.awt.XWindow.class, xFrameWindow.getUNOWindowPeer());
583cdf0e10cSrcweir 						Object xFrame = xServiceFactory.createInstance( "com.sun.star.frame.Frame");
584cdf0e10cSrcweir 						aFrame = new Frame( (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
585cdf0e10cSrcweir 								com.sun.star.frame.XFrame.class, xFrame ) );
586cdf0e10cSrcweir 						aFrame.initialize( xWindow );
587cdf0e10cSrcweir 						aFrame.setName( aFrame.toString() );
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 						// register the frame at the desktop
590cdf0e10cSrcweir 						com.sun.star.frame.XFrames xFrames =
591cdf0e10cSrcweir 								( (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface(
592cdf0e10cSrcweir 								com.sun.star.frame.XFramesSupplier.class, getOOoDesktop() ) ).getFrames();
593cdf0e10cSrcweir 						xFrames.append( aFrame );
594cdf0e10cSrcweir 					}
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 					// Initializes the slot command execution environment.
597cdf0e10cSrcweir 					xURLTransformer	= (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface(
598cdf0e10cSrcweir 						com.sun.star.util.XURLTransformer.class,
599cdf0e10cSrcweir 						xServiceFactory.createInstance( "com.sun.star.util.URLTransformer") );
600cdf0e10cSrcweir 
601cdf0e10cSrcweir                                         try
602cdf0e10cSrcweir                                         {
603cdf0e10cSrcweir                                             xDispatcher = UnoRuntime.queryInterface(com.sun.star.frame.XDispatchProvider.class, aFrame);
604cdf0e10cSrcweir                                         }
605cdf0e10cSrcweir                                         catch (Exception e)
606cdf0e10cSrcweir                                         {
607cdf0e10cSrcweir                                             /*ignore!*/
608cdf0e10cSrcweir                                         }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 					// get XComponentLoader from frame
611cdf0e10cSrcweir 					com.sun.star.frame.XComponentLoader xLoader = (com.sun.star.frame.XComponentLoader)
612cdf0e10cSrcweir 						UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class, aFrame );
613cdf0e10cSrcweir 					if ( xLoader == null )
614cdf0e10cSrcweir 					{
615cdf0e10cSrcweir 						throw new java.lang.RuntimeException(
616cdf0e10cSrcweir 							"com.sun.star.frame.Frame(" + aFrame +
617cdf0e10cSrcweir 								") without com.sun.star.frame.XComponentLoader" );
618cdf0e10cSrcweir 					}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 					// Avoid Dialog 'Document changed' while reloading
621cdf0e10cSrcweir 					if ( aDocument != null )
622cdf0e10cSrcweir 					{
623cdf0e10cSrcweir                         try {
624cdf0e10cSrcweir                             aDocument.setModified(false);
625cdf0e10cSrcweir                         } catch (com.sun.star.beans.PropertyVetoException ep) {
626cdf0e10cSrcweir                             //it dosn't make sense to throw the exception here. The interface does not
627cdf0e10cSrcweir                             //offer a way to add/remove respective listeners.
628cdf0e10cSrcweir                         } catch (com.sun.star.lang.DisposedException ed) {
629cdf0e10cSrcweir                             // can be disposed if user closed document via UI
630cdf0e10cSrcweir                         }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir                         com.sun.star.frame.XController xOldController = null;
633cdf0e10cSrcweir 						if ( aFrame != null )
634cdf0e10cSrcweir 							xOldController = aFrame.getController();
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 						try
637cdf0e10cSrcweir 						{
638cdf0e10cSrcweir 
639cdf0e10cSrcweir 							if ( aFrame != null && xOldController != null )
640cdf0e10cSrcweir 								if (xOldController.suspend(true) == false)
641cdf0e10cSrcweir                                     throw new com.sun.star.util.CloseVetoException(
642cdf0e10cSrcweir                                             "Dokument is still being used and cannot be closed.", this);
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 						}
645cdf0e10cSrcweir 						catch (java.lang.IllegalStateException exp)
646cdf0e10cSrcweir 						{}
647cdf0e10cSrcweir 					}
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 					// load the document.
650cdf0e10cSrcweir 					com.sun.star.beans.PropertyValue aArgs[] =
651cdf0e10cSrcweir 						addArgument( aArguments, new com.sun.star.beans.PropertyValue(
652cdf0e10cSrcweir 							"MacroExecutionMode", -1,
653cdf0e10cSrcweir 							new Short( com.sun.star.document.MacroExecMode.USE_CONFIG ),
654cdf0e10cSrcweir 							com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
655cdf0e10cSrcweir 									//String fn = aFRame.getName();
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 					com.sun.star.lang.XComponent xComponent = xLoader.loadComponentFromURL(
658cdf0e10cSrcweir 						aURL, /*aFrame.getName()*/"_self", 0, aArgs );
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 					// nothing loaded?
661cdf0e10cSrcweir 					if ( xComponent == null && aDocument != null )
662cdf0e10cSrcweir 					{
663cdf0e10cSrcweir 						// reactivate old document
664cdf0e10cSrcweir 						if ( aFrame != null && aFrame.getController() != null )
665cdf0e10cSrcweir 							aFrame.getController().suspend(false);
666cdf0e10cSrcweir 						aDocument.setModified(true);
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 						// throw exception
669cdf0e10cSrcweir 						throw new java.io.IOException(
670cdf0e10cSrcweir 							"Can not load a document: \"" + aURL + "\"");
671cdf0e10cSrcweir 					}
672cdf0e10cSrcweir 					// mDocumentURL = aURL; TBD: still needed?
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 					// Get document's XModifiable interface if any.
675cdf0e10cSrcweir 					aDocument = new OfficeDocument(
676cdf0e10cSrcweir 						(com.sun.star.frame.XModel) UnoRuntime.queryInterface(
677cdf0e10cSrcweir 						com.sun.star.frame.XModel.class, xComponent ) );
678cdf0e10cSrcweir 					bLoaded = true;
679cdf0e10cSrcweir 				}
680cdf0e10cSrcweir 				catch ( NoConnectionException aExc )
681cdf0e10cSrcweir 				{
682cdf0e10cSrcweir 					// stop, clear and retry
683cdf0e10cSrcweir 					stopOOoConnection();
684cdf0e10cSrcweir 				}
685cdf0e10cSrcweir 				catch ( com.sun.star.lang.DisposedException aExc )
686cdf0e10cSrcweir 				{
687cdf0e10cSrcweir 					// stop, clear and retry
688cdf0e10cSrcweir 					stopOOoConnection();
689cdf0e10cSrcweir 				}
690cdf0e10cSrcweir 				catch ( com.sun.star.uno.Exception aExc )
691cdf0e10cSrcweir 				{
692cdf0e10cSrcweir 					// TDB: handling failure in createInstance
693cdf0e10cSrcweir 					aExc.printStackTrace();
694cdf0e10cSrcweir 					throw new java.io.IOException();
695cdf0e10cSrcweir 				}
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 				aCallWatchThread.cancel();
698cdf0e10cSrcweir 				if ( xServiceFactory == null )
699cdf0e10cSrcweir 					throw new NoConnectionException();
700cdf0e10cSrcweir 			}
701cdf0e10cSrcweir 			if ( iConnection == null )
702cdf0e10cSrcweir 			{
703cdf0e10cSrcweir 				throw new NoConnectionException();
704cdf0e10cSrcweir 			}
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 			applyToolVisibilities();
707cdf0e10cSrcweir 		}
708cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
709cdf0e10cSrcweir 		{
710cdf0e10cSrcweir 			throw new NoConnectionException();
711cdf0e10cSrcweir 		}
712cdf0e10cSrcweir 	}
713cdf0e10cSrcweir 
714cdf0e10cSrcweir 	/** Loads a document from a Java stream.
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 	   	See loadFromURL() for further information.
717cdf0e10cSrcweir 	 */
loadFromStream( final java.io.InputStream iInStream, final com.sun.star.beans.PropertyValue aArguments[] )718cdf0e10cSrcweir 	public void loadFromStream(
719cdf0e10cSrcweir 			final java.io.InputStream iInStream,
720cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
721cdf0e10cSrcweir 		throws
722cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
723cdf0e10cSrcweir 			NoConnectionException,
724cdf0e10cSrcweir 			java.io.IOException,
725cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException,
726cdf0e10cSrcweir             com.sun.star.util.CloseVetoException
727cdf0e10cSrcweir 	{
728cdf0e10cSrcweir 		// wrap Java stream into UNO stream
729cdf0e10cSrcweir                 /*
730cdf0e10cSrcweir 		com.sun.star.io.XInputStream xStream =
731cdf0e10cSrcweir 				new com.sun.star.lib.uno.adapter.InputStreamToXInputStreamAdapter(
732cdf0e10cSrcweir 					iInStream );
733cdf0e10cSrcweir                  */
734cdf0e10cSrcweir                  // copy stream....
735cdf0e10cSrcweir 
736cdf0e10cSrcweir                  int s = 4096;
737cdf0e10cSrcweir                  int r=0 ,n = 0;
738cdf0e10cSrcweir                  byte[] buffer = new byte[s];
739cdf0e10cSrcweir                  byte[] newBuffer = null;
740cdf0e10cSrcweir                  while ((r = iInStream.read(buffer, n, buffer.length-n))>0) {
741cdf0e10cSrcweir                      n += r;
742cdf0e10cSrcweir                      if (iInStream.available() > buffer.length - n) {
743cdf0e10cSrcweir                          newBuffer = new byte[buffer.length*2];
744cdf0e10cSrcweir                          System.arraycopy(buffer, 0, newBuffer, 0, n);
745cdf0e10cSrcweir                          buffer = newBuffer;
746cdf0e10cSrcweir                      }
747cdf0e10cSrcweir                 }
748cdf0e10cSrcweir                 if (buffer.length != n) {
749cdf0e10cSrcweir                     newBuffer = new byte[n];
750cdf0e10cSrcweir                     System.arraycopy(buffer, 0, newBuffer, 0, n);
751cdf0e10cSrcweir                     buffer = newBuffer;
752cdf0e10cSrcweir                 }
753cdf0e10cSrcweir                 com.sun.star.io.XInputStream xStream =
754cdf0e10cSrcweir                     new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter(buffer);
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 		// add stream to arguments
757cdf0e10cSrcweir 		com.sun.star.beans.PropertyValue[] aExtendedArguments =
758cdf0e10cSrcweir 			addArgument( aArguments, new com.sun.star.beans.PropertyValue(
759cdf0e10cSrcweir 				"InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 		// call normal load method
762cdf0e10cSrcweir 		loadFromURL( "private:stream", aExtendedArguments );
763cdf0e10cSrcweir 	}
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	/** Loads a document from a byte array.
766cdf0e10cSrcweir 
767cdf0e10cSrcweir 	   	See loadFromURL() for further information.
768cdf0e10cSrcweir 	 */
loadFromByteArray( final byte aInBuffer[], final com.sun.star.beans.PropertyValue aArguments[] )769cdf0e10cSrcweir 	public void loadFromByteArray(
770cdf0e10cSrcweir 			final byte aInBuffer[],
771cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
772cdf0e10cSrcweir 		throws
773cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
774cdf0e10cSrcweir 			NoConnectionException,
775cdf0e10cSrcweir 			java.io.IOException,
776cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException,
777cdf0e10cSrcweir             com.sun.star.util.CloseVetoException
778cdf0e10cSrcweir 	{
779cdf0e10cSrcweir 		// wrap byte arrray into UNO stream
780cdf0e10cSrcweir 		com.sun.star.io.XInputStream xStream =
781cdf0e10cSrcweir 				new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter(
782cdf0e10cSrcweir 					aInBuffer );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 		// add stream to arguments
785cdf0e10cSrcweir 		com.sun.star.beans.PropertyValue[] aExtendedArguments =
786cdf0e10cSrcweir 			addArgument( aArguments, new com.sun.star.beans.PropertyValue(
787cdf0e10cSrcweir 				"InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 		// call normal load method
790cdf0e10cSrcweir 		loadFromURL( "private:stream", aExtendedArguments );
791cdf0e10cSrcweir 	}
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 	/** Stores a document to the given URL.
794cdf0e10cSrcweir         <p>
795cdf0e10cSrcweir         Due due a bug (50651) calling this method may cause the office to crash,
796cdf0e10cSrcweir         when at the same time the office writes a backup of the document. This bug
797cdf0e10cSrcweir         also affects {@link #storeToByteArray storeToByteArray} and
798cdf0e10cSrcweir         {@link #storeToStream storeToStream}. The workaround
799cdf0e10cSrcweir         is to start the office with the option -norestore, which disables the automatic
800cdf0e10cSrcweir         backup and recovery mechanism. OOoBean offers currently no supported way of providing
801cdf0e10cSrcweir         startup options for OOo. But it is possible to set a Java property when starting
802cdf0e10cSrcweir         Java, which is examined by OOoBean:
803cdf0e10cSrcweir         <pre>
804cdf0e10cSrcweir             java -Dcom.sun.star.officebean.Options=-norestore  ...
805cdf0e10cSrcweir         </pre>
806cdf0e10cSrcweir         It is planned to offer a way of specifying startup options in a future version.
807cdf0e10cSrcweir         The property can be used until then. When using this property only one option
808cdf0e10cSrcweir         can be provided.
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 	    @throws IllegalArgumentException
811cdf0e10cSrcweir 	    	if either of the arguments is out of the specified range.
812cdf0e10cSrcweir 
813cdf0e10cSrcweir 	    @throws java.io.IOException
814cdf0e10cSrcweir 	    	if an IO error occurs reading the ressource specified by the URL.
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	    @throws com.sun.star.lang.NoConnectionException
817cdf0e10cSrcweir 	    	if no connection is established.
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		@throws NoDocumentException
820cdf0e10cSrcweir 			if no document is loaded
821cdf0e10cSrcweir 	 */
storeToURL( final String aURL, final com.sun.star.beans.PropertyValue aArguments[] )822cdf0e10cSrcweir 	public void storeToURL(
823cdf0e10cSrcweir 			final String aURL,
824cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
825cdf0e10cSrcweir 		throws
826cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
827cdf0e10cSrcweir 			NoConnectionException,
828cdf0e10cSrcweir 			java.io.IOException,
829cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException,
830cdf0e10cSrcweir 			NoDocumentException
831cdf0e10cSrcweir 	{
832cdf0e10cSrcweir 		// no document available?
833cdf0e10cSrcweir 		if ( aDocument == null )
834cdf0e10cSrcweir 			throw new NoDocumentException();
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 		try
837cdf0e10cSrcweir 		{
838cdf0e10cSrcweir 			// start runtime timeout
839cdf0e10cSrcweir 			CallWatchThread aCallWatchThread =
840cdf0e10cSrcweir 				new CallWatchThread( nOOoCallTimeOut, "storeToURL" );
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 			// store the document
843cdf0e10cSrcweir 			try { aDocument.storeToURL( aURL, aArguments ); }
844cdf0e10cSrcweir 			catch ( com.sun.star.io.IOException aExc )
845cdf0e10cSrcweir 			{ throw new java.io.IOException(); }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 			// end runtime timeout
848cdf0e10cSrcweir 			aCallWatchThread.cancel();
849cdf0e10cSrcweir 		}
850cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
851cdf0e10cSrcweir 		{ throw new NoConnectionException(); }
852cdf0e10cSrcweir 	}
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	/** Stores a document to a stream.
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 	   	See {@link #storeToURL storeToURL} for further information.
857cdf0e10cSrcweir         @see #storeToURL storeToURL
858cdf0e10cSrcweir 	 */
storeToStream( java.io.OutputStream aOutStream, final com.sun.star.beans.PropertyValue aArguments[] )859cdf0e10cSrcweir 	public java.io.OutputStream storeToStream(
860cdf0e10cSrcweir 			java.io.OutputStream aOutStream,
861cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
862cdf0e10cSrcweir 		throws
863cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
864cdf0e10cSrcweir 			NoConnectionException,
865cdf0e10cSrcweir 			NoDocumentException,
866cdf0e10cSrcweir 			java.io.IOException,
867cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	{
870cdf0e10cSrcweir 		// wrap Java stream into UNO stream
871cdf0e10cSrcweir 		com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter aStream =
872cdf0e10cSrcweir 				new com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter(
873cdf0e10cSrcweir 					aOutStream );
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 		// add stream to arguments
876cdf0e10cSrcweir 		com.sun.star.beans.PropertyValue[] aExtendedArguments =
877cdf0e10cSrcweir 			addArgument( aArguments, new com.sun.star.beans.PropertyValue(
878cdf0e10cSrcweir 				"OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 		// call normal store method
881cdf0e10cSrcweir 		storeToURL( "private:stream", aExtendedArguments );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 		// get byte array from document stream
884cdf0e10cSrcweir 		try { aStream.closeOutput(); }
885cdf0e10cSrcweir 		catch ( com.sun.star.io.NotConnectedException aExc )
886cdf0e10cSrcweir 		{ /* TDB */ }
887cdf0e10cSrcweir 		catch ( com.sun.star.io.BufferSizeExceededException aExc )
888cdf0e10cSrcweir 		{ /* TDB */ }
889cdf0e10cSrcweir 		catch ( com.sun.star.io.IOException aExc )
890cdf0e10cSrcweir 		{ throw new java.io.IOException(); }
891cdf0e10cSrcweir 		return aOutStream;
892cdf0e10cSrcweir 	}
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 	/** Stores a document to a byte array.
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 	   	See {@link #storeToURL storeToURL} for further information.
897cdf0e10cSrcweir         @see #storeToURL storeToURL
898cdf0e10cSrcweir 	 */
storeToByteArray( byte aOutBuffer[], final com.sun.star.beans.PropertyValue aArguments[] )899cdf0e10cSrcweir 	public byte[] storeToByteArray(
900cdf0e10cSrcweir 			byte aOutBuffer[],
901cdf0e10cSrcweir 			final com.sun.star.beans.PropertyValue aArguments[] )
902cdf0e10cSrcweir 		throws
903cdf0e10cSrcweir 			// @requirement FUNC.CON.LOST/0.2
904cdf0e10cSrcweir 			NoConnectionException,
905cdf0e10cSrcweir 			NoDocumentException,
906cdf0e10cSrcweir 			java.io.IOException,
907cdf0e10cSrcweir 			com.sun.star.lang.IllegalArgumentException
908cdf0e10cSrcweir 	{
909cdf0e10cSrcweir 		// wrap byte arrray into UNO stream
910cdf0e10cSrcweir 		com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter aStream =
911cdf0e10cSrcweir 				new com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter(
912cdf0e10cSrcweir 					aOutBuffer );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 		// add stream to arguments
915cdf0e10cSrcweir 		com.sun.star.beans.PropertyValue[] aExtendedArguments =
916cdf0e10cSrcweir 			addArgument( aArguments, new com.sun.star.beans.PropertyValue(
917cdf0e10cSrcweir 				"OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) );
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 		// call normal store method
920cdf0e10cSrcweir 		storeToURL( "private:stream", aExtendedArguments );
921cdf0e10cSrcweir 
922cdf0e10cSrcweir 		// get byte array from document stream
923cdf0e10cSrcweir 		try { aStream.closeOutput(); }
924cdf0e10cSrcweir 		catch ( com.sun.star.io.NotConnectedException aExc )
925cdf0e10cSrcweir 		{ /* TDB */ }
926cdf0e10cSrcweir 		catch ( com.sun.star.io.BufferSizeExceededException aExc )
927cdf0e10cSrcweir 		{ /* TDB */ }
928cdf0e10cSrcweir 		catch ( com.sun.star.io.IOException aExc )
929cdf0e10cSrcweir 		{ throw new java.io.IOException(); }
930cdf0e10cSrcweir 		return aStream.getBuffer();
931cdf0e10cSrcweir 	}
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 	// @requirement FUNC.BEAN.PROG/0.5
934cdf0e10cSrcweir 	// @requirement API.SIM.SEAP/0.2
935cdf0e10cSrcweir 	/** returns the <type scope="com::sun::star::frame">Frame</a>
936cdf0e10cSrcweir 	    of the bean.
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 	    @returns
939cdf0e10cSrcweir 	    	a Java class which implements all interfaces which the service
940cdf0e10cSrcweir 		<type scope="com::sun::star::frame">Frame</a> implements.
941cdf0e10cSrcweir 		Thus, methods can be called directly without queryInterface.
942cdf0e10cSrcweir 		This feature might be implemented by UNO or explicitely coded.
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 	    @throws NoConnectionException
945cdf0e10cSrcweir 	    	if the connection is not established.
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 	    @throws NotDocumentException
948cdf0e10cSrcweir 	    	if no document is loaded an thus no frame is available.
949cdf0e10cSrcweir 	 */
getFrame()950cdf0e10cSrcweir 	public Frame getFrame()
951cdf0e10cSrcweir 
952cdf0e10cSrcweir 		throws
953cdf0e10cSrcweir 			NoConnectionException // @requirement FUNC.CON.LOST/0.2
954cdf0e10cSrcweir 	{
955cdf0e10cSrcweir 		if ( iConnection == null )
956cdf0e10cSrcweir 			throw new NoConnectionException();
957cdf0e10cSrcweir 		return aFrame;
958cdf0e10cSrcweir 	}
959cdf0e10cSrcweir 
960cdf0e10cSrcweir    	// @requirement FUNC.BEAN.PROG/0.5
961cdf0e10cSrcweir    	// @requirement API.SIM.SEAP/0.2
962cdf0e10cSrcweir 	/** returns the <type scope="com::sun::star::frame::Controller"> of the bean.
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 	    @returns
965cdf0e10cSrcweir 	    	a Java class which implements all interfaces which the service
966cdf0e10cSrcweir 		<type scope="com::sun::star::frame">Controller</a> implements.
967cdf0e10cSrcweir 		Thus, methods can be called directly without queryInterface.
968cdf0e10cSrcweir 		This feature might be implemented by UNO or explicitely coded.
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 	    @throws NoConnectionException
971cdf0e10cSrcweir 	    	if the connection is not established.
972cdf0e10cSrcweir 	 */
getController()973cdf0e10cSrcweir 	public Controller getController()
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 		// @requirement FUNC.CON.LOST/0.2
976cdf0e10cSrcweir 		throws NoConnectionException
977cdf0e10cSrcweir 	{
978cdf0e10cSrcweir 		if ( iConnection == null )
979cdf0e10cSrcweir 			throw new NoConnectionException();
980cdf0e10cSrcweir 		if ( aController == null )
981cdf0e10cSrcweir 			aController = new Controller( aFrame.getController() );
982cdf0e10cSrcweir 		return aController;
983cdf0e10cSrcweir 	}
984cdf0e10cSrcweir 
985cdf0e10cSrcweir     // @requirement FUNC.BEAN.PROG/0.5
986cdf0e10cSrcweir     // @requirement FUNC.BEAN.STOR/0.4
987cdf0e10cSrcweir     // @requirement FUNC.BEAN.PRNT/0.4
988cdf0e10cSrcweir     // @requirement API.SIM.SEAP/0.2
989cdf0e10cSrcweir    	/** returns the <type scope="com::sun::star::document::OfficeDocument">
990cdf0e10cSrcweir 	    of the bean.
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 	    @returns
993cdf0e10cSrcweir 	    	a Java class which implements all interfaces which the service
994cdf0e10cSrcweir 		<type scope="com::sun::star::document">OfficeDocument</a>
995cdf0e10cSrcweir 		implements.
996cdf0e10cSrcweir 		Thus, methods can be called directly without queryInterface.
997cdf0e10cSrcweir 		This feature might be implemented by UNO or explicitely coded.
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	    @throws NoConnectionException
1000cdf0e10cSrcweir 	    	if the connection is not established.
1001cdf0e10cSrcweir 	 */
getDocument()1002cdf0e10cSrcweir 	public OfficeDocument getDocument()
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 		// @requirement FUNC.CON.LOST/0.2
1005cdf0e10cSrcweir 		throws NoConnectionException
1006cdf0e10cSrcweir 	{
1007cdf0e10cSrcweir 		if ( iConnection == null )
1008cdf0e10cSrcweir 			throw new NoConnectionException();
1009cdf0e10cSrcweir 		return aDocument;
1010cdf0e10cSrcweir 	}
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir     /**	Sets visibility of all tool bars known by this OOoBean version.
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir 	 	Initially all tool bars are visible.  By hiding all tool bars
1015cdf0e10cSrcweir 		utilizing this method, it is possible to turn just a subset of
1016cdf0e10cSrcweir 		tool bars on afterwards, no matter whether all available tool
1017cdf0e10cSrcweir 		bars are known or not.
1018cdf0e10cSrcweir         <p>
1019cdf0e10cSrcweir 		If an older OOoBean instance is used with a newer OOo instance,
1020cdf0e10cSrcweir 		some tool bars might not be affected by this method.
1021cdf0e10cSrcweir         <p>
1022cdf0e10cSrcweir 		If no connection is established or no document is loaded,
1023cdf0e10cSrcweir 		the setting is memorized until a document is loaded.  Same
1024cdf0e10cSrcweir 		is valid when the connection dies within this function call.
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1027cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. For example:
1028cdf0e10cSrcweir         <pre>
1029cdf0e10cSrcweir com.sun.star.beans.XPropertySet xPropSet =
1030cdf0e10cSrcweir   (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
1031cdf0e10cSrcweir     com.sun.star.beans.XPropertySet.class, aFrame );
1032cdf0e10cSrcweir com.sun.star.frame.XLayoutManager xLayoutManager =
1033cdf0e10cSrcweir   (com.sun.star.frame.XLayoutManager) UnoRuntime.queryInterface(
1034cdf0e10cSrcweir     com.sun.star.frame.XLayoutManager.class,
1035cdf0e10cSrcweir     xPropSet.getPropertyValue( "LayoutManager" ) );
1036cdf0e10cSrcweir xLayoutManager.showElement("private:resource/menubar/menubar");
1037cdf0e10cSrcweir         </pre>
1038cdf0e10cSrcweir      */
setAllBarsVisible( boolean bVisible )1039cdf0e10cSrcweir 	public void setAllBarsVisible( boolean bVisible )
1040cdf0e10cSrcweir 	{
1041cdf0e10cSrcweir 		bIgnoreVisibility = true;
1042cdf0e10cSrcweir 		setMenuBarVisible( bVisible );
1043cdf0e10cSrcweir 		setStandardBarVisible( bVisible );
1044cdf0e10cSrcweir 		setToolBarVisible( bVisible );
1045cdf0e10cSrcweir 		setStatusBarVisible( bVisible );
1046cdf0e10cSrcweir 		bIgnoreVisibility = false;
1047cdf0e10cSrcweir 	}
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 	//--------------------------------------------------------------------------
1050cdf0e10cSrcweir     /**	Applies all tool visiblities to the real thing.
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1053cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1054cdf0e10cSrcweir         {@link #setAllBarsVisible setAllBarsVisible}.
1055cdf0e10cSrcweir      */
applyToolVisibilities()1056cdf0e10cSrcweir 	protected void applyToolVisibilities()
1057cdf0e10cSrcweir 		throws
1058cdf0e10cSrcweir 			java.lang.InterruptedException
1059cdf0e10cSrcweir 	{
1060cdf0e10cSrcweir 		bIgnoreVisibility = true;
1061cdf0e10cSrcweir 		setMenuBarVisible( bMenuBarVisible );
1062cdf0e10cSrcweir 		setStandardBarVisible( bStandardBarVisible );
1063cdf0e10cSrcweir 		setToolBarVisible( bToolBarVisible );
1064cdf0e10cSrcweir 		setStatusBarVisible( bStatusBarVisible );
1065cdf0e10cSrcweir 		bIgnoreVisibility = false;
1066cdf0e10cSrcweir 	}
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir     /**	Helper method to set tool bar visibilty.
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir      	@param bnewValue
1071cdf0e10cSrcweir 			If false, the tool bar is disabled,
1072cdf0e10cSrcweir 			If true, the tool bar is visible.
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1075cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1076cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1077cdf0e10cSrcweir      */
setToolVisible( String aProperty, String aResourceURL, boolean bOldValue, boolean bNewValue )1078cdf0e10cSrcweir     protected boolean setToolVisible( String aProperty, String aResourceURL,
1079cdf0e10cSrcweir         boolean bOldValue, boolean bNewValue )
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 		throws
1082cdf0e10cSrcweir 			java.lang.InterruptedException
1083cdf0e10cSrcweir     {
1084cdf0e10cSrcweir 		// start runtime timeout
1085cdf0e10cSrcweir 		CallWatchThread aCallWatchThread =
1086cdf0e10cSrcweir 			new CallWatchThread( nOOoCallTimeOut, "setToolVisible" );
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 		// Does a frame exist?
1089cdf0e10cSrcweir 		if ( aFrame != null )
1090cdf0e10cSrcweir 		{
1091cdf0e10cSrcweir 			if ( bIgnoreVisibility || bOldValue != bNewValue )
1092cdf0e10cSrcweir 			{
1093cdf0e10cSrcweir 				try
1094cdf0e10cSrcweir 				{
1095cdf0e10cSrcweir 					com.sun.star.beans.XPropertySet xPropSet =
1096cdf0e10cSrcweir 							(com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
1097cdf0e10cSrcweir 							com.sun.star.beans.XPropertySet.class, aFrame );
1098cdf0e10cSrcweir 					com.sun.star.frame.XLayoutManager xLayoutManager =
1099cdf0e10cSrcweir 							(com.sun.star.frame.XLayoutManager) UnoRuntime.queryInterface(
1100cdf0e10cSrcweir 							com.sun.star.frame.XLayoutManager.class,
1101cdf0e10cSrcweir 							xPropSet.getPropertyValue( "LayoutManager" ) );
1102cdf0e10cSrcweir 					if ( bNewValue )
1103cdf0e10cSrcweir 						xLayoutManager.showElement( aResourceURL );
1104cdf0e10cSrcweir 					else
1105cdf0e10cSrcweir 						xLayoutManager.hideElement( aResourceURL );
1106cdf0e10cSrcweir 				}
1107cdf0e10cSrcweir 				catch (  com.sun.star.beans.UnknownPropertyException aExc )
1108cdf0e10cSrcweir 				{
1109cdf0e10cSrcweir 					throw new RuntimeException( "not layout manager found" );
1110cdf0e10cSrcweir 				}
1111cdf0e10cSrcweir 				catch (  com.sun.star.lang.WrappedTargetException aExc )
1112cdf0e10cSrcweir 				{
1113cdf0e10cSrcweir 					throw new RuntimeException( "not layout manager found" );
1114cdf0e10cSrcweir 				}
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 				// notify change
1117cdf0e10cSrcweir 				firePropertyChange( aProperty, new Boolean(bOldValue), new Boolean(bNewValue) );
1118cdf0e10cSrcweir 		   }
1119cdf0e10cSrcweir 		}
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 		// end runtime timeout
1122cdf0e10cSrcweir 		aCallWatchThread.cancel();
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 		// the new value will be stored by caller
1125cdf0e10cSrcweir 		return bNewValue;
1126cdf0e10cSrcweir 	}
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir     /**	Sets the visibility of the menu bar.
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 		Initially the menu bar is visible.
1131cdf0e10cSrcweir         <p>
1132cdf0e10cSrcweir 		If not connected or no document loaded, the value is stored
1133cdf0e10cSrcweir 		and automatically applied to the document after it is loaded.
1134cdf0e10cSrcweir 		Same is valid when the connection dies within this function call.
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir      	@param bVisible
1137cdf0e10cSrcweir 			If false, the menu bar is disabled,
1138cdf0e10cSrcweir 			If true, the menu bar is visible.
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1141cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1142cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1143cdf0e10cSrcweir      */
setMenuBarVisible(boolean bVisible)1144cdf0e10cSrcweir     public void setMenuBarVisible(boolean bVisible)
1145cdf0e10cSrcweir     {
1146cdf0e10cSrcweir 		try
1147cdf0e10cSrcweir 		{
1148cdf0e10cSrcweir 			bMenuBarVisible = setToolVisible( "MenuBarVisible",
1149cdf0e10cSrcweir                     "private:resource/menubar/menubar",	bMenuBarVisible, bVisible );
1150cdf0e10cSrcweir 		}
1151cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
1152cdf0e10cSrcweir 		{
1153cdf0e10cSrcweir             bMenuBarVisible = bVisible;
1154cdf0e10cSrcweir         }
1155cdf0e10cSrcweir 	}
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir   	/** Returns the visibility of the menu bar.
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 	   	This method works independently from a connetion or loaded document.
1160cdf0e10cSrcweir 		If no connection is established or no document is loaded,
1161cdf0e10cSrcweir 		this method just returns a memorized status.
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir     	@return
1164cdf0e10cSrcweir 			True if the menu bar is visible,
1165cdf0e10cSrcweir 			false if the menu bar is hidden.
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1168cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1169cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1170cdf0e10cSrcweir      */
isMenuBarVisible()1171cdf0e10cSrcweir 	public boolean isMenuBarVisible()
1172cdf0e10cSrcweir 	{
1173cdf0e10cSrcweir 		return bMenuBarVisible;
1174cdf0e10cSrcweir 	}
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir     /**	Sets the main function bar visibilty.
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir 		Initially the standard bar is visible.
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir 		If not connected or no document loaded, the value is stored
1181cdf0e10cSrcweir 		and automatically applied to the document after it is loaded.
1182cdf0e10cSrcweir 		Same is valid when the connection dies within this function call.
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir      	@param bVisible
1185cdf0e10cSrcweir 			If false, the main function bar is disabled,
1186cdf0e10cSrcweir 			If true, the main function bar is visible.
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1189cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1190cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1191cdf0e10cSrcweir      */
setStandardBarVisible(boolean bVisible)1192cdf0e10cSrcweir     public void setStandardBarVisible(boolean bVisible)
1193cdf0e10cSrcweir     {
1194cdf0e10cSrcweir 		try
1195cdf0e10cSrcweir 		{
1196cdf0e10cSrcweir 			bStandardBarVisible = setToolVisible( "StandardBarVisible",
1197cdf0e10cSrcweir                     "private:resource/toolbar/standardbar", bStandardBarVisible, bVisible );
1198cdf0e10cSrcweir 		}
1199cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
1200cdf0e10cSrcweir 		{
1201cdf0e10cSrcweir             bMenuBarVisible = bVisible;
1202cdf0e10cSrcweir         }
1203cdf0e10cSrcweir 	}
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir   	/** Returns the visibility of the main function bar.
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 	   	This method works independently from a connetion or loaded document.
1208cdf0e10cSrcweir 		If no connection is established or no document is loaded,
1209cdf0e10cSrcweir 		this method just returns a memorized status.
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir     	@return
1212cdf0e10cSrcweir 			True if the main function bar is visible,
1213cdf0e10cSrcweir 			false if the main function bar is hidden.
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1216cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1217cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1218cdf0e10cSrcweir     */
isStandardBarVisible()1219cdf0e10cSrcweir 	public boolean isStandardBarVisible()
1220cdf0e10cSrcweir 	{
1221cdf0e10cSrcweir 		return bStandardBarVisible;
1222cdf0e10cSrcweir 	}
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir     /**	Sets the tool function bar visibilty.
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir 		Initially the tool bar is visible.
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir 		If not connected or no document loaded, the value is stored
1229cdf0e10cSrcweir 		and automatically applied to the document after it is loaded.
1230cdf0e10cSrcweir 		Same is valid when the connection dies within this function call.
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir      	@param bVisible
1233cdf0e10cSrcweir 			If false, the tool function bar is disabled,
1234cdf0e10cSrcweir 			If true, the tool function bar is visible.
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1237cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1238cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1239cdf0e10cSrcweir      */
setToolBarVisible(boolean bVisible)1240cdf0e10cSrcweir     public void setToolBarVisible(boolean bVisible)
1241cdf0e10cSrcweir     {
1242cdf0e10cSrcweir 		try
1243cdf0e10cSrcweir 		{
1244cdf0e10cSrcweir 			bToolBarVisible = setToolVisible( "ToolBarVisible",
1245cdf0e10cSrcweir                     "private:resource/toolbar/toolbar", bToolBarVisible, bVisible );
1246cdf0e10cSrcweir 		}
1247cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
1248cdf0e10cSrcweir 		{
1249cdf0e10cSrcweir             bMenuBarVisible = bVisible;
1250cdf0e10cSrcweir         }
1251cdf0e10cSrcweir 	}
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir   	/** Returns the visibility of the tool function bar.
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 	   	This method works independently from a connetion or loaded document.
1256cdf0e10cSrcweir 		If no connection is established or no document is loaded,
1257cdf0e10cSrcweir 		this method just returns a memorized status.
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir     	@return
1260cdf0e10cSrcweir 			True if the tool function bar is visible,
1261cdf0e10cSrcweir 			false if the tool function bar is hidden.
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1264cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1265cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1266cdf0e10cSrcweir      */
isToolBarVisible()1267cdf0e10cSrcweir 	public boolean isToolBarVisible()
1268cdf0e10cSrcweir 	{
1269cdf0e10cSrcweir 		return bToolBarVisible;
1270cdf0e10cSrcweir 	}
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir     /**	Sets the status function bar visibilty.
1273cdf0e10cSrcweir 
1274cdf0e10cSrcweir 		Initially the status bar is visible.
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 		If not connected or no document loaded, the value is stored
1277cdf0e10cSrcweir 		and automatically applied to the document after it is loaded.
1278cdf0e10cSrcweir 		Same is valid when the connection dies within this function call.
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir      	@param bVisible
1281cdf0e10cSrcweir 			If false, the status function bar is disabled,
1282cdf0e10cSrcweir 			If true, the status function bar is visible.
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1285cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1286cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1287cdf0e10cSrcweir      */
setStatusBarVisible(boolean bVisible)1288cdf0e10cSrcweir     public void setStatusBarVisible(boolean bVisible)
1289cdf0e10cSrcweir     {
1290cdf0e10cSrcweir 		try
1291cdf0e10cSrcweir 		{
1292cdf0e10cSrcweir 			bStatusBarVisible = setToolVisible( "StatusBarVisible",
1293cdf0e10cSrcweir                     "private:resource/statusbar/statusbar", bStatusBarVisible, bVisible );
1294cdf0e10cSrcweir 		}
1295cdf0e10cSrcweir 		catch ( java.lang.InterruptedException aExc )
1296cdf0e10cSrcweir 		{
1297cdf0e10cSrcweir             bMenuBarVisible = bVisible;
1298cdf0e10cSrcweir         }
1299cdf0e10cSrcweir 	}
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir   	/**	Returns the visibility of the status function bar.
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir 	   	This method works independently from a connetion or loaded document.
1304cdf0e10cSrcweir 		If no connection is established or no document is loaded,
1305cdf0e10cSrcweir 		this method just returns a memorized status.
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir     	@return
1308cdf0e10cSrcweir 			True if the status function bar is visible,
1309cdf0e10cSrcweir 			false if the status function bar is hidden.
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir         @deprecated Clients should use the service com.sun.star.frame.LayoutManager,
1312cdf0e10cSrcweir         which can be obtained from a frame, to control toolbars. See also
1313cdf0e10cSrcweir         {@link #setAllBarsVisible}.
1314cdf0e10cSrcweir      */
isStatusBarVisible()1315cdf0e10cSrcweir 	public boolean isStatusBarVisible()
1316cdf0e10cSrcweir 	{
1317cdf0e10cSrcweir 		return bStatusBarVisible;
1318cdf0e10cSrcweir 	}
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 	//===========================================================================
1321cdf0e10cSrcweir 	// Helper Methods / Internal Methods
1322cdf0e10cSrcweir 	//---------------------------------------------------------------------------
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 	// general instance intializer
1325cdf0e10cSrcweir 	{
setLayout(new java.awt.BorderLayout())1326cdf0e10cSrcweir 		setLayout(new java.awt.BorderLayout());
1327cdf0e10cSrcweir 	}
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir     /**
1330cdf0e10cSrcweir         @deprecated
1331cdf0e10cSrcweir      */
paint( java.awt.Graphics aGraphics )1332cdf0e10cSrcweir 	public void paint( java.awt.Graphics aGraphics )
1333cdf0e10cSrcweir 	{
1334cdf0e10cSrcweir 	}
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir 	/** Adds a single argument to an array of arguments.
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 		If the argument by its name is already in aArguments
1339cdf0e10cSrcweir 		it is exchanged and aArguments is returned.
1340cdf0e10cSrcweir         <p>
1341cdf0e10cSrcweir 		If the argument by its name is not yet in aArguments,
1342cdf0e10cSrcweir 		a new array is created, aArgument added and the new
1343cdf0e10cSrcweir 		array returned.
1344cdf0e10cSrcweir 	*/
addArgument( com.sun.star.beans.PropertyValue aArguments[], final com.sun.star.beans.PropertyValue aArgument )1345cdf0e10cSrcweir 	protected com.sun.star.beans.PropertyValue[] addArgument(
1346cdf0e10cSrcweir 				com.sun.star.beans.PropertyValue aArguments[],
1347cdf0e10cSrcweir 				final com.sun.star.beans.PropertyValue aArgument )
1348cdf0e10cSrcweir 	{
1349cdf0e10cSrcweir 		// get number of current arguments
1350cdf0e10cSrcweir 		int nNumArgs = 0;
1351cdf0e10cSrcweir 		if ( aArguments != null )
1352cdf0e10cSrcweir 			nNumArgs = aArguments.length;
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir 		// is new argument already set?
1355cdf0e10cSrcweir 		for ( int n = 0; n < nNumArgs; ++n )
1356cdf0e10cSrcweir 		{
1357cdf0e10cSrcweir 			if ( aArguments[n].Name == aArgument.Name )
1358cdf0e10cSrcweir 			{
1359cdf0e10cSrcweir 				// substitute this argument
1360cdf0e10cSrcweir 				aArguments[n] = aArgument;
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir 				// return current array
1363cdf0e10cSrcweir 				return aArguments;
1364cdf0e10cSrcweir 			}
1365cdf0e10cSrcweir 		}
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir 		// create extended arguments
1368cdf0e10cSrcweir 		com.sun.star.beans.PropertyValue[] aExtendedArguments =
1369cdf0e10cSrcweir 			new com.sun.star.beans.PropertyValue[ nNumArgs + 1 ];
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir 		// copy current arguments
1372cdf0e10cSrcweir 		for ( int n = 0; n < nNumArgs; ++n )
1373cdf0e10cSrcweir 			aExtendedArguments[n] = aArguments[n];
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 		// add new argument
1376cdf0e10cSrcweir 		aExtendedArguments[ nNumArgs ] = aArgument;
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir 		// return new arguments
1379cdf0e10cSrcweir 		return aExtendedArguments;
1380cdf0e10cSrcweir 	}
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir 	//===========================================================================
1383cdf0e10cSrcweir 	// Helper Classes
1384cdf0e10cSrcweir 	//---------------------------------------------------------------------------
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir 	/** Helper class to listen on the connection to learn when it dies.
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir 	    @internal
1389cdf0e10cSrcweir 	 */
1390cdf0e10cSrcweir 	private class EventListener
1391cdf0e10cSrcweir 		extends Thread
1392cdf0e10cSrcweir 		implements
1393cdf0e10cSrcweir 			com.sun.star.lang.XEventListener,
1394cdf0e10cSrcweir 			com.sun.star.frame.XTerminateListener
1395cdf0e10cSrcweir 	{
1396cdf0e10cSrcweir 		String aTag;
1397cdf0e10cSrcweir 
EventListener( String aTag )1398cdf0e10cSrcweir 		EventListener( String aTag )
1399cdf0e10cSrcweir 			throws NoConnectionException
1400cdf0e10cSrcweir 		{
1401cdf0e10cSrcweir 			// init members
1402cdf0e10cSrcweir 			this.aTag = aTag;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 			// listen on a dying connection
1405cdf0e10cSrcweir 			iConnection.addEventListener( this );
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir 			// listen on a terminating OOo
1408cdf0e10cSrcweir 			getOOoDesktop().addTerminateListener( this );
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir 			// start this thread as a daemon
1411cdf0e10cSrcweir 			setDaemon( true );
1412cdf0e10cSrcweir 			start();
1413cdf0e10cSrcweir 		}
1414cdf0e10cSrcweir 
end()1415cdf0e10cSrcweir 		public void end()
1416cdf0e10cSrcweir 		{
1417cdf0e10cSrcweir 			// do not listen on a dying connection anymore
1418cdf0e10cSrcweir 			try {
1419cdf0e10cSrcweir 				iConnection.removeEventListener( this );
1420cdf0e10cSrcweir 			}
1421cdf0e10cSrcweir 			catch ( Throwable aExc ) {};
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir 			// do not listen on a terminating OOo anymore
1424cdf0e10cSrcweir 			try {
1425cdf0e10cSrcweir 				getOOoDesktop().removeTerminateListener( this );
1426cdf0e10cSrcweir 			}
1427cdf0e10cSrcweir 			catch ( Throwable aExc ) {};
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 			// stop thread
1430cdf0e10cSrcweir             this.interrupt();
1431cdf0e10cSrcweir 		}
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir 		/// gets called when the connection dies
disposing( com.sun.star.lang.EventObject Source )1434cdf0e10cSrcweir 		public void disposing( /*IN*/ com.sun.star.lang.EventObject Source )
1435cdf0e10cSrcweir 		{
1436cdf0e10cSrcweir 			// empty the OOoBean and cut the connection
1437cdf0e10cSrcweir 			stopOOoConnection();
1438cdf0e10cSrcweir 		}
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 		/// gets called when the user wants to terminate OOo
queryTermination( com.sun.star.lang.EventObject Event )1441cdf0e10cSrcweir 	   	public void queryTermination( /*IN*/ com.sun.star.lang.EventObject Event )
1442cdf0e10cSrcweir 			throws com.sun.star.frame.TerminationVetoException
1443cdf0e10cSrcweir 		{
1444cdf0e10cSrcweir 			// disallow termination of OOo while a OOoBean exists
1445cdf0e10cSrcweir 			throw new com.sun.star.frame.TerminationVetoException();
1446cdf0e10cSrcweir 		}
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir 		/// gets called when OOo terminates
notifyTermination( com.sun.star.lang.EventObject Event )1449cdf0e10cSrcweir 		public void notifyTermination( /*IN*/ com.sun.star.lang.EventObject Event )
1450cdf0e10cSrcweir 		{
1451cdf0e10cSrcweir 			// empty the OOoBean and cut the connection
1452cdf0e10cSrcweir 			stopOOoConnection();
1453cdf0e10cSrcweir 		}
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir 		/// watching the connection
run()1456cdf0e10cSrcweir 		public void run()
1457cdf0e10cSrcweir 		{
1458cdf0e10cSrcweir 			dbgPrint( "EventListener(" + aTag + ").run()" );
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir 			// remote call might hang => watch try
1461cdf0e10cSrcweir 			CallWatchThread aCallWatchThread =
1462cdf0e10cSrcweir 				new CallWatchThread( nOOoCallTimeOut, "EventListener(" + aTag + ")" );
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 			// continue to trying to connect the OOo instance
1465cdf0e10cSrcweir 			long n = 0;
1466cdf0e10cSrcweir 			while ( isInterrupted() == false
1467cdf0e10cSrcweir                     && iConnection != null
1468cdf0e10cSrcweir                     && iConnection.getComponentContext() != null )
1469cdf0e10cSrcweir 			{
1470cdf0e10cSrcweir 				dbgPrint( "EventListener(" + aTag + ").running() #" + ++n );
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir 				// still alive?
1473cdf0e10cSrcweir 				com.sun.star.lang.XMultiComponentFactory xServiceManager = null;
1474cdf0e10cSrcweir 				try
1475cdf0e10cSrcweir 				{
1476cdf0e10cSrcweir 					// an arbitrary (but cheap) call into OOo
1477cdf0e10cSrcweir 					xServiceManager = iConnection.getComponentContext().getServiceManager();
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 					// call successfully performed, restart watch for next loop
1480cdf0e10cSrcweir 					try
1481cdf0e10cSrcweir 					{
1482cdf0e10cSrcweir 						aCallWatchThread.restart();
1483cdf0e10cSrcweir 					}
1484cdf0e10cSrcweir 					catch ( java.lang.InterruptedException aExc )
1485cdf0e10cSrcweir 					{
1486cdf0e10cSrcweir 						// ignore late interrupt
1487cdf0e10cSrcweir 					}
1488cdf0e10cSrcweir 				}
1489cdf0e10cSrcweir 				catch ( java.lang.RuntimeException aExc )
1490cdf0e10cSrcweir 				{
1491cdf0e10cSrcweir 					// hung
1492cdf0e10cSrcweir 					OfficeConnection iDeadConn = iConnection;
1493cdf0e10cSrcweir 					iConnection = null;
1494cdf0e10cSrcweir 					iDeadConn.dispose();
1495cdf0e10cSrcweir 				}
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 				// sleep
1498cdf0e10cSrcweir 				try {
1499cdf0e10cSrcweir 						sleep(nOOoCheckCycle);
1500cdf0e10cSrcweir 				}
1501cdf0e10cSrcweir 				catch ( java.lang.InterruptedException aExc )
1502cdf0e10cSrcweir 				{
1503cdf0e10cSrcweir                     dbgPrint("EventListener(" + aTag + ") interupted.");
1504cdf0e10cSrcweir                     //thread can be ended by EvendListener.end();
1505cdf0e10cSrcweir                     break;
1506cdf0e10cSrcweir 				}
1507cdf0e10cSrcweir 			}
1508cdf0e10cSrcweir 		}
1509cdf0e10cSrcweir 	}
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir }
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir 
1515