KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > TypeList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javacore.jmiimpl.javamodel;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.AbstractList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.mdr.events.AttributeEvent;
26 import org.netbeans.jmi.javamodel.TypeClass;
27 import org.netbeans.jmi.javamodel.Type;
28 import org.netbeans.modules.javacore.parser.TypeRef;
29
30 /**
31  * @author Martin Matula
32  */

33 public class TypeList extends AbstractList JavaDoc {
34     protected final List JavaDoc innerList;
35     protected final SemiPersistentElement parent;
36
37     public TypeList(SemiPersistentElement parent) {
38         this(parent, new ArrayList JavaDoc());
39     }
40     
41     public TypeList(SemiPersistentElement parent, ArrayList JavaDoc innerList) {
42         this.parent = parent;
43         this.innerList = innerList;
44     }
45
46     public Object JavaDoc get(int index) {
47         return wrap(innerList.get(index));
48     }
49
50     public Object JavaDoc remove(int index) {
51         try {
52             fireChange(AttributeEvent.EVENT_ATTRIBUTE_REMOVE, null, index);
53             return wrap(innerList.remove(index));
54         } finally {
55             updateParent();
56         }
57     }
58
59     public void add(int index, Object JavaDoc element) {
60         try {
61             TypeRef tr = unwrap(element);
62             fireChange(AttributeEvent.EVENT_ATTRIBUTE_ADD, tr, index);
63             innerList.add(index, tr);
64         } finally {
65             updateParent();
66         }
67     }
68
69     public Object JavaDoc set(int index, Object JavaDoc element) {
70         try {
71             TypeRef tr = unwrap(element);
72             fireChange(AttributeEvent.EVENT_ATTRIBUTE_SET, tr, index);
73             return wrap(innerList.set(index, tr));
74         } finally {
75             updateParent();
76         }
77     }
78     
79     public int size() {
80         return innerList.size();
81     }
82
83     private TypeRef unwrap(Object JavaDoc element) {
84         return SemiPersistentElement.typeToTypeRef((Type) element);
85     }
86
87     private Object JavaDoc wrap(Object JavaDoc o) {
88         return parent.resolveType((TypeRef) o);
89     }
90
91     void addTypeRef(TypeRef typeRef) {
92         innerList.add(typeRef);
93     }
94     
95     protected void fireChange(int attrType, TypeRef newValue, int position) {
96     }
97     
98     protected void updateParent() {
99     }
100 }
101
Popular Tags