KickJava   Java API By Example, From Geeks To Geeks.

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


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 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; // variable used to generate mof id's
30
private static final String JavaDoc DEFERRED_STORAGE_ID = "deferredStorage"; // NOI18N
31

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     // ..........................................................................
41

42     public static synchronized MOFID generateNextMofid() {
43         return new MOFID (mofIdCounter++, DEFERRED_STORAGE_ID);
44     }
45     
46     // ..........................................................................
47

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     /** Creates a new instance of DeferredObject */
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         // immediate composite must be hard-referenced
63
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                 // check for Composition Violation
104
if (immediateComposite != null) {
105                     throw new javax.jmi.reflect.CompositionViolationException(getMdrStorage().getRepository().getHandler(this), (RefObject) getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(elementId)));
106                 }
107                 // check for Composition Cycle
108
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                 // check for Composition Closure
112
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         // do nothing
124
}
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         // do nothing
148
}
149     
150     public void objectChanged() {
151         // do nothing
152
}
153     
154     /** Returns string representation of this object.
155      * @return string representation of this object
156      */

157     public String JavaDoc toString () {
158         return getClass().getName() + "(" + mofId.toString() + ")"; // NOI18N
159
}
160
161     /** Returns object's hashcode
162      * @return hashcode
163      */

164     public int hashCode() {
165         return mofId.hashCode();
166     }
167     
168     protected void deleteRecursive() {
169         mdrStorage.removeExternal(this);
170     }
171     
172 }
173
Popular Tags