KickJava   Java API By Example, From Geeks To Geeks.

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


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.modules.javacore.jmiimpl.javamodel;
20
21 import java.util.*;
22 import javax.jmi.model.MofClass;
23 import javax.jmi.model.NameNotFoundException;
24 import javax.jmi.reflect.ConstraintViolationException;
25 import javax.jmi.reflect.RefObject;
26 import org.netbeans.jmi.javamodel.*;
27 import org.netbeans.mdr.handlers.InstanceHandler;
28 import org.netbeans.mdr.storagemodel.StorableObject;
29
30 /**
31  *
32  * @author Martin Matula
33  */

34 public abstract class ArrayImpl extends InstanceHandler implements Array {
35     Type type = null;
36     String JavaDoc name = null;
37     private Field lengthField = null;
38     private Method cloneMethod = null;
39
40     public ArrayImpl(StorableObject s) {
41         super(s);
42     }
43     
44     public Type getType() {
45         return type;
46     }
47     
48     public String JavaDoc getName() {
49         if (name == null) {
50             name = getType().getName() + "[]"; // NOI18N
51
}
52         return name;
53     }
54     
55     public void setName() {
56         throwIsReadOnly(this, "name"); // NOI18N
57
}
58     
59     public void setType(Type type) {
60         throwIsReadOnly(this, "type"); // NOI18N
61
}
62     
63     private Field getSyntheticField() {
64         if (lengthField == null) {
65             lengthField = new ArrayLengthField(this);
66         }
67         return lengthField;
68     }
69     
70     private Method getSyntheticMethod() {
71         if (cloneMethod == null) {
72             cloneMethod = new ArrayCloneMethod(this);
73         }
74         return cloneMethod;
75     }
76
77     // ClassDefinition implementation ...........................................
78

79     public Field getField(String JavaDoc name, boolean includeSupertypes) {
80         return "length".equals(name) ? getSyntheticField() : null; // NOI18N
81
}
82     
83     public Method getMethod(String JavaDoc name, List parameters, boolean includeSupertypes) {
84         return "clone".equals(name) ? getSyntheticMethod() : null; // NOI18N
85
}
86     
87     public JavaClass getInnerClass(String JavaDoc simpleName, boolean includeSupertypes) {
88         return null;
89     }
90     
91     public Constructor getConstructor(java.util.List JavaDoc parameters, boolean includeSupertypes) {
92         return null;
93     }
94     
95     public List getContents() {
96         return getFeatures();
97     }
98     
99     public MultipartId getSuperClassName() {
100         return null;
101     }
102     
103     public void setSuperClassName(MultipartId newValue) {
104         throwIsReadOnly(this, "superClassName"); // NOI18N
105
}
106     
107     public List getInterfaceNames() {
108         return Collections.EMPTY_LIST;
109     }
110     
111     public List getFeatures() {
112         List ret = new ArrayList(2);
113         ret.add(getSyntheticField());
114         ret.add(getSyntheticMethod());
115         return ret;
116     }
117     
118     public List getInterfaces() {
119         List ret = new ArrayList(2);
120         ret.add(((JavaModelPackage) refImmediatePackage()).getType().resolve("java.lang.Cloneable")); // NOI18N);
121
ret.add(((JavaModelPackage) refImmediatePackage()).getType().resolve("java.io.Serializable")); // NOI18N);
122
return ret;
123     }
124     
125     public JavaClass getSuperClass() {
126         return (JavaClass)((JavaModelPackage) refImmediatePackage()).getType().resolve("java.lang.Object"); // NOI18N
127
}
128     
129     public void setSuperClass(JavaClass newValue) {
130         throwIsReadOnly(this, "superClass"); // NOI18N
131
}
132     
133     public boolean isSubTypeOf(ClassDefinition clazz) {
134         return ClassDefinitionImpl.isSubTypeOf(this, clazz);
135     }
136     
137     public Resource getResource() {
138         return null;
139     }
140     
141     public List getChildren() {
142         return new ArrayList(getContents());
143     }
144     
145     public int getStartOffset() {
146         throw new UnsupportedOperationException JavaDoc();
147     }
148     
149     public int getEndOffset() {
150         throw new UnsupportedOperationException JavaDoc();
151     }
152     
153     public int getPartStartOffset(ElementPartKind part) {
154         throw new UnsupportedOperationException JavaDoc();
155     }
156
157     public int getPartEndOffset(ElementPartKind part) {
158         throw new UnsupportedOperationException JavaDoc();
159     }
160     
161     public boolean isValid() {
162         return type.isValid();
163     }
164     
165     public void replaceChild(Element oldChild, Element newChild) {
166         throw new UnsupportedOperationException JavaDoc();
167     }
168
169     // helper methods ...........................................................
170

171     static void throwIsReadOnly(RefObject obj, String JavaDoc attrName) {
172         RefObject attr = null;
173         try {
174             attr = ((MofClass) obj.refMetaObject()).lookupElementExtended(attrName);
175         } catch (NameNotFoundException e) {
176             // ignore
177
}
178         attrName = attrName.substring(0, 1).toUpperCase() + attrName.substring(1);
179         throw new ConstraintViolationException(obj, attr, attrName + " is readonly."); // NOI18N
180
}
181     
182     static void throwIsReadOnly(RefObject obj) {
183         throw new ConstraintViolationException(obj, null, "This instance is read only."); // NOI18N
184
}
185
186     public Element duplicate() {
187         throw new UnsupportedOperationException JavaDoc("The operation is intentionally unsupported at this element."); // NOI18N
188
}
189 }
190
Popular Tags