2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.lang
.EventObject
;
22 import com
.sun
.star
.lang
.XComponent
;
23 import com
.sun
.star
.lang
.XEventListener
;
24 import share
.LogWriter
;
27 * Testing <code>com.sun.star.lang.XComponent</code>
30 * <li><code> dispose()</code></li>
31 * <li><code> addEventListener()</code></li>
32 * <li><code> removeEventListener()</code></li>
34 * After this interface test object <b>must be recreated</b>. <p>
35 * Multithreaded test ability <b>not implemented</b> yet.
36 * @see com.sun.star.lang.XComponent
38 public class _XComponent
{
40 public static XComponent oObj
= null;
41 private final LogWriter log
= null;
43 private boolean listenerDisposed
[] = new boolean[2];
44 private String
[] Loutput
= new String
[2];
47 * Listener which added but not removed, and its method must be called
48 * on <code>dispose</code> call.
50 private class MyEventListener
implements XEventListener
{
51 public void disposing ( EventObject oEvent
) {
52 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV1" + this;
53 listenerDisposed
[0] = true;
58 * Listener which added and then removed, and its method must <b>not</b>
59 * be called on <code>dispose</code> call.
61 private class MyEventListener2
implements XEventListener
{
62 public void disposing ( EventObject oEvent
) {
63 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV2" + this;
64 listenerDisposed
[1] = true;
68 private final XEventListener listener1
= new MyEventListener();
69 private final XEventListener listener2
= new MyEventListener2();
72 * Adds two listeners. <p>
73 * Has OK status if then the first listener will receive an event
74 * on <code>dispose</code> method call.
76 public boolean _addEventListener() {
78 listenerDisposed
[0] = false;
79 listenerDisposed
[1] = false;
81 oObj
.addEventListener( listener1
);
82 oObj
.addEventListener( listener2
);
85 } // finished _addEventListener()
88 * Removes the second of two added listeners. <p>
89 * Method tests to be completed successfully :
91 * <li> <code>addEventListener</code> : method must add two listeners. </li>
93 * Has OK status if no events will be sent to the second listener on
94 * <code>dispose</code> method call.
96 public boolean _removeEventListener() {
97 if (disposed
) return true;
98 // the second listener should not be called
99 oObj
.removeEventListener( listener2
);
100 log
.println(Thread
.currentThread() + " is removing EL " + listener2
);
102 } // finished _removeEventListener()
104 private boolean disposed
= false;
106 } // finished class _XComponent