1 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 34 public abstract class ArrayImpl extends InstanceHandler implements Array { 35 Type type = null; 36 String 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 getName() { 49 if (name == null) { 50 name = getType().getName() + "[]"; } 52 return name; 53 } 54 55 public void setName() { 56 throwIsReadOnly(this, "name"); } 58 59 public void setType(Type type) { 60 throwIsReadOnly(this, "type"); } 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 79 public Field getField(String name, boolean includeSupertypes) { 80 return "length".equals(name) ? getSyntheticField() : null; } 82 83 public Method getMethod(String name, List parameters, boolean includeSupertypes) { 84 return "clone".equals(name) ? getSyntheticMethod() : null; } 86 87 public JavaClass getInnerClass(String simpleName, boolean includeSupertypes) { 88 return null; 89 } 90 91 public Constructor getConstructor(java.util.List 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"); } 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")); ret.add(((JavaModelPackage) refImmediatePackage()).getType().resolve("java.io.Serializable")); return ret; 123 } 124 125 public JavaClass getSuperClass() { 126 return (JavaClass)((JavaModelPackage) refImmediatePackage()).getType().resolve("java.lang.Object"); } 128 129 public void setSuperClass(JavaClass newValue) { 130 throwIsReadOnly(this, "superClass"); } 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 (); 147 } 148 149 public int getEndOffset() { 150 throw new UnsupportedOperationException (); 151 } 152 153 public int getPartStartOffset(ElementPartKind part) { 154 throw new UnsupportedOperationException (); 155 } 156 157 public int getPartEndOffset(ElementPartKind part) { 158 throw new UnsupportedOperationException (); 159 } 160 161 public boolean isValid() { 162 return type.isValid(); 163 } 164 165 public void replaceChild(Element oldChild, Element newChild) { 166 throw new UnsupportedOperationException (); 167 } 168 169 171 static void throwIsReadOnly(RefObject obj, String attrName) { 172 RefObject attr = null; 173 try { 174 attr = ((MofClass) obj.refMetaObject()).lookupElementExtended(attrName); 175 } catch (NameNotFoundException e) { 176 } 178 attrName = attrName.substring(0, 1).toUpperCase() + attrName.substring(1); 179 throw new ConstraintViolationException(obj, attr, attrName + " is readonly."); } 181 182 static void throwIsReadOnly(RefObject obj) { 183 throw new ConstraintViolationException(obj, null, "This instance is read only."); } 185 186 public Element duplicate() { 187 throw new UnsupportedOperationException ("The operation is intentionally unsupported at this element."); } 189 } 190 | Popular Tags |