KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > storagemodel > AttrList


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 package org.netbeans.mdr.storagemodel;
20
21 import java.util.*;
22 import javax.jmi.reflect.*;
23
24 import org.netbeans.mdr.persistence.StorageException;
25 import org.netbeans.mdr.persistence.MOFID;
26 import org.netbeans.mdr.util.DebugException;
27 import org.netbeans.mdr.util.Logger;
28
29 /**
30  *
31  * @author Martin Matula
32  */

33 public class AttrList extends AttrCollection implements List {
34     protected final List innerList;
35
36     public AttrList() {
37         innerList = (List) inner;
38     }
39
40     AttrList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc) throws StorageException {
41         this(mdrObject, desc, null);
42     }
43     
44     protected AttrList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc, List values) throws StorageException {
45         super(mdrObject, desc, values);
46         innerList = (List) inner;
47     }
48     
49     protected AttrList(StorableFeatured mdrObject, List values, int maxSize, Class JavaDoc type, String JavaDoc attrName, boolean isRefObject, MOFID metaMofId) {
50         super(mdrObject, values, maxSize, type, attrName, isRefObject, metaMofId);
51         innerList = values;
52     }
53     
54     public void add(int param, Object JavaDoc obj) {
55         checkType(obj);
56         checkMaxSize(1);
57         checkUnwrap();
58         mdrObject.objectWillChange();
59         
60         if (isIndexed)
61             ((StorableObject) mdrObject).removeFromIndex (metaMofId);
62         innerList.add(param, obj);
63         if (isRefObject) {
64             try {
65                 setAttribComposite((RefObject) obj);
66             } catch (StorageException e) {
67                 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
68             }
69         }
70         
71         if (isIndexed)
72             ((StorableObject) mdrObject).addToIndex (metaMofId);
73         
74         mdrObject.objectChanged();
75     }
76     
77     public boolean addAll(int param, Collection collection) {
78         // should not be called
79
throw new DebugException();
80     }
81     
82     public Object JavaDoc get(int param) {
83         checkUnwrap();
84         return innerList.get(param);
85     }
86     
87     public int indexOf(Object JavaDoc obj) {
88         checkUnwrap();
89         return innerList.indexOf(obj);
90     }
91     
92     public int lastIndexOf(Object JavaDoc obj) {
93         checkUnwrap();
94         return innerList.lastIndexOf(obj);
95     }
96     
97     public ListIterator listIterator() {
98         checkUnwrap();
99         return new AttrListIterator(innerList.listIterator());
100     }
101     
102     public ListIterator listIterator(int param) {
103         checkUnwrap();
104         return new AttrListIterator(innerList.listIterator(param));
105     }
106     
107     public Object JavaDoc remove(int param) {
108         checkUnwrap();
109         mdrObject.objectWillChange();
110         if (isIndexed)
111             ((StorableObject) mdrObject).removeFromIndex (metaMofId);
112
113         Object JavaDoc result = innerList.remove(param);
114         if (isRefObject) {
115             try {
116                 clearAttribComposite((RefObject) result);
117             } catch (StorageException e) {
118                 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
119             }
120         }
121         
122         if (isIndexed)
123             ((StorableObject) mdrObject).addToIndex (metaMofId);
124         
125         mdrObject.objectChanged();
126         return result;
127     }
128     
129     public Object JavaDoc set(int param, Object JavaDoc obj) {
130         checkType(obj);
131         checkUnwrap();
132         mdrObject.objectWillChange();
133         if (isIndexed)
134             ((StorableObject) mdrObject).removeFromIndex (metaMofId);
135         
136         Object JavaDoc result = innerList.set(param, obj);
137         if (isRefObject) {
138             try {
139                 clearAttribComposite((RefObject) result);
140                 setAttribComposite((RefObject) obj);
141             } catch (StorageException e) {
142                 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
143             }
144         }
145         
146         if (isIndexed)
147             ((StorableObject) mdrObject).addToIndex (metaMofId);
148         
149         mdrObject.objectChanged();
150         return result;
151     }
152     
153     public List subList(int param, int param1) {
154         checkUnwrap();
155         return new AttrList(mdrObject, innerList.subList(param, param1), maxSize, type, attrName, isRefObject, metaMofId);
156     }
157     
158     protected class AttrListIterator extends AttrIterator implements ListIterator {
159         private final ListIterator innerIterator;
160         
161         protected AttrListIterator(ListIterator iterator) {
162             super(iterator);
163             innerIterator = iterator;
164         }
165         
166         public void add(Object JavaDoc obj) {
167             checkType(obj);
168             checkMaxSize(1);
169             
170             mdrObject.objectWillChange();
171             
172             if (isIndexed)
173                 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
174             
175             innerIterator.add(obj);
176             if (isRefObject) {
177                 try {
178                     setAttribComposite((RefObject) obj);
179                 } catch (StorageException e) {
180                     throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
181                 }
182             }
183             
184             if (isIndexed)
185                 ((StorableObject) mdrObject).addToIndex (metaMofId);
186             
187             mdrObject.objectChanged();
188         }
189         
190         public boolean hasPrevious() {
191             return innerIterator.hasPrevious();
192         }
193         
194         public int nextIndex() {
195             return innerIterator.nextIndex();
196         }
197         
198         public Object JavaDoc previous() {
199             return (lastRead = innerIterator.previous());
200         }
201         
202         public int previousIndex() {
203             return innerIterator.previousIndex();
204         }
205         
206         public void set(Object JavaDoc obj) {
207             checkType(obj);
208             
209             mdrObject.objectWillChange();
210             
211             if (isIndexed)
212                 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
213             
214             innerIterator.set(obj);
215             if (isRefObject) {
216                 try {
217                     clearAttribComposite((RefObject) lastRead);
218                     setAttribComposite((RefObject) obj);
219                 } catch (StorageException e) {
220                     throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
221                 }
222             }
223             
224             if (isIndexed)
225                 ((StorableObject) mdrObject).addToIndex (metaMofId);
226             
227             mdrObject.objectChanged();
228         }
229     }
230 }
231
Popular Tags