KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Modifier JavaDoc;
23 import java.util.*;
24 import javax.jmi.reflect.*;
25 import javax.jmi.model.MofClass;
26 import javax.jmi.model.Attribute;
27 import javax.jmi.model.GeneralizableElement;
28 import javax.jmi.model.NameNotFoundException;
29 import org.netbeans.jmi.javamodel.*;
30
31 /**
32  * @author Daniel Prusa
33  */

34 public class ArrayLengthField implements Field {
35
36     private static final String JavaDoc typeName = "int"; // NOI18N
37
private static final String JavaDoc MOF_ID_PREFIX = "ArrayLengthField:"; // NOI18N
38

39     private ArrayImpl parent;
40     private String JavaDoc mofId;
41     
42     private Type type;
43     private MultipartId typeRef;
44     
45     ArrayLengthField(ArrayImpl parent) {
46         this.parent = parent;
47         mofId = MOF_ID_PREFIX + parent.refMofId();
48         type = ((JavaModelPackage) parent.refImmediatePackage()).getType().resolve(typeName);
49         typeRef = new SyntheticMultipartId(this);
50     }
51     
52     public List getAnnotations() {
53         return Collections.EMPTY_LIST;
54     }
55     
56     public ClassDefinition getDeclaringClass() {
57         return parent;
58     }
59     
60     public int getDimCount() {
61         return 0;
62     }
63     
64     public int getEndOffset() {
65         return 0;
66     }
67     
68     public boolean isDeprecated() {
69         return false;
70     }
71     
72     public InitialValue getInitialValue() {
73         return null;
74     }
75     
76     public String JavaDoc getInitialValueText() {
77         return null;
78     }
79     
80     public JavaDoc getJavadoc() {
81         return null;
82     }
83     
84     public String JavaDoc getJavadocText() {
85         return null;
86     }
87     
88     public int getModifiers() {
89         return Modifier.PUBLIC | Modifier.FINAL;
90     }
91     
92     public String JavaDoc getName() {
93         return "length"; // NOI18N
94
}
95     
96     public int getPartEndOffset(ElementPartKind part) {
97         return 0;
98     }
99     
100     public int getPartStartOffset(ElementPartKind part) {
101         return 0;
102     }
103     
104     public Resource getResource() {
105         return parent.getResource();
106     }
107     
108     public int getStartOffset() {
109         return 0;
110     }
111     
112     public Type getType() {
113         return type;
114     }
115     
116     public TypeReference getTypeName() {
117         return typeRef;
118     }
119
120     public List getChildren() {
121         return Collections.EMPTY_LIST;
122     }
123
124     public boolean isValid() {
125         return true;
126     }
127
128     public Collection getReferences() {
129         return Collections.EMPTY_LIST; // [TODO]
130
}
131     
132     public boolean isFinal() {
133         return true;
134     }
135     
136     public RefClass refClass() {
137         return ((JavaModelPackage) parent.refImmediatePackage()).getField();
138     }
139     
140     public void refDelete() {
141         // do nothing
142
}
143     
144     public Object JavaDoc refGetValue(RefObject refObject) {
145         if (!(refObject instanceof Attribute)) {
146             throw new InvalidCallException(null, refObject);
147         }
148         return refGetValue(((Attribute) refObject).getName());
149     }
150     
151     public Object JavaDoc refGetValue(String JavaDoc str) {
152         if ("dimCount".equals(str)) { // NOI18N
153
return new Integer JavaDoc(getDimCount());
154         } else if ("final".equals(str)) { // NOI18N
155
return isFinal() ? Boolean.TRUE : Boolean.FALSE;
156         } else if ("initialValue".equals(str)) { // NOI18N
157
return getInitialValue();
158         } else if ("initialValueText".equals(str)) { // NOI18N
159
return getInitialValueText();
160         } else if ("javadoc".equals(str)) { // NOI18N
161
return getJavadoc();
162         } else if ("javadocText".equals(str)) { // NOI18N
163
return getJavadocText();
164         } else if ("modifiers".equals(str)) { // NOI18N
165
return new Integer JavaDoc(getModifiers());
166         } else if ("name".equals(str)) { // NOI18N
167
return getName();
168         } else if ("type".equals(str)) { // NOI18N
169
return getType();
170         } else if ("typeName".equals(str)) { // NOI18N
171
return getTypeName();
172         }
173         throw new InvalidCallException(null, null, "Invalid attribute name: " + str); // NOI18N
174
}
175     
176     public RefFeatured refImmediateComposite() {
177         return parent;
178     }
179     
180     public RefPackage refImmediatePackage() {
181         return parent.refImmediatePackage();
182     }
183     
184     public Object JavaDoc refInvokeOperation(RefObject refObject, List list) throws RefException {
185         throw new InvalidCallException(null, null);
186     }
187     
188     public Object JavaDoc refInvokeOperation(String JavaDoc str, List list) throws RefException {
189         throw new InvalidCallException(null, null);
190     }
191     
192     public boolean refIsInstanceOf(RefObject objType, boolean considerSubtypes) {
193         GeneralizableElement metaObject = (GeneralizableElement) refMetaObject();
194         return isInstanceOf(metaObject, objType, considerSubtypes);
195     }
196     
197     private boolean isInstanceOf(GeneralizableElement metaObject, RefObject objType, boolean considerSubtypes) {
198         if (metaObject.equals(objType))
199             return true;
200         if (considerSubtypes) {
201             Iterator it = metaObject.getSupertypes().iterator();
202             while (it.hasNext()) {
203                 if (isInstanceOf(((GeneralizableElement) it.next()), objType, true)) {
204                     return true;
205                 }
206             }
207         }
208         return false;
209     }
210     
211     public RefObject refMetaObject() {
212         return refClass().refMetaObject();
213     }
214     
215     public String JavaDoc refMofId() {
216         return mofId;
217     }
218     
219     public RefFeatured refOutermostComposite() {
220         return parent.refOutermostComposite();
221     }
222     
223     public RefPackage refOutermostPackage() {
224         return parent.refOutermostPackage();
225     }
226     
227     public void refSetValue(String JavaDoc str, Object JavaDoc obj) {
228         ArrayImpl.throwIsReadOnly(this);
229     }
230     
231     public void refSetValue(RefObject refObject, Object JavaDoc obj) {
232         ArrayImpl.throwIsReadOnly(this);
233     }
234     
235     public Collection refVerifyConstraints(boolean param) {
236         return Collections.EMPTY_LIST;
237     }
238     
239     public void replaceChild(Element oldChild, Element newChild) {
240         ArrayImpl.throwIsReadOnly(this);
241     }
242     
243     public void setDimCount(int newValue) {
244         ArrayImpl.throwIsReadOnly(this, "dimCount"); // NOI18N
245
}
246     
247     public void setFinal(boolean newValue) {
248         ArrayImpl.throwIsReadOnly(this, "final"); // NOI18N
249
}
250     
251     public void setInitialValue(InitialValue newValue) {
252         ArrayImpl.throwIsReadOnly(this, "initialValue"); // NOI18N
253
}
254     
255     public void setInitialValueText(String JavaDoc newValue) {
256         ArrayImpl.throwIsReadOnly(this, "initialValueText"); // NOI18N
257
}
258     
259     public void setJavadoc(JavaDoc newValue) {
260         ArrayImpl.throwIsReadOnly(this, "javadoc"); // NOI18N
261
}
262     
263     public void setJavadocText(String JavaDoc newValue) {
264         ArrayImpl.throwIsReadOnly(this, "javadocText"); // NOI18N
265
}
266     
267     public void setModifiers(int newValue) {
268         ArrayImpl.throwIsReadOnly(this, "modifiers"); // NOI18N
269
}
270     
271     public void setName(String JavaDoc newValue) {
272         ArrayImpl.throwIsReadOnly(this, "name"); // NOI18N
273
}
274     
275     public void setType(Type newValue) {
276         ArrayImpl.throwIsReadOnly(this, "type"); // NOI18N
277
}
278     
279     public void setTypeName(TypeReference newValue) {
280         ArrayImpl.throwIsReadOnly(this, "typeName"); // NOI18N
281
}
282         
283     public Element duplicate() {
284         throw new UnsupportedOperationException JavaDoc();
285     }
286     
287     public void setDeprecated(boolean newValue) {
288         ArrayImpl.throwIsReadOnly(this, "typeName"); // NOI18N
289
}
290 }
291
Popular Tags