1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import javax.jmi.reflect.RefObject; 22 import org.netbeans.mdr.handlers.FeaturedHandler; 23 import org.netbeans.mdr.persistence.MOFID; 24 import org.netbeans.mdr.persistence.StorageException; 25 import org.netbeans.mdr.storagemodel.*; 26 27 public class DeferredObject extends StorableObject implements Transient { 28 29 private static long mofIdCounter = 0; private static final String DEFERRED_STORAGE_ID = "deferredStorage"; 32 private final MdrStorage mdrStorage; 33 private final StorableObject metaObject; 34 private final StorableClass classProxy; 35 private StorableFeatured immediateComposite; 36 private FeaturedHandler icHandler; 37 private final MOFID mofId; 38 private final MOFID outermostPackageId; 39 40 42 public static synchronized MOFID generateNextMofid() { 43 return new MOFID (mofIdCounter++, DEFERRED_STORAGE_ID); 44 } 45 46 48 public DeferredObject(MOFID mofId, MdrStorage mdrStorage, MOFID immediatePackageId, MOFID outermostPackageId, 49 StorableObject metaObject, StorableClass classProxy, StorableFeatured immediateComposite) throws StorageException { 50 this(mofId, mdrStorage, immediatePackageId, outermostPackageId, metaObject, classProxy, immediateComposite, false); 51 } 52 53 public DeferredObject(MOFID mofId, MdrStorage mdrStorage, MOFID immediatePackageId, MOFID outermostPackageId, 54 StorableObject metaObject, StorableClass classProxy, StorableFeatured immediateComposite, boolean initializeValues) throws StorageException { 55 super(); 56 this.mdrStorage = mdrStorage; 57 this.immediatePackage = immediatePackageId; 58 this.outermostPackageId = outermostPackageId; 59 this.metaObject = metaObject; 60 this.classProxy = classProxy; 61 this.immediateComposite = immediateComposite; 62 icHandler = (FeaturedHandler) mdrStorage.getRepository().getHandler(immediateComposite); 64 if (mofId == null) { 65 this.mofId = generateNextMofid(); 66 } else { 67 this.mofId = mofId; 68 } 69 70 if (initializeValues) { 71 check(); 72 int count = values.length; 73 for (int i = 0; i < count; i++) { 74 StorableClass.AttributeDescriptor desc = classProxy.getAttrDesc(i); 75 values[i] = getInitialValue(desc, null); 76 } 77 } 78 79 mdrStorage.registerExternal(this); 80 } 81 82 public DeferredObject(StorableObject storable) throws StorageException { 83 this(storable.getMofId(), storable.getMdrStorage(), storable.getImmediatePackageId(), storable.getOutermostPackageId(), 84 storable.getMetaObject(), storable.getClassProxy(), storable.getImmediateComposite()); 85 copyValues(storable); 86 } 87 88 public MOFID getMofId() { 89 return mofId; 90 } 91 92 public StorableFeatured getImmediateComposite() throws StorageException { 93 return immediateComposite; 94 } 95 96 public void setComposite(StorableBaseObject composite, org.netbeans.mdr.persistence.MOFID objectId, org.netbeans.mdr.persistence.MOFID elementId) throws StorageException { 97 if (composite == null) { 98 immediateComposite = null; 99 icHandler = null; 100 } else { 101 org.netbeans.mdr.persistence.MOFID id = composite.getMofId(); 102 if (immediateComposite == null || !id.equals(immediateComposite.getMofId())) { 103 if (immediateComposite != null) { 105 throw new javax.jmi.reflect.CompositionViolationException(getMdrStorage().getRepository().getHandler(this), (RefObject) getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(elementId))); 106 } 107 if ((composite instanceof StorableObject) && (((StorableObject) composite).getOutermostComposite().equals(this))) { 109 throw new javax.jmi.reflect.CompositionCycleException(getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(objectId)), (RefObject) getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(elementId))); 110 } 111 if (!composite.getOutermostPackageId().equals(getOutermostPackageId())) { 113 throw new javax.jmi.reflect.ClosureViolationException(getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(objectId)), (RefObject) getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(elementId))); 114 } 115 immediateComposite = (StorableFeatured) composite; 116 icHandler = (FeaturedHandler) mdrStorage.getRepository().getHandler(immediateComposite); 117 } 118 } 119 objectChanged (); 120 } 121 122 public void deleteInstance() throws StorageException { 123 } 125 126 public StorableObject getMetaObject() { 127 return metaObject; 128 } 129 130 public MOFID getClassProxyId() { 131 return classProxy.getMofId(); 132 } 133 134 public StorableClass getClassProxy() { 135 return classProxy; 136 } 137 138 public MOFID getOutermostPackageId() { 139 return outermostPackageId; 140 } 141 142 public MdrStorage getMdrStorage () { 143 return mdrStorage; 144 } 145 146 public void objectWillChange() { 147 } 149 150 public void objectChanged() { 151 } 153 154 157 public String toString () { 158 return getClass().getName() + "(" + mofId.toString() + ")"; } 160 161 164 public int hashCode() { 165 return mofId.hashCode(); 166 } 167 168 protected void deleteRecursive() { 169 mdrStorage.removeExternal(this); 170 } 171 172 } 173 | Popular Tags |