KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.jmi.reflect.*;
27 import javax.jmi.model.GeneralizableElement;
28 import javax.jmi.model.Attribute;
29 import org.netbeans.jmi.javamodel.*;
30
31 /** Used by ArrayLengthField to represent type.
32  * [TODO] check whether this class is really necessary (ArrayLengthField most likely does not need to support returning multipartid for type
33  *
34  * @author Daniel Prusa
35  */

36 public class SyntheticMultipartId implements MultipartId {
37     public static final String JavaDoc MOF_ID_PREFIX = "SyntheticMultipartId:"; // NOI18N
38

39     private TypedElement parent;
40     private String JavaDoc mofId;
41     
42     SyntheticMultipartId(TypedElement parent) {
43         this.parent = parent;
44         mofId = MOF_ID_PREFIX + parent.refMofId();
45     }
46     
47     public NamedElement getElement() {
48         return (NamedElement) parent;
49     }
50     
51     public int getEndOffset() {
52         return 0;
53     }
54     
55     public String JavaDoc getName() {
56         return parent.getType().getName();
57     }
58     
59     public MultipartId getParent() {
60         return null;
61     }
62     
63     public int getPartEndOffset(ElementPartKind part) {
64         return 0;
65     }
66     
67     public int getPartStartOffset(ElementPartKind part) {
68         return 0;
69     }
70     
71     public Resource getResource() {
72         return parent.getResource();
73     }
74     
75     public int getStartOffset() {
76         return 0;
77     }
78     
79     public Type getType() {
80         return parent.getType();
81     }
82     
83     public Collection JavaDoc getReferences() {
84         return Collections.EMPTY_LIST;
85     }
86
87     public List JavaDoc getChildren() {
88         return Collections.EMPTY_LIST;
89     }
90
91     public boolean isValid() {
92         return true;
93     }
94
95     public RefClass refClass() {
96         return ((JavaModelPackage) refImmediatePackage()).getMultipartId();
97     }
98     
99     public void refDelete() {
100         // do nothing
101
}
102     
103     public Object JavaDoc refGetValue(RefObject refObject) {
104         if (!(refObject instanceof Attribute)) {
105             throw new InvalidCallException(null, refObject);
106         }
107         return refGetValue(((Attribute) refObject).getName());
108     }
109     
110     public Object JavaDoc refGetValue(String JavaDoc str) {
111          if ("element".equals(str)) { // NOI18N
112
return getElement();
113         } else if ("name".equals(str)) { // NOI18N
114
return getName();
115         } else if ("type".equals(str)) { // NOI18N
116
return getType();
117         } else if ("parent".equals(str)) { // NOI18N
118
return getParent();
119         }
120         throw new InvalidCallException(null, null, "Invalid attribute name: " + str); // NOI18N
121
}
122     
123     public RefFeatured refImmediateComposite() {
124         return parent;
125     }
126     
127     public RefPackage refImmediatePackage() {
128         return parent.refImmediatePackage();
129     }
130     
131     public Object JavaDoc refInvokeOperation(RefObject refObject, List JavaDoc list) throws RefException {
132         throw new InvalidCallException(null, null);
133     }
134     
135     public Object JavaDoc refInvokeOperation(String JavaDoc str, List JavaDoc list) throws RefException {
136         throw new InvalidCallException(null, null);
137     }
138     
139     public boolean refIsInstanceOf(RefObject objType, boolean considerSubtypes) {
140         GeneralizableElement metaObject = (GeneralizableElement) refMetaObject();
141         return isInstanceOf(metaObject, objType, considerSubtypes);
142     }
143     
144     private boolean isInstanceOf(GeneralizableElement metaObject, RefObject objType, boolean considerSubtypes) {
145         if (metaObject.equals(objType))
146             return true;
147         if (considerSubtypes) {
148             Iterator JavaDoc it = metaObject.getSupertypes().iterator();
149             while (it.hasNext()) {
150                 if (isInstanceOf(((GeneralizableElement) it.next()), objType, true)) {
151                     return true;
152                 }
153             }
154         }
155         return false;
156     }
157     
158     public RefObject refMetaObject() {
159         return refClass().refMetaObject();
160     }
161     
162     public String JavaDoc refMofId() {
163         return mofId;
164     }
165     
166     public RefFeatured refOutermostComposite() {
167         return parent.refOutermostComposite();
168     }
169     
170     public RefPackage refOutermostPackage() {
171         return parent.refOutermostPackage();
172     }
173     
174     public void refSetValue(String JavaDoc str, Object JavaDoc obj) {
175         ArrayImpl.throwIsReadOnly(this);
176     }
177     
178     public void refSetValue(RefObject refObject, Object JavaDoc obj) {
179         ArrayImpl.throwIsReadOnly(this);
180     }
181     
182     public Collection JavaDoc refVerifyConstraints(boolean param) {
183         return Collections.EMPTY_LIST;
184     }
185     
186     public void replaceChild(Element oldChild, Element newChild) {
187         ArrayImpl.throwIsReadOnly(this);
188     }
189     
190     public void setElement(NamedElement newValue) {
191         ArrayImpl.throwIsReadOnly(this, "element"); // NOI18N
192
}
193     
194     public void setName(String JavaDoc newValue) {
195         ArrayImpl.throwIsReadOnly(this, "name"); // NOI18N
196
}
197     
198     public void setParent(MultipartId newValue) {
199         ArrayImpl.throwIsReadOnly(this, "parent"); // NOI18N
200
}
201     
202     public void setType(Type newValue) {
203         ArrayImpl.throwIsReadOnly(this, "type"); // NOI18N
204
}
205     
206     public List JavaDoc getTypeArguments() {
207         return Collections.EMPTY_LIST;
208     }
209     
210     public Element duplicate() {
211         throw new UnsupportedOperationException JavaDoc();
212     }
213 }
214
Popular Tags