1 19 20 package org.netbeans.modules.javacore.jmiimpl.javamodel; 21 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 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 36 public class SyntheticMultipartId implements MultipartId { 37 public static final String MOF_ID_PREFIX = "SyntheticMultipartId:"; 39 private TypedElement parent; 40 private String 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 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 getReferences() { 84 return Collections.EMPTY_LIST; 85 } 86 87 public List 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 } 102 103 public Object 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 refGetValue(String str) { 111 if ("element".equals(str)) { return getElement(); 113 } else if ("name".equals(str)) { return getName(); 115 } else if ("type".equals(str)) { return getType(); 117 } else if ("parent".equals(str)) { return getParent(); 119 } 120 throw new InvalidCallException(null, null, "Invalid attribute name: " + str); } 122 123 public RefFeatured refImmediateComposite() { 124 return parent; 125 } 126 127 public RefPackage refImmediatePackage() { 128 return parent.refImmediatePackage(); 129 } 130 131 public Object refInvokeOperation(RefObject refObject, List list) throws RefException { 132 throw new InvalidCallException(null, null); 133 } 134 135 public Object refInvokeOperation(String str, List 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 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 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 str, Object obj) { 175 ArrayImpl.throwIsReadOnly(this); 176 } 177 178 public void refSetValue(RefObject refObject, Object obj) { 179 ArrayImpl.throwIsReadOnly(this); 180 } 181 182 public Collection 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"); } 193 194 public void setName(String newValue) { 195 ArrayImpl.throwIsReadOnly(this, "name"); } 197 198 public void setParent(MultipartId newValue) { 199 ArrayImpl.throwIsReadOnly(this, "parent"); } 201 202 public void setType(Type newValue) { 203 ArrayImpl.throwIsReadOnly(this, "type"); } 205 206 public List getTypeArguments() { 207 return Collections.EMPTY_LIST; 208 } 209 210 public Element duplicate() { 211 throw new UnsupportedOperationException (); 212 } 213 } 214 | Popular Tags |