KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > junit > MultipleInheritanceTest


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.js.junit;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Observable JavaDoc;
22 import java.util.Observer JavaDoc;
23
24 import junit.framework.TestCase;
25
26
27 /** <p>This example demonstrates implementation of multiple
28  * inheritance with the ProxyGenerator. The class MyObservableList,
29  * an extension of {@link ObservableList}, is a subclass of
30  * {@link Observable}, but can also be viewed as a subclass
31  * of {@link ArrayList} (or whatever implementation of
32  * {@link List} you choose in the constructor. The
33  * {@link Observer Observers} are notified whenever an object
34  * is added to the list.</p>
35  *
36  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
37  * @version $Id: MultipleInheritanceTest.java,v 1.2 2004/02/16 23:39:54 jochen Exp $
38  */

39 public class MultipleInheritanceTest extends TestCase implements Observer JavaDoc {
40   public class MyObservableList extends ObservableList {
41     MyObservableList(List JavaDoc pList) {
42       super(pList);
43     }
44     public boolean add(Object JavaDoc o) {
45       boolean result = super.add(o);
46       setChanged();
47       notifyObservers();
48       clearChanged();
49       return result;
50     }
51   }
52
53   private int size;
54   public void update(Observable JavaDoc o, Object JavaDoc arg) {
55     size = ((List JavaDoc) o).size();
56   }
57
58   public MultipleInheritanceTest(String JavaDoc arg0) {
59     super(arg0);
60   }
61
62   public void testObserver() {
63     size = 0;
64     MyObservableList mol = new MyObservableList(new ArrayList JavaDoc());
65     mol.add("s");
66     assertEquals(0, size);
67     mol.addObserver(this);
68     mol.add("t");
69     assertEquals(2, size);
70     mol.add(new Integer JavaDoc(4));
71     assertEquals(3, size);
72   }
73 }
74
Popular Tags