This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 25186
Collapse All | Expand All

(-)build.xml (-54 / +81 lines)
Lines 14-30 Link Here
14
14
15
<project name="mdr" basedir="." default="netbeans">
15
<project name="mdr" basedir="." default="netbeans">
16
16
17
  <!-- =========================================================== -->
18
  <!-- == Properties ============================================= -->
19
  <!-- =========================================================== -->
20
17
  <property name="nbroot" location=".."/>
21
  <property name="nbroot" location=".."/>
18
  <property name="nbext" location="${nbroot}/nbbuild"/>
22
  <property name="nbext" location="${nbroot}/nbbuild"/>
19
  <property name="binroot" location="../../nbextra"/>
23
  <property name="binroot" location="../../nbextra"/>
20
  <property name="storepass" value="?"/>
24
  <property name="storepass" value="?"/>
21
  <property name="build.compiler.debug" value="true"/>
25
  <property name="build.compiler.debug" value="true"/>
26
  <property name="build.compiler.deprecation" value="true"/>
22
  <property name="homepage.base" value="netbeans.org"/>
27
  <property name="homepage.base" value="netbeans.org"/>
23
  <property name="dist.base" value="www.netbeans.org/download/nbms/40/MDR"/>
28
  <property name="dist.base" value="www.netbeans.org/download/nbms/40/MDR"/>
24
29
25
  <taskdef name="makenbm" classname="org.netbeans.nbbuild.MakeNBM" classpath="${nbext}/nbantext.jar"/>
30
  <!-- all external files and directories -->
26
  <taskdef name="genlist" classname="org.netbeans.nbbuild.MakeListOfNBM" classpath="${nbext}/nbantext.jar"/>
31
  <property name="nbantext.jar" location="${nbext}/nbantext.jar"/>
27
  <taskdef name="locjar" classname="org.netbeans.nbbuild.LocalizedJar" classpath="${nbext}/nbantext.jar"/>
32
  <property name="openide-13javac-workaround.jar" location="${nbroot}/openide/openide-13javac-workaround.jar"/>
33
  <property name="openide.jar.dir" location="${nbroot}/openide/netbeans/lib"/>
34
  <property name="xml-apis.jar" location="${binroot}/core/release/lib/ext/xml-apis.jar"/>
35
  <property name="djava.jar" location="${binroot}/scripting/release/modules/ext/djava.jar"/>
36
  <property name="openidex.jar" location="${nbroot}/openidex/netbeans/modules/autoload/openidex.jar"/>
37
  <property name="naming.jar" location="${nbroot}/core/naming/netbeans/modules/autoload/naming.jar"/>
38
  <property name="looks.jar" location="${nbroot}/openidex/looks/netbeans/modules/autoload/looks.jar"/>
39
  <property name="standard-jar-excludes.txt" location="${nbroot}/nbbuild/standard-jar-excludes.txt"/>
40
  <property name="mof.xml" location="jmi/mof.xml"/>
41
  <property name="standard-nbm-license.txt" location="${nbroot}/nbbuild/standard-nbm-license.txt"/>
42
43
  <!-- =========================================================== -->
44
  <!-- == Taskdefs =============================================== -->
45
  <!-- =========================================================== -->
46
47
  <taskdef name="makenbm" classname="org.netbeans.nbbuild.MakeNBM" classpath="${nbantext.jar}"/>
48
  <taskdef name="genlist" classname="org.netbeans.nbbuild.MakeListOfNBM" classpath="${nbantext.jar}"/>
49
  <taskdef name="locjar" classname="org.netbeans.nbbuild.LocalizedJar"
50
  classpath="${nbantext.jar}"/>
51
52
  <!-- =========================================================== -->
53
  <!-- == Initialization ========================================= -->
54
  <!-- =========================================================== -->
28
55
29
  <target name="init">
56
  <target name="init">
30
    <tstamp>
57
    <tstamp>
Lines 34-72 Link Here
34
    <echo message="buildnumber = ${buildnumber}"/>
61
    <echo message="buildnumber = ${buildnumber}"/>
35
  </target>
62
  </target>
36
63
37
  <!-- ===================== -->
64
  <!-- =========================================================== -->
38
  <!-- Compilation classpath -->
65
  <!-- == Compilation classpath ================================== -->
39
  <!-- ===================== -->
66
  <!-- =========================================================== -->
67
40
  <path id="compile.class.path">
68
  <path id="compile.class.path">
41
    <pathelement location="${nbroot}/openide/openide-13javac-workaround.jar"/>
69
    <pathelement location="${openide-13javac-workaround.jar}"/>
42
    <fileset dir="${nbroot}/openide/netbeans/lib">
70
    <fileset dir="${openide.jar.dir}">
43
       <include name="openide*.jar"/>
71
       <include name="openide*.jar"/>
44
    </fileset>        
72
    </fileset>        
45
    <pathelement location="${binroot}/core/release/lib/ext/xml-apis.jar"/>
73
    <pathelement location="${xml-apis.jar}"/>
46
    <pathelement location="${binroot}/scripting/release/modules/ext/djava.jar"/>
74
    <pathelement location="${djava.jar}"/>
47
    <pathelement location="jmi/"/>
75
    <pathelement location="jmi/"/>
48
    <pathelement location="${nbroot}/openidex/netbeans/modules/autoload/openidex.jar"/>
76
    <pathelement location="${openidex.jar}"/>
49
  </path>
77
  </path>
50
78
51
  <!-- ====================================== -->
79
  <!-- =========================================================== -->
52
  <!-- Compilation classpath for MDR-Explorer -->
80
  <!-- == Compilation classpath for MDR-Explorer ================= -->
53
  <!-- ====================================== -->
81
  <!-- =========================================================== -->
82
54
  <path id="explorer.compile.class.path">
83
  <path id="explorer.compile.class.path">
55
    <pathelement location="${nbroot}/openide/openide-13javac-workaround.jar"/>
84
    <path refid="compile.class.path"/>
56
    <fileset dir="${nbroot}/openide/netbeans/lib">
85
    <pathelement location="${naming.jar}"/>
57
       <include name="openide*.jar"/>
86
    <pathelement location="${looks.jar}"/>
58
    </fileset>        
59
    <pathelement location="${binroot}/core/release/lib/ext/xml-apis.jar"/>
60
    <pathelement location="${binroot}/scripting/release/modules/ext/djava.jar"/>
61
    <pathelement location="jmi/"/>
62
    <pathelement location="${nbroot}/openidex/netbeans/modules/autoload/openidex.jar"/>
63
    <pathelement location="${nbroot}/core/naming/netbeans/modules/autoload/naming.jar"/>
64
    <pathelement location="${nbroot}/openidex/looks/netbeans/modules/autoload/looks.jar"/>
65
  </path>
87
  </path>
66
88
67
  <!-- ======================== -->
89
  <!-- =========================================================== -->
68
  <!-- Compilation of all parts -->
90
  <!-- == Compilation of all parts =============================== -->
69
  <!-- ======================== -->
91
  <!-- =========================================================== -->
92
70
  <target name="compile" depends="compile-src"/>
93
  <target name="compile" depends="compile-src"/>
71
  
94
  
72
  <target name="compile-jmi">
95
  <target name="compile-jmi">
Lines 96-104 Link Here
96
    </javac> 
119
    </javac> 
97
  </target>
120
  </target>
98
121
99
  <!-- ===================== -->
122
  <!-- =========================================================== -->
100
  <!-- Creating all mdr jars -->
123
  <!-- == Creating all mdr jars ================================== -->
101
  <!-- ===================== -->
124
  <!-- =========================================================== -->
125
102
  <target name="jars" depends="init,jars-all"/>
126
  <target name="jars" depends="init,jars-all"/>
103
127
104
  <target name="jars-jmi" depends="compile-jmi">
128
  <target name="jars-jmi" depends="compile-jmi">
Lines 106-112 Link Here
106
    <mkdir dir="netbeans/modules/autoload"/>
130
    <mkdir dir="netbeans/modules/autoload"/>
107
    <mkdir dir="jmi/javax/jmi/model/resources"/>
131
    <mkdir dir="jmi/javax/jmi/model/resources"/>
108
132
109
    <copy file="jmi/mof.xml" todir="jmi/javax/jmi/model/resources"/>
133
    <copy file="${mof.xml}" tofile="jmi/javax/jmi/model/resources/mof.xml"/>
110
134
111
    <filter token="BUILD_NUMBER_SUBST" value="${buildnumber}"/>
135
    <filter token="BUILD_NUMBER_SUBST" value="${buildnumber}"/>
112
    <copy file="manifest-mof.mf" filtering="on" tofile="manifest-mof-subst.mf"/>    
136
    <copy file="manifest-mof.mf" filtering="on" tofile="manifest-mof-subst.mf"/>    
Lines 118-124 Link Here
118
            manifest="manifest-mof-subst.mf"
142
            manifest="manifest-mof-subst.mf"
119
            compress="false">
143
            compress="false">
120
      <locale name="ja"/>
144
      <locale name="ja"/>
121
      <fileset dir="jmi" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
145
      <fileset dir="jmi" excludesfile="${standard-jar-excludes.txt}">
122
        <include name="javax/"/>
146
        <include name="javax/"/>
123
	<exclude name="javax/jmi/reflect/"/>
147
	<exclude name="javax/jmi/reflect/"/>
124
	<exclude name="javax/jmi/xmi/"/>
148
	<exclude name="javax/jmi/xmi/"/>
Lines 129-135 Link Here
129
            manifest="manifest-jmi-subst.mf"
153
            manifest="manifest-jmi-subst.mf"
130
            compress="false">
154
            compress="false">
131
      <locale name="ja"/>
155
      <locale name="ja"/>
132
      <fileset dir="jmi" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
156
      <fileset dir="jmi" excludesfile="${standard-jar-excludes.txt}">
133
	<include name="javax/jmi/reflect/"/>
157
	<include name="javax/jmi/reflect/"/>
134
	<include name="javax/jmi/xmi/"/>
158
	<include name="javax/jmi/xmi/"/>
135
      </fileset>
159
      </fileset>
Lines 151-157 Link Here
151
    <locjar jarfile="netbeans/modules/ext/nbmdr.jar"
175
    <locjar jarfile="netbeans/modules/ext/nbmdr.jar"
152
            compress="false">
176
            compress="false">
153
      <locale name="ja"/>
177
      <locale name="ja"/>
154
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
178
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
155
        <include name="org/netbeans/mdr/"/>
179
        <include name="org/netbeans/mdr/"/>
156
        <include name="javax/"/>
180
        <include name="javax/"/>
157
	<exclude name="org/netbeans/mdr/shell/"/>
181
	<exclude name="org/netbeans/mdr/shell/"/>
Lines 165-171 Link Here
165
    <locjar jarfile="apps/mdrshell.jar"
189
    <locjar jarfile="apps/mdrshell.jar"
166
            compress="false">
190
            compress="false">
167
      <locale name="ja"/>
191
      <locale name="ja"/>
168
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
192
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
169
        <include name="org/netbeans/mdr/shell/"/>
193
        <include name="org/netbeans/mdr/shell/"/>
170
      </fileset>
194
      </fileset>
171
    </locjar>
195
    </locjar>
Lines 173-179 Link Here
173
    <locjar jarfile="netbeans/modules/ext/jmiutils.jar"
197
    <locjar jarfile="netbeans/modules/ext/jmiutils.jar"
174
            compress="false">
198
            compress="false">
175
      <locale name="ja"/>
199
      <locale name="ja"/>
176
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
200
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
177
        <include name="org/netbeans/lib/jmi/"/>
201
        <include name="org/netbeans/lib/jmi/"/>
178
      </fileset>
202
      </fileset>
179
    </locjar>
203
    </locjar>
Lines 186-192 Link Here
186
            compress="false"             
210
            compress="false"             
187
            manifest="manifest-mdr-subst.mf">
211
            manifest="manifest-mdr-subst.mf">
188
      <locale name="ja"/>
212
      <locale name="ja"/>
189
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
213
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
190
        <include name="org/netbeans/modules/mdr/"/>	
214
        <include name="org/netbeans/modules/mdr/"/>	
191
      </fileset>
215
      </fileset>
192
    </locjar>
216
    </locjar>
Lines 195-201 Link Here
195
            compress="false"             
219
            compress="false"             
196
            manifest="manifest-toolkit-subst.mf">
220
            manifest="manifest-toolkit-subst.mf">
197
      <locale name="ja"/>
221
      <locale name="ja"/>
198
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
222
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
199
        <include name="org/netbeans/modules/mdrtoolkit/"/>	
223
        <include name="org/netbeans/modules/mdrtoolkit/"/>	
200
      </fileset>
224
      </fileset>
201
    </locjar>
225
    </locjar>
Lines 205-217 Link Here
205
            compress="false"
229
            compress="false"
206
            manifest="manifest-mdrapi-subst.mf">
230
            manifest="manifest-mdrapi-subst.mf">
207
      <locale name="ja"/>
231
      <locale name="ja"/>
208
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
232
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
209
        <include name="org/netbeans/api/"/>
233
        <include name="org/netbeans/api/"/>
210
      </fileset>
234
      </fileset>
211
    </locjar>
235
    </locjar>
212
  </target>
236
  </target>
213
237
214
  <target name="explorer-jar" depends="compile-explorer">
238
  <target name="explorer-jar" depends="compile-explorer, init">
215
  
239
  
216
    <filter token="BUILD_NUMBER_SUBST" value="${buildnumber}"/>
240
    <filter token="BUILD_NUMBER_SUBST" value="${buildnumber}"/>
217
    <copy file="manifest-explorer.mf" filtering="on" tofile="manifest-explorer-subst.mf"/> 
241
    <copy file="manifest-explorer.mf" filtering="on" tofile="manifest-explorer-subst.mf"/> 
Lines 220-235 Link Here
220
      compress="false"             
244
      compress="false"             
221
      manifest="manifest-explorer-subst.mf">
245
      manifest="manifest-explorer-subst.mf">
222
      <locale name="ja"/>
246
      <locale name="ja"/>
223
      <fileset dir="src" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt">
247
      <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
224
        <include name="org/netbeans/modules/mdrexplorer/"/>	
248
        <include name="org/netbeans/modules/mdrexplorer/"/>	
225
      </fileset>
249
      </fileset>
226
    </locjar>
250
    </locjar>
227
    
251
    
228
  </target>
252
  </target>
229
253
230
  <!-- ===================== -->
254
  <!-- =========================================================== -->
231
  <!-- MDR-Explorer target   -->
255
  <!-- == MDR-Explorer target =================================== -->
232
  <!-- ===================== -->
256
  <!-- =========================================================== -->
257
233
  <target name="mdrexplorer" depends="explorer-jar">
258
  <target name="mdrexplorer" depends="explorer-jar">
234
  </target>
259
  </target>
235
260
Lines 238-246 Link Here
238
      <!--genlist targetname="nbm" outputfiledir="${nbroot}/nbbuild/netbeans"/-->
263
      <!--genlist targetname="nbm" outputfiledir="${nbroot}/nbbuild/netbeans"/-->
239
  </target>
264
  </target>
240
265
241
  <!-- ================= -->
266
  <!-- =========================================================== -->
242
  <!-- Production of NBM -->
267
  <!-- == Production of NBM ====================================== -->
243
  <!-- ================= -->
268
  <!-- =========================================================== -->
269
244
  <target name="nbm" depends="toolkit-nbm,mdr-nbm,jmi-nbm,mof-nbm,mdrapi-nbm"/>
270
  <target name="nbm" depends="toolkit-nbm,mdr-nbm,jmi-nbm,mof-nbm,mdrapi-nbm"/>
245
    
271
    
246
  <target name="mdrapi-nbm" depends="netbeans">
272
  <target name="mdrapi-nbm" depends="netbeans">
Lines 255-261 Link Here
255
             module="netbeans/modules/autoload/mdrapi.jar"
281
             module="netbeans/modules/autoload/mdrapi.jar"
256
	     homepage="http://mdr.${homepage.base}/"
282
	     homepage="http://mdr.${homepage.base}/"
257
	     distribution="http://${dist.base}/mdrapi.nbm">
283
	     distribution="http://${dist.base}/mdrapi.nbm">
258
      <license file="${nbroot}/nbbuild/standard-nbm-license.txt"/>
284
      <license file="${standard-nbm-license.txt}"/>
259
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
285
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
260
    </makenbm>
286
    </makenbm>
261
  </target>
287
  </target>
Lines 272-278 Link Here
272
             module="netbeans/modules/mdrtoolkit.jar"
298
             module="netbeans/modules/mdrtoolkit.jar"
273
	     homepage="http://mdr.${homepage.base}/"
299
	     homepage="http://mdr.${homepage.base}/"
274
	     distribution="http://${dist.base}/mdrtoolkit.nbm">
300
	     distribution="http://${dist.base}/mdrtoolkit.nbm">
275
      <license file="${nbroot}/nbbuild/standard-nbm-license.txt"/>
301
      <license file="${standard-nbm-license.txt}"/>
276
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
302
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
277
    </makenbm>
303
    </makenbm>
278
  </target>
304
  </target>
Lines 283-289 Link Here
283
             module="netbeans/modules/mdr.jar"
309
             module="netbeans/modules/mdr.jar"
284
	     homepage="http://mdr.${homepage.base}/"
310
	     homepage="http://mdr.${homepage.base}/"
285
	     distribution="http://${dist.base}/mdr.nbm">
311
	     distribution="http://${dist.base}/mdr.nbm">
286
      <license file="${nbroot}/nbbuild/standard-nbm-license.txt"/>
312
      <license file="${standard-nbm-license.txt}"/>
287
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
313
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
288
      <exclude name="netbeans/modules/mdrtoolkit.jar"/>
314
      <exclude name="netbeans/modules/mdrtoolkit.jar"/>
289
      <exclude name="netbeans/modules/mdrexplorer.jar"/>
315
      <exclude name="netbeans/modules/mdrexplorer.jar"/>
Lines 332-338 Link Here
332
			 module="netbeans/modules/mdrexplorer.jar"
358
			 module="netbeans/modules/mdrexplorer.jar"
333
			 homepage="http://mdr.${homepage.base}/"
359
			 homepage="http://mdr.${homepage.base}/"
334
			 distribution="http://${dist.base}/mdrexplorer.nbm">
360
			 distribution="http://${dist.base}/mdrexplorer.nbm">
335
		<license file="${nbroot}/nbbuild/standard-nbm-license.txt"/>
361
		<license file="${standard-nbm-license.txt}"/>
336
        <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
362
        <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
337
363
338
	</makenbm>
364
	</makenbm>
Lines 388-396 Link Here
388
    <zip zipfile="MdrAPIs.zip" basedir="MdrAPIs"/>
414
    <zip zipfile="MdrAPIs.zip" basedir="MdrAPIs"/>
389
  </target>
415
  </target>
390
416
391
  <!-- ======================= -->
417
  <!-- =========================================================== -->
392
  <!-- Cleaning compiled stuff -->
418
  <!-- == Cleaning compiled stuff ================================ -->
393
  <!-- ======================= -->
419
  <!-- =========================================================== -->
420
394
  <target name="clean" description="Removes all build products.">
421
  <target name="clean" description="Removes all build products.">
395
    <delete>
422
    <delete>
396
      <fileset dir="src">
423
      <fileset dir="src">
(-)src/org/netbeans/api/mdr/MDRepository.java (+10 lines)
Lines 63-68 Link Here
63
     */
63
     */
64
    public String[] getExtentNames();
64
    public String[] getExtentNames();
65
65
66
    /**
67
     * Returns the object with the given MOF ID.
68
     *
69
     * @param mofId the MOF ID of the object to be returned
70
     * @return the object with the given MOF ID
71
     * @throws java.util.NoSuchElementException if there is no object with
72
     *         the given MOF ID
73
     */
74
    public RefBaseObject getByMofId(String mofId);
75
    
66
    /** Starts a new transaction. This method causes that the repository will be locked
76
    /** Starts a new transaction. This method causes that the repository will be locked
67
     * for read-only access or exclusive write access (depending on the value passed as
77
     * for read-only access or exclusive write access (depending on the value passed as
68
     * a parameter) and starts a new transaction. It is prefered to enclose any batch
78
     * a parameter) and starts a new transaction. It is prefered to enclose any batch
(-)src/org/netbeans/api/mdr/events/AttributeEvent.java (-4 / +4 lines)
Lines 28-40 Link Here
28
    /** Bitmask representing all event types related to classifier attribute changes */
28
    /** Bitmask representing all event types related to classifier attribute changes */
29
    public static final int EVENTMASK_CLASSATTR = 0x102FFFF;
29
    public static final int EVENTMASK_CLASSATTR = 0x102FFFF;
30
    
30
    
31
    /** Event type indicating that a value of a single-valued attribute is to be/was changed or
31
    /** Event type indicating that a value of a single-valued instance attribute is to be/was changed or
32
     * a value element of a multi-valued attribute is to be/was changed.
32
     * a value element of a multi-valued instance attribute is to be/was changed.
33
     */
33
     */
34
    public static final int EVENT_ATTRIBUTE_SET = 0x1010001;
34
    public static final int EVENT_ATTRIBUTE_SET = 0x1010001;
35
    /** Event type indicating that a value element of a multi-valued attribute is to be/was added */
35
    /** Event type indicating that a value element of a multi-valued instance attribute is to be/was added */
36
    public static final int EVENT_ATTRIBUTE_ADD = 0x1010002;
36
    public static final int EVENT_ATTRIBUTE_ADD = 0x1010002;
37
    /** Event type indicating that a value element of a multi-valued attribute is to be/was removed */
37
    /** Event type indicating that a value element of a multi-valued instance attribute is to be/was removed */
38
    public static final int EVENT_ATTRIBUTE_REMOVE = 0x1010004;
38
    public static final int EVENT_ATTRIBUTE_REMOVE = 0x1010004;
39
39
40
    /** Event type indicating that a value of a single-valued classifier attribute is to be/was changed or
40
    /** Event type indicating that a value of a single-valued classifier attribute is to be/was changed or
(-)src/org/netbeans/api/mdr/events/MDRChangeEvent.java (+24 lines)
Lines 22-33 Link Here
22
 * This way the event listeners can filter the events using a bitmask.
22
 * This way the event listeners can filter the events using a bitmask.
23
 *
23
 *
24
 * @author Martin Matula
24
 * @author Martin Matula
25
 * @author <a href="mailto:hkrug@rationalizer.com">Holger Krug</code>.
25
 */
26
 */
26
public abstract class MDRChangeEvent extends EventObject {
27
public abstract class MDRChangeEvent extends EventObject {
27
    /** Bitmask representing all possible repository event types.
28
    /** Bitmask representing all possible repository event types.
28
     * Can be used for registering listener to receive all kinds of events.
29
     * Can be used for registering listener to receive all kinds of events.
29
     */
30
     */
30
    public static final int EVENTMASK_ALL = 0x0FFFFFFF;
31
    public static final int EVENTMASK_ALL = 0x0FFFFFFF;
32
    
33
    /** Bitmask representing all event types which are initially fired on
34
     * associations. */
35
    public static final int EVENTMASK_ON_ASSOCIATION = AssociationEvent.EVENTMASK_ASSOCIATION;
36
    /** Bitmask representing all event types which are initially fired on
37
     * instance objects. */
38
    public static final int EVENTMASK_ON_INSTANCE = InstanceEvent.EVENT_INSTANCE_CREATE | AttributeEvent.EVENTMASK_ATTRIBUTE;
39
    /** Bitmask representing all event types which are initially fired on
40
     * class proxies. */
41
    public static final int EVENTMASK_ON_CLASS = InstanceEvent.EVENT_INSTANCE_DELETE | AttributeEvent.EVENTMASK_CLASSATTR;
42
    /** Bitmask representing all event types which are initially fired on
43
     * package proxies.
44
     *
45
     * <p><em>Note:</em> This bitmask is empty, because there are not
46
     * events which originate on packages. Packages receive only events
47
     * propagated from other objects. As a consequence this bitmask is
48
     * useless. It is nevertheless part of the API to achieve greater
49
     * uniformity of the API.</p>
50
     */
51
    public static final int EVENTMASK_ON_PACKAGE = 0x0000000;
52
    /** Bitmask representing all event types which are initially fired on
53
     * repositories. */
54
    public static final int EVENTMASK_ON_REPOSITORY = ExtentEvent.EVENTMASK_EXTENT | TransactionEvent.EVENTMASK_TRANSACTION;
31
55
32
    // event type
56
    // event type
33
    private final int eventType;
57
    private final int eventType;
(-)src/org/netbeans/api/mdr/events/MDRChangeSource.java (-8 / +39 lines)
Lines 18-51 Link Here
18
 * The objects that have to be registered for event
18
 * The objects that have to be registered for event
19
 * notifications need to implement {@link MDRChangeListener}
19
 * notifications need to implement {@link MDRChangeListener}
20
 * or {@link MDRPreChangeListener} interface.<p>
20
 * or {@link MDRPreChangeListener} interface.<p>
21
 * The repository should distribute all the events in the following way:
21
 *
22
 * <p>The repository distributes all the events recursively in the following way:
22
 * <ul>
23
 * <ul>
23
 * <li>Each event fired on an instance is also fired on the corresponding class proxy for this instance.
24
 * <li>Event fired on an instance are also fired on the corresponding class proxy for this instance.
24
 * <li>Events fired on a class proxy are propagated to its immediate package proxy.
25
 * <li>Events fired on a class proxy are propagated to its immediate package proxy.
25
 * <li>Events fired on an association proxy are fired on all the instances affected by this event 
26
 * <li>Events fired on an association proxy are fired on all the instances affected by this event 
26
 * (e.g. instances added/removed from a link) and also it is fired on the immediate package proxy.
27
 * (e.g. instances added/removed from a link) and also it is fired on the immediate package proxy.
27
 * <li>Each event fired on a package proxy are propagated to its immediate package proxy.
28
 * <li>Event fired on a package proxy are propagated to its immediate package proxy.
28
 * If the package proxy is outermost, the event is propagated to the MDRepository that contains
29
 * If the package proxy is outermost, the event is propagated to the MDRepository that contains
29
 * the proxy.
30
 * the proxy.
30
 * </ul>
31
 * </ul>
31
 * All the events are propagated recursively till they reach the repository object (e.g. each
32
 * Figure <b>XXX: MARTIN, PLEASE ADD THE FIGURE, I'VE CREATED</b> shows where the
33
 * events are initially fired and how they propagate.
34
 * </p>
35
 *
36
 * <p>All the events are propagated recursively till they reach the repository object (e.g. each
32
 * instance event is as a result of propagation always fired on the instance itself,
37
 * instance event is as a result of propagation always fired on the instance itself,
33
 * on its class proxy, on its immediate package proxy, on all other package proxies containing
38
 * on its class proxy, on its immediate package proxy, on all other package proxies containing
34
 * the immediate package proxy to the outermost package proxy and at the end on the repository containing
39
 * the immediate package proxy to the outermost package proxy and at the end on the repository containing
35
 * instance).<br>
40
 * instance).</p>
36
 * In addition, any event is fired only once for each listener (so no matter how many objects 
41
 *
42
 * <p>In addition, any event is fired only once for each listener (so no matter how many objects 
37
 * on the event's propagation path is a listener registered on - e.g. on both
43
 * on the event's propagation path is a listener registered on - e.g. on both
38
 * class proxy and its instances - it receives each notification only once per event). 
44
 * class proxy and its instances - it receives each notification only once per event).</p>
45
 *
46
 * <p>Listeners may be added specifically for certain events only by calling
47
 * {@link #addListener(MDRChangeListener, int) addListener(MDRChangeListener, int)}.
48
 * If instead {@link #addListener(MDRChangeListener) addListener(MDRChangeListener)}
49
 * is used for listener addition and, hence, no event mask is speficied, the listener
50
 * receives all events which are propagated to the source it is registered for.
39
 *
51
 *
40
 * @author Martin Matula
52
 * @author Martin Matula
53
 * @author <a href="mailto:hkrug@rationalizer.com">Holger Krug</code>.
41
 */
54
 */
42
public interface MDRChangeSource {
55
public interface MDRChangeSource {
43
    /** Registers a listener for receiving event notifications.
56
    
57
    /** Registers a listener for receiving event notifications using the default
58
     *  event mask. The default event mask depends on the type of the change source
59
     *  and filters all events which are initially fired on this object.
44
     * @param listener Object that implements {@link MDRChangeListener} interface.
60
     * @param listener Object that implements {@link MDRChangeListener} interface.
45
     */    
61
     */    
46
    public void addListener(MDRChangeListener listener);
62
    public void addListener(MDRChangeListener listener);
63
    /** Registers a listener for receiving notifications about events the type
64
     *  of which matches <code>mask</code>.
65
     * @param listener Object that implements {@link MDRChangeListener} interface.
66
     * @param eventMask bitmask to be used in a call to {@link MdrChangeEvent#isOfType()}
67
     *    to filter events based on the mask
68
     */    
69
    public void addListener(MDRChangeListener listener, int mask);
47
    /** Removes listener from the list of objects registered for events notifications.
70
    /** Removes listener from the list of objects registered for events notifications.
48
     * @param listener Object that implements {@link MDRChangeListener} interface.
71
     * @param listener Object that implements {@link MDRChangeListener} interface.
49
     */    
72
     */    
50
    public void removeListener(MDRChangeListener listener);
73
    public void removeListener(MDRChangeListener listener);
74
    /** Removes listener only for events of types matching <code>mask</code>.
75
     * If a listener is additionally registered for events of other types, it
76
     * proceeds listening on the remaining event types.
77
     * @param listener Object that implements {@link MDRChangeListener} interface.
78
     * @param mask determines the types of events the listener shall stop
79
     *   to listen on
80
     */    
81
    public void removeListener(MDRChangeListener listener, int mask);
51
}
82
}
(-)src/org/netbeans/api/mdr/events/TransactionEvent.java (+42 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.api.mdr.events;
14
15
import javax.jmi.reflect.RefFeatured;
16
import org.netbeans.api.mdr.MDRepository;
17
18
/** Class representing MDR events related to start, commit and
19
 * rollback of write transactions.
20
 *
21
 * @author <a href="mailto:hkrug@rationalizer.com">Holger Krug</code>.
22
 */
23
public class TransactionEvent extends MDRChangeEvent {
24
    
25
    /** Bitmask representing all event types related to write transactions */
26
    public static final int EVENTMASK_TRANSACTION = 0x011FFFF;
27
    
28
    /** Event type indicating that a write transaction has been started. */
29
    public static final int EVENT_TRANSACTION_START = 0x0110001;
30
    /** Event type indicating that a write transaction has been committed. */
31
    public static final int EVENT_TRANSACTION_COMMIT = 0x0110002;
32
    /** Event type indicating that a write transaction has been rolled back. */
33
    public static final int EVENT_TRANSACTION_ROLLBACK = 0x0110004;
34
35
    /** Creates new <code>TransactionEvent</code> instance. 
36
     * @param source the event source, an instance of <code>MDRepository</code>.
37
     * @param type the event type.
38
     */
39
    public TransactionEvent(MDRepository source, int type) {
40
        super(source, type);
41
    }
42
}
(-)src/org/netbeans/mdr/NBMDRepositoryImpl.java (-238 / +335 lines)
Lines 1-11 Link Here
1
/*
1
/*
2
 *                 Sun Public License Notice
2
 *                 Sun Public License Notice
3
 * 
3
 *
4
 * The contents of this file are subject to the Sun Public License
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
Lines 42-49 Link Here
42
    /* -------------------------------------------------------------------- */
42
    /* -------------------------------------------------------------------- */
43
    /* -- Private static constants ---------------------------------------- */
43
    /* -- Private static constants ---------------------------------------- */
44
    /* -------------------------------------------------------------------- */
44
    /* -------------------------------------------------------------------- */
45
45
    
46
//    private static final Collection instances = new HashSet();
46
    //    private static final Collection instances = new HashSet();
47
    
47
    
48
    private static final URL MOF_XML_URL = ModelPackage.class.getResource("resources/mof.xml");
48
    private static final URL MOF_XML_URL = ModelPackage.class.getResource("resources/mof.xml");
49
    private static final URL BOOTMOF_XML_URL = ModelPackage.class.getResource("resources/mof.xml");
49
    private static final URL BOOTMOF_XML_URL = ModelPackage.class.getResource("resources/mof.xml");
Lines 55-76 Link Here
55
    private static final String INTERCEPTABLE_TAG_ID = "org.netbeans.mdr.interceptable";
55
    private static final String INTERCEPTABLE_TAG_ID = "org.netbeans.mdr.interceptable";
56
    private static final String TRANSIENT_TAG_ID = "org.netbeans.mdr.transient";
56
    private static final String TRANSIENT_TAG_ID = "org.netbeans.mdr.transient";
57
    private static final String TAG_VALUE_TRUE = "true";
57
    private static final String TAG_VALUE_TRUE = "true";
58
58
    
59
    public static final String BOOT_MOF = "BootMOF";
59
    public static final String BOOT_MOF = "BootMOF";
60
    public static final String PURE_MOF = "MOF";
60
    public static final String PURE_MOF = "MOF";
61
61
    
62
    /* -------------------------------------------------------------------- */
62
    /* -------------------------------------------------------------------- */
63
    /* -- Private attributes ---------------------------------------------- */
63
    /* -- Private attributes ---------------------------------------------- */
64
    /* -------------------------------------------------------------------- */
64
    /* -------------------------------------------------------------------- */
65
   
65
    
66
    private MdrStorage mdrStorage = null;
66
    private MdrStorage mdrStorage = null;
67
67
    
68
    private Map classProxies = null;
68
    private Map classProxies = null;
69
    private Map associationProxies = null;
69
    private Map associationProxies = null;
70
    private Map classProxiesMofIds = null;    
70
    private Map classProxiesMofIds = null;
71
71
72
    private final Map parameters;
72
    private final Map parameters;
73
73
    
74
    /* --------------------------------------------------------------------- */
74
    /* --------------------------------------------------------------------- */
75
    /* -- Constructors ----------------------------------------------------- */
75
    /* -- Constructors ----------------------------------------------------- */
76
    /* --------------------------------------------------------------------- */
76
    /* --------------------------------------------------------------------- */
Lines 95-112 Link Here
95
     *     <td>storage location</td>
95
     *     <td>storage location</td>
96
     *   </tr>
96
     *   </tr>
97
     * </table>
97
     * </table>
98
     *
99
     */
98
     */
100
    public NBMDRepositoryImpl () {
99
//     * <p>Additionally the following properties allow to replace parts
100
//     *  of the MDR implementation by tailor-made classes, namely the base classes
101
//     *  for generated handler classes. This is an experimental feature, use
102
//     *  it with care. Currently no documentation is available about the features
103
//     *  the replacing classes must provide in order to cooperate with the generated code:</p>
104
//     *
105
//     * <table border cellspacing="1" cellpadding="2">
106
//     *   <tr>
107
//     *     <td><code>org.netbeans.mdr.handlers.PackageProxyHandler</code></td>
108
//     *     <td>(no default)</td>
109
//     *     <td>fully qualified name of the class replacing <code>PackageProxyHandler</code>
110
//     *         as base class for package proxy implementations</td>
111
//     *   </tr>
112
//     *   <tr>
113
//     *     <td><code>org.netbeans.mdr.handlers.ClassProxyHandler</code></td>
114
//     *     <td>(no default)</td>
115
//     *     <td>fully qualified name of the class replacing <code>ClassProxyHandler</code>
116
//     *         as default base class for class proxy implementations</td>
117
//     *   </tr>
118
//     *   <tr>
119
//     *     <td><code>org.netbeans.mdr.handlers.InstanceHandler</code></td>
120
//     *     <td>(no default)</td>
121
//     *     <td>fully qualified name of the class replacing <code>InstanceHandler</code>
122
//     *         as default base class for instance implementations</td>
123
//     *   </tr>
124
//     *   <tr>
125
//     *     <td><code>org.netbeans.mdr.handlers.AssociationHandler</code></td>
126
//     *     <td>(no default)</td>
127
//     *     <td>fully qualified name of the class replacing <code>AssociationHandler</code>
128
//     *         as default base class for association implementations</td>
129
//     *   </tr>
130
//     *   <tr>
131
//     *     <td><code>org.netbeans.mdr.handlers.StructureHandler</code></td>
132
//     *     <td>(no default)</td>
133
//     *     <td>fully qualified name of the class replacing <code>StructImpl</code>
134
//     *         as base class for structure implementations</td>
135
//     *   </tr>
136
//     * </table>
137
//     *
138
//     */
139
    public NBMDRepositoryImpl() {
101
        System.out.println("using default values...");
140
        System.out.println("using default values...");
102
141
        
103
        String storageClass = System.getProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory");
142
        String storageClass = System.getProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory");
104
        String storageFile = System.getProperty("org.netbeans.mdr.persistence.Dir");
143
        String storageFile = System.getProperty("org.netbeans.mdr.persistence.Dir");
105
144
//        String packageProxyHandler = System.getProperty("org.netbeans.mdr.handlers.PackageProxyHandler");
145
//        String classProxyHandler = System.getProperty("org.netbeans.mdr.handlers.ClassProxyHandler");
146
//        String instanceHandler = System.getProperty("org.netbeans.mdr.handlers.InstanceHandler");
147
//        String associationHandler = System.getProperty("org.netbeans.mdr.handlers.AssociationHandler");
148
//        String structureHandler = System.getProperty("org.netbeans.mdr.handlers.StructureHandler");
149
        
106
        parameters = new HashMap();
150
        parameters = new HashMap();
107
        parameters.put("storage", storageClass);
151
        parameters.put("storage", storageClass);
108
        parameters.put(org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory.STORAGE_FILE_NAME, storageFile);
152
        parameters.put(org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory.STORAGE_FILE_NAME, storageFile);
109
//        instances.add(this);
153
//        if ( packageProxyHandler != null ) parameters.put("PackageProxyHandler", packageProxyHandler);
154
//        if ( classProxyHandler != null ) parameters.put("ClassProxyHandler", classProxyHandler);
155
//        if ( instanceHandler != null ) parameters.put("InstanceHandler", instanceHandler);
156
//        if ( associationHandler != null ) parameters.put("AssociationHandler", associationHandler);
157
//        if ( structureHandler != null ) parameters.put("StructureHandler", structureHandler);
158
        //        instances.add(this);
110
    }
159
    }
111
    
160
    
112
    /** Creates new {@link org.netbeans.api.mdr.MDRepository} with given parameters.
161
    /** Creates new {@link org.netbeans.api.mdr.MDRepository} with given parameters.
Lines 116-150 Link Here
116
     *    <li><code>storage</code>: name of a class implementing {@link
165
     *    <li><code>storage</code>: name of a class implementing {@link
117
     *          org.netbeans.mdr.persistence.StorageFactory}</li>
166
     *          org.netbeans.mdr.persistence.StorageFactory}</li>
118
     *    <li><code>fileName</code>: storage location</li>
167
     *    <li><code>fileName</code>: storage location</li>
119
     *  </ol>
168
     *   </ol></p>
120
     *
121
     */
169
     */
170
//     * <p>Additionally the following parameters allow to replace parts
171
//     *  of the MDR implementation by tailor-made classes, namely the base classes
172
//     *  for generated handler classes. This is an experimental feature, use
173
//     *  it with care. Currently no documentation is available about the features
174
//     *  the replacing classes must provide in order to cooperate with the generated code:</p>
175
//     *
176
//     *   <p><ol>
177
//     *    <li><code>PackageProxyHandler</code>: fully qualified name of the super-class
178
//     *              for package proxy implementations (default:
179
//     *              <code>org.netbeans.mdr.handler.PackageProxyHandler</code>)</li>
180
//     *    <li><code>ClassProxyHandler</code>: fully qualified name of the default super-class
181
//     *              for class proxy implementations (default:
182
//     *              <code>org.netbeans.mdr.handler.ClassProxyHandler</code>)</li>
183
//     *    <li><code>InstanceHandler</code>: fully qualified name of the default super-class
184
//     *              for instance implementations (default:
185
//     *              <code>org.netbeans.mdr.handler.InstanceHandler</code>)</li>
186
//     *    <li><code>AssociationHandler</code>: fully qualified name of the default super-class
187
//     *              for assocation proxy implementations (default:
188
//     *              <code>org.netbeans.mdr.handler.AssociationHandler</code>)</li>
189
//     *    <li><code>StructureHandler</code>: fully qualified name of the super-class
190
//     *              for structure implementations (default:
191
//     *              <code>org.netbeans.mdr.handler.StructImpl</code>)</li>
192
//     *  </ol></p>
193
//     *
194
//     */
122
    public NBMDRepositoryImpl(Map parameters) {
195
    public NBMDRepositoryImpl(Map parameters) {
123
        Log.out.println("Creating MDRepository implementation ...");
196
        Log.out.println("Creating MDRepository implementation ...");
124
        this.parameters = parameters;
197
        this.parameters = parameters;
125
//        instances.add(this);
198
        //        instances.add(this);
126
    }
199
    }
127
200
    
128
    /* -------------------------------------------------------------------- */
201
    /* -------------------------------------------------------------------- */
129
    /* -- Implementation of org.netbeans.api.mdr.event.MDRChangeSource ---- */
202
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
130
    /* -------------------------------------------------------------------- */
203
    /* -------------------------------------------------------------------- */
131
    
204
    
132
    /** Registers a listener for receiving event notifications.
205
    /** Registers a listener for receiving event notifications with are
133
     * @param listener Object that implements {@link Listener} interface.
206
     *  initially fired on this object.
207
     * @param listener Object that implements {@link MDRChangeListener} interface.
134
     */
208
     */
135
    public void addListener(MDRChangeListener listener) {
209
    public void addListener(MDRChangeListener listener) {
210
        addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
211
    }
212
    
213
    /** Registers a listener for receiving event notifications.
214
     * @param listener Object that implements {@link MDRChangeListener} interface.
215
     * @param mask bitmask to filter types of events the listener listens on
216
     */
217
    public void addListener(MDRChangeListener listener, int mask) {
136
        initCheck();
218
        initCheck();
137
        mdrStorage.getEventNotifier().REPOSITORY.addListener(listener, mdrStorage);
219
        mdrStorage.getEventNotifier().REPOSITORY.addListener(listener, mask, mdrStorage);
138
    }
220
    }
139
    
221
    
140
    /** Removes listener from the list of objects registered for events notifications.
222
    /** Removes listener from the list of objects registered for event notifications.
141
     * @param listener Object that implements {@link Listener} interface.
223
     * @param listener Object that implements {@link MDRChangeListener} interface.
142
     */
224
     */
143
    public void removeListener(MDRChangeListener listener) {
225
    public void removeListener(MDRChangeListener listener) {
144
        initCheck();
226
        initCheck();
145
        mdrStorage.getEventNotifier().REPOSITORY.removeListener(listener, mdrStorage);
227
        mdrStorage.getEventNotifier().REPOSITORY.removeListener(listener, mdrStorage);
146
    }
228
    }
147
229
    
230
    /** Removes listener from the list of objects registered for event notifications.
231
     * @param listener Object that implements {@link MDRChangeListener} interface.
232
     * @param mask determines type of the events the listeners stops to listen on
233
     */
234
    public void removeListener(MDRChangeListener listener, int mask) {
235
        initCheck();
236
        mdrStorage.getEventNotifier().REPOSITORY.removeListener(listener, mask, mdrStorage);
237
    }
238
    
148
    /* -------------------------------------------------------------------- */
239
    /* -------------------------------------------------------------------- */
149
    /* -- Implementation of org.netbeans.api.mdr.MDRepositry -------------- */
240
    /* -- Implementation of org.netbeans.api.mdr.MDRepositry -------------- */
150
    /* -------------------------------------------------------------------- */
241
    /* -------------------------------------------------------------------- */
Lines 163-174 Link Here
163
        initCheck();
254
        initCheck();
164
        mdrStorage.getRepositoryMutex().leave(rollback);
255
        mdrStorage.getRepositoryMutex().leave(rollback);
165
    }
256
    }
166
257
    
167
    /** Instantiates the MOF model package.
258
    /** Instantiates the MOF model package.
168
     *
259
     *
169
     *  @param substName the name of the new model
260
     *  @param substName the name of the new model
170
     */
261
     */
171
     public RefPackage createExtent(String substName) throws CreationFailedException {
262
    public RefPackage createExtent(String substName) throws CreationFailedException {
172
        return createExtent(substName, null);
263
        return createExtent(substName, null);
173
    }
264
    }
174
    
265
    
Lines 191-199 Link Here
191
     *           package.
282
     *           package.
192
     *  @param existingInstances
283
     *  @param existingInstances
193
     */
284
     */
194
    public RefPackage createExtent (String substName, RefObject metaPackage, RefPackage[] existingInstances) throws CreationFailedException {   
285
    public RefPackage createExtent(String substName, RefObject metaPackage, RefPackage[] existingInstances) throws CreationFailedException {
195
        return createExtent (substName, metaPackage, existingInstances, null);
286
        return createExtent(substName, metaPackage, existingInstances, null);
196
    } 
287
    }
197
    
288
    
198
    /** Returns reference to an outermost package instance of a given name.
289
    /** Returns reference to an outermost package instance of a given name.
199
     * @param name name of package instance to be returned
290
     * @param name name of package instance to be returned
Lines 202-213 Link Here
202
     */
293
     */
203
    public RefPackage getExtent(String name) {
294
    public RefPackage getExtent(String name) {
204
        StorablePackage pkg;
295
        StorablePackage pkg;
205
296
        
206
        initCheck();
297
        initCheck();
207
298
        
208
        try {
299
        try {
209
            beginTrans(false);
300
            beginTrans(false);
210
301
            
211
            try {
302
            try {
212
                // retrieve the package
303
                // retrieve the package
213
                pkg = (StorablePackage) mdrStorage.getContextOutermostPackage(name);
304
                pkg = (StorablePackage) mdrStorage.getContextOutermostPackage(name);
Lines 233-239 Link Here
233
     */
324
     */
234
    public String[] getExtentNames() {
325
    public String[] getExtentNames() {
235
        initCheck();
326
        initCheck();
236
327
        
237
        String result[] = new String[0];
328
        String result[] = new String[0];
238
        try {
329
        try {
239
            beginTrans(false);
330
            beginTrans(false);
Lines 246-252 Link Here
246
            endTrans();
337
            endTrans();
247
        }
338
        }
248
    }
339
    }
249
    
340
341
    /**
342
     * Returns the object with the given <code>mofId</code>.
343
     */
344
    public RefBaseObject getByMofId(String mofId) {
345
        initCheck();
346
        try {
347
            beginTrans(false);
348
            StorableBaseObject storable = mdrStorage.getObject(mofId);
349
            if ( storable == null ) {
350
                throw new NoSuchElementException("No object with MOF ID: " + mofId);
351
            } else {
352
                return BaseObjectHandler.getHandler(storable);
353
            }
354
        } catch (StorageException e) {
355
            e.printStackTrace();
356
            throw new DebugException();
357
        } finally {
358
            endTrans();
359
        }
360
    }
361
     
250
    /**
362
    /**
251
     * Called on repository exit. Should perform all needed finalization actions.
363
     * Called on repository exit. Should perform all needed finalization actions.
252
     */
364
     */
Lines 261-276 Link Here
261
            }
373
            }
262
        }
374
        }
263
    }
375
    }
264
376
    
265
    /* -------------------------------------------------------------------- */
377
    /* -------------------------------------------------------------------- */
266
    /* -- Extending java.lang.Object -------------------------------------- */
378
    /* -- Extending java.lang.Object -------------------------------------- */
267
    /* -------------------------------------------------------------------- */   
379
    /* -------------------------------------------------------------------- */
268
    
380
    
269
    public String toString() {
381
    public String toString() {
270
        StringBuffer sb = new StringBuffer("IDE MOF Repository");
382
        StringBuffer sb = new StringBuffer("IDE MOF Repository");
271
        return sb.toString();
383
        return sb.toString();
272
    }
384
    }
273
385
    
274
    /* -------------------------------------------------------------------- */
386
    /* -------------------------------------------------------------------- */
275
    /* -- Create an outermost package instance ---------------------------- */
387
    /* -- Create an outermost package instance ---------------------------- */
276
    /* -------------------------------------------------------------------- */
388
    /* -------------------------------------------------------------------- */
Lines 288-363 Link Here
288
        initCheck();
400
        initCheck();
289
        
401
        
290
        RefPackage result;
402
        RefPackage result;
291
403
        
292
        if (substName.equals(BOOT_MOF) && mdrStorage.isBooting()) {
404
        boolean fail = true;
293
            // instantiate BootMOF
405
        if (metaPackage == null) {
294
            // this piece of code does not need to be locked because it can be invoked
406
            metaPackage = getMOFModelPackage();
295
            // only during booting and the booting process itself runs in a locked session
407
        }
296
            // [PENDING] probably this code should be removed from here and put
408
        ExtentEvent event = new ExtentEvent(
297
            //    directly into installFakeMof()
409
            this,
298
            createBootMOF();
410
            ExtentEvent.EVENT_EXTENT_CREATE,
299
            result = getExtent(substName);
411
            substName,
300
            if (result == null) {
412
            metaPackage,
301
                throw new CreationFailedException("Fatal error during bootstrapping.");
413
            new ImmutableList(existingInstances)
414
        );
415
        
416
        try {
417
            beginTrans(true);
418
            mdrStorage.getEventNotifier().REPOSITORY.firePlannedChange(mdrStorage, event);
419
            Map instancesToCluster = new HashMap();
420
            
421
            // Traverse the metamodel containtment
422
            classProxies = new HashMap();
423
            associationProxies = new HashMap();
424
            classProxiesMofIds = new HashMap();
425
            
426
            if (existingInstances != null) {
427
                for (int i = 0; i < existingInstances.length; i++) {
428
                    collectPackageInstances(existingInstances[i], instancesToCluster);
429
                }
302
            }
430
            }
303
        } else {
304
            boolean fail = true;
305
            if (metaPackage == null) {
306
                metaPackage = getMOFModelPackage();
307
            }
308
            ExtentEvent event = new ExtentEvent(
309
                this, 
310
                ExtentEvent.EVENT_EXTENT_CREATE, 
311
                substName,
312
                metaPackage, 
313
                new ImmutableList(existingInstances)
314
            );
315
316
            try {
431
            try {
317
                beginTrans(true);
432
                instantiatePackage(substName, null, (MofPackage) metaPackage, instancesToCluster, storageId, false);
318
                mdrStorage.getEventNotifier().REPOSITORY.firePlannedChange(mdrStorage, event);
433
            } catch (RuntimeException e) {
319
                Map instancesToCluster = new HashMap();
434
                e.printStackTrace();
320
435
                throw new CreationFailedException("Cannot instantiate package because of unexpected exception: " + e);
321
                // Traverse the metamodel containtment
436
            }
322
                classProxies = new HashMap();
437
            
323
                associationProxies = new HashMap();
438
            classProxies = null;
324
                classProxiesMofIds = new HashMap();                
439
            associationProxies = null;
325
440
            classProxiesMofIds = null;
326
                if (existingInstances != null) {
441
            
327
                    for (int i = 0; i < existingInstances.length; i++) {
442
            result = getExtent(substName);
328
                        collectPackageInstances(existingInstances[i], instancesToCluster);
443
            if (result == null) {
329
                    }
444
                throw new CreationFailedException("Cannot find created package.");
330
                }
331
                try {
332
                    instantiatePackage(substName, null, (MofPackage) metaPackage, instancesToCluster, storageId, false);
333
                } catch (RuntimeException e) {
334
                    e.printStackTrace();
335
                    throw new CreationFailedException("Cannot instantiate package because of unexpected exception: " + e);
336
                }
337
338
                classProxies = null;
339
                associationProxies = null;
340
                classProxiesMofIds = null;
341
342
                result = getExtent(substName);
343
                if (result == null) {
344
                    throw new CreationFailedException("Cannot find created package.");
345
                }
346
347
                fail = false;
348
            } finally {
349
                endTrans(fail);
350
            }
445
            }
446
            
447
            fail = false;
448
        } finally {
449
            endTrans(fail);
351
        }
450
        }
352
451
        
353
        return result;
452
        return result;
354
    }
453
    }
355
454
    
356
    /* -------------------------------------------------------------------- */
455
    /* -------------------------------------------------------------------- */
357
    /* -- Storage partitions ---------------------------------------------- */
456
    /* -- Storage partitions ---------------------------------------------- */
358
    /* -------------------------------------------------------------------- */
457
    /* -------------------------------------------------------------------- */
359
   
458
    
360
    /** 
459
    /**
361
     *  Mounts new partition into current repository,
460
     *  Mounts new partition into current repository,
362
     *  The partition is created and initialized, if it does not exist.
461
     *  The partition is created and initialized, if it does not exist.
363
     *  @param String storageFactoryClass, name of storage factory class, which will create a new storage.
462
     *  @param String storageFactoryClass, name of storage factory class, which will create a new storage.
Lines 365-412 Link Here
365
     *  @return String id.
464
     *  @return String id.
366
     *  @exception MountFailedException thrown when mounting fails.
465
     *  @exception MountFailedException thrown when mounting fails.
367
     */
466
     */
368
    public String mountStorage (String storageFactoryClass, Map properties) throws MountFailedException {
467
    public String mountStorage(String storageFactoryClass, Map properties) throws MountFailedException {
369
        boolean failed = true;
468
        boolean failed = true;
370
        try {
469
        try {
371
            beginTrans (true);
470
            beginTrans(true);
372
            // Firing of event is done inside a MdrStorage mountStorage method
471
            // Firing of event is done inside a MdrStorage mountStorage method
373
            String storageId = this.mdrStorage.mountStorage (storageFactoryClass, properties);
472
            String storageId = this.mdrStorage.mountStorage(storageFactoryClass, properties);
374
            failed = false;
473
            failed = false;
375
            return storageId;
474
            return storageId;
376
        }catch (Exception e) {
475
        }catch (Exception e) {
377
            throw new MountFailedException ("Partition mount failed.", e);
476
            throw new MountFailedException("Partition mount failed.", e);
378
        }
477
        }
379
        finally {
478
        finally {
380
            endTrans (failed);
479
            endTrans(failed);
381
        }
480
        }
382
    }
481
    }
383
    
482
    
384
    /** 
483
    /**
385
     *  Umounts partition from current repository.
484
     *  Umounts partition from current repository.
386
     *  Umounting partition can affect validity of association links 
485
     *  Umounting partition can affect validity of association links
387
     *  which cross partitions. Module developer is responsible for
486
     *  which cross partitions. Module developer is responsible for
388
     *  either removing cross partition links or handling exceptions
487
     *  either removing cross partition links or handling exceptions
389
     *  caused by accessing these links.
488
     *  caused by accessing these links.
390
     *  @param String storageId, id of storage.
489
     *  @param String storageId, id of storage.
391
     */
490
     */
392
    public void umountStorage (String storageId) {
491
    public void umountStorage(String storageId) {
393
        boolean failed = true;
492
        boolean failed = true;
394
        try {
493
        try {
395
            beginTrans (true);
494
            beginTrans(true);
396
            Collection c = mdrStorage.getContexts (storageId);
495
            Collection c = mdrStorage.getContexts(storageId);
397
            for (Iterator it = c.iterator(); it.hasNext();) {
496
            for (Iterator it = c.iterator(); it.hasNext();) {
398
                String extentName = (String)it.next();
497
                String extentName = (String)it.next();
399
                RefPackage pkg = this.getExtent (extentName);
498
                RefPackage pkg = this.getExtent(extentName);
400
                ExtentEvent event = new ExtentEvent (pkg, ExtentEvent.EVENT_EXTENT_DELETE, extentName, pkg.refMetaObject(), null);
499
                ExtentEvent event = new ExtentEvent(pkg, ExtentEvent.EVENT_EXTENT_DELETE, extentName, pkg.refMetaObject(), null);
401
                this.mdrStorage.getEventNotifier().PACKAGE.firePlannedChange (pkg, event);
500
                this.mdrStorage.getEventNotifier().PACKAGE.firePlannedChange(pkg, event);
402
            }
501
            }
403
            this.mdrStorage.umountStorage (storageId);
502
            this.mdrStorage.umountStorage(storageId);
404
            failed = false;
503
            failed = false;
405
        }catch (StorageException e) {
504
        }catch (StorageException e) {
406
            throw new DebugException ("Umounting failed: "+e.toString());
505
            throw new DebugException("Umounting failed: "+e.toString());
407
        }
506
        }
408
        finally {
507
        finally {
409
            endTrans (failed);
508
            endTrans(failed);
410
        }
509
        }
411
    }
510
    }
412
    /* -------------------------------------------------------------------- */
511
    /* -------------------------------------------------------------------- */
Lines 419-425 Link Here
419
    public String getMOFInstanceName() {
518
    public String getMOFInstanceName() {
420
        return PURE_MOF;
519
        return PURE_MOF;
421
    }
520
    }
422
521
    
423
    /* -------------------------------------------------------------------- */
522
    /* -------------------------------------------------------------------- */
424
    /* -- Private helper methods ------------------------------------------ */
523
    /* -- Private helper methods ------------------------------------------ */
425
    /* -------------------------------------------------------------------- */
524
    /* -------------------------------------------------------------------- */
Lines 429-435 Link Here
429
    private MofPackage getMOFModelPackage() {
528
    private MofPackage getMOFModelPackage() {
430
        ModelPackage mofPackage = (ModelPackage) getExtent(getMOFInstanceName());
529
        ModelPackage mofPackage = (ModelPackage) getExtent(getMOFInstanceName());
431
        MofPackage result;
530
        MofPackage result;
432
531
        
433
        for (Iterator it = mofPackage.getMofPackage().refAllOfClass().iterator(); it.hasNext();) {
532
        for (Iterator it = mofPackage.getMofPackage().refAllOfClass().iterator(); it.hasNext();) {
434
            result = (MofPackage) it.next();
533
            result = (MofPackage) it.next();
435
            if (result.getName().equals("Model")) {
534
            if (result.getName().equals("Model")) {
Lines 440-446 Link Here
440
        return null;
539
        return null;
441
    }
540
    }
442
    
541
    
443
    /** 
542
    /**
444
     * Initializes the repository, if not already initialized: creates and
543
     * Initializes the repository, if not already initialized: creates and
445
     * initializes the {@link org.netbeans.mdr.storagemodel.MDRStorage}. If
544
     * initializes the {@link org.netbeans.mdr.storagemodel.MDRStorage}. If
446
     * necessary the repository is bootstrapped.
545
     * necessary the repository is bootstrapped.
Lines 448-454 Link Here
448
    private synchronized void initCheck() {
547
    private synchronized void initCheck() {
449
        if (mdrStorage == null) {
548
        if (mdrStorage == null) {
450
            String storageClass = (String) parameters.get(PARAM_STORAGE_CLASS);
549
            String storageClass = (String) parameters.get(PARAM_STORAGE_CLASS);
451
550
            
452
            mdrStorage = new MdrStorage(this, storageClass, this.parameters);
551
            mdrStorage = new MdrStorage(this, storageClass, this.parameters);
453
            try {
552
            try {
454
                System.out.println("initializing...");
553
                System.out.println("initializing...");
Lines 465-475 Link Here
465
            }
564
            }
466
        }
565
        }
467
    }
566
    }
468
567
    
469
    /* -------------------------------------------------------------------- */
568
    /* -------------------------------------------------------------------- */
470
    /* -- Helper methods for extent creation (private) -------------------- */
569
    /* -- Helper methods for extent creation (private) -------------------- */
471
    /* -------------------------------------------------------------------- */
570
    /* -------------------------------------------------------------------- */
472
       
571
    
473
    /**
572
    /**
474
     *  Helper method needed for the creation of a new outermost package instance.
573
     *  Helper method needed for the creation of a new outermost package instance.
475
     *  Puts <code>pkg</code> and, recursively, all its nested packages
574
     *  Puts <code>pkg</code> and, recursively, all its nested packages
Lines 480-488 Link Here
480
     *                   of their meta-objects as key
579
     *                   of their meta-objects as key
481
     *  @exception CreationFailedException if two different packages with the
580
     *  @exception CreationFailedException if two different packages with the
482
     *                same keys are added to <code>packages</code>
581
     *                same keys are added to <code>packages</code>
483
     *              
582
     *
484
      */
583
     */
485
     private void collectPackageInstances(RefPackage pkg, Map packages) throws CreationFailedException {
584
    private void collectPackageInstances(RefPackage pkg, Map packages) throws CreationFailedException {
486
        Object result = packages.put(pkg.refMetaObject().refMofId(), pkg);
585
        Object result = packages.put(pkg.refMetaObject().refMofId(), pkg);
487
        if (result != null && !result.equals(pkg)) {
586
        if (result != null && !result.equals(pkg)) {
488
            throw new CreationFailedException("The provided list of existing package instances contains duplicities.");
587
            throw new CreationFailedException("The provided list of existing package instances contains duplicities.");
Lines 492-498 Link Here
492
            collectPackageInstances(nested, packages);
591
            collectPackageInstances(nested, packages);
493
        }
592
        }
494
    }
593
    }
495
594
    
496
    /** Instantiates given package, i.e. packageProxies, classProxies,
595
    /** Instantiates given package, i.e. packageProxies, classProxies,
497
     * associationProxies.
596
     * associationProxies.
498
     *
597
     *
Lines 500-517 Link Here
500
     * @param metaPackage outermost M2 package
599
     * @param metaPackage outermost M2 package
501
     * @param clusteredInstances maps MOF IDs of M2 packages to M1 package instances
600
     * @param clusteredInstances maps MOF IDs of M2 packages to M1 package instances
502
     * @param storageId ID of the storage partition
601
     * @param storageId ID of the storage partition
503
     */  
602
     */
504
    private RefPackage instantiatePackage(String substName, StorablePackage immediatePackage, MofPackage metaPackage, Map clusteredInstances, String storageId, boolean clustered) {
603
    private RefPackage instantiatePackage(String substName, StorablePackage immediatePackage, MofPackage metaPackage, Map clusteredInstances, String storageId, boolean clustered) {
505
        // Create package proxy
604
        // Create package proxy
506
        StorablePackage newPackage = createPackageHandler(metaPackage, immediatePackage, substName, storageId, clustered);
605
        StorablePackage newPackage = createPackageHandler(metaPackage, immediatePackage, substName, storageId, clustered);
507
        System.out.println("new package: " + newPackage.getMofId() + ", metapackage: " + metaPackage.refMofId());
606
        System.out.println("new package: " + newPackage.getMofId() + ", metapackage: " + metaPackage.refMofId());
508
607
        
509
        Log.out.indent();
608
        Log.out.indent();
510
609
        
511
        Set localAssocProxies = new HashSet();
610
        Set localAssocProxies = new HashSet();
512
        Map localClassProxies = new HashMap();
611
        Map localClassProxies = new HashMap();
513
        instantiatePackageContent(metaPackage, newPackage, clusteredInstances, localClassProxies, localAssocProxies);
612
        instantiatePackageContent(metaPackage, newPackage, clusteredInstances, localClassProxies, localAssocProxies);
514
        resolveSuperclasses(localClassProxies);        
613
        resolveSuperclasses(localClassProxies);
515
        
614
        
516
        // [PENDING] need to fix the mutex ordering and NPE and then uncomment this
615
        // [PENDING] need to fix the mutex ordering and NPE and then uncomment this
517
        /*
616
        /*
Lines 525-531 Link Here
525
        return (RefPackage) BaseObjectHandler.getHandler(newPackage);
624
        return (RefPackage) BaseObjectHandler.getHandler(newPackage);
526
    }
625
    }
527
    
626
    
528
627
    
529
    /**
628
    /**
530
     * @param localClassProxies
629
     * @param localClassProxies
531
     */
630
     */
Lines 586-592 Link Here
586
                }
685
                }
587
                sc.addSuperclass(current.getMofId());
686
                sc.addSuperclass(current.getMofId());
588
                current.addSubclass(sc.getMofId());
687
                current.addSubclass(sc.getMofId());
589
            }            
688
            }
590
            for (Iterator contents = cls.getContents().iterator(); contents.hasNext();) {
689
            for (Iterator contents = cls.getContents().iterator(); contents.hasNext();) {
591
                me = (ModelElement) contents.next();
690
                me = (ModelElement) contents.next();
592
                if (me instanceof Reference) {
691
                if (me instanceof Reference) {
Lines 614-629 Link Here
614
            }
713
            }
615
            if (indexTags.size() > 0) {
714
            if (indexTags.size() > 0) {
616
                try {
715
                try {
617
                    sc.buildAdditionalIndexes (indexTags, associationProxies);
716
                    sc.buildAdditionalIndexes(indexTags, associationProxies);
618
                } catch (StorageException e) {
717
                } catch (StorageException e) {
619
                    throw new DebugException ("Storage exception: " + e);
718
                    throw new DebugException("Storage exception: " + e);
620
                }
719
                }
621
            }
720
            }
622
             */
721
             */
623
        } // for
722
        } // for
624
        
723
        
625
    }
724
    }
626
725
    
627
    /**
726
    /**
628
     * @param metaPackage
727
     * @param metaPackage
629
     * @param newPackage
728
     * @param newPackage
Lines 633-656 Link Here
633
     */
732
     */
634
    private void instantiatePackageContent(MofPackage metaPackage, StorablePackage newPackage, Map clusteredInstances, Map localClassProxies, Set localAssocProxies) {
733
    private void instantiatePackageContent(MofPackage metaPackage, StorablePackage newPackage, Map clusteredInstances, Map localClassProxies, Set localAssocProxies) {
635
        Iterator superTypes = metaPackage.allSupertypes().iterator();
734
        Iterator superTypes = metaPackage.allSupertypes().iterator();
636
        boolean thisTypeNotProcessed = true;        
735
        boolean thisTypeNotProcessed = true;
637
        while (thisTypeNotProcessed || superTypes.hasNext()) {
736
        while (thisTypeNotProcessed || superTypes.hasNext()) {
638
            Iterator it;
737
            Iterator it;
639
            if (thisTypeNotProcessed) {
738
            if (thisTypeNotProcessed) {
640
                it = metaPackage.getContents().iterator();
739
                it = metaPackage.getContents().iterator();
641
                thisTypeNotProcessed = false;
740
                thisTypeNotProcessed = false;
642
            } else            
741
            } else
643
                it = ((MofPackage) superTypes.next ()).getContents().iterator();
742
                it = ((MofPackage) superTypes.next()).getContents().iterator();
644
        
743
            
645
            while (it.hasNext()) {
744
            while (it.hasNext()) {
646
                Object o = it.next();
745
                Object o = it.next();
647
                ModelElement element = (ModelElement) o;
746
                ModelElement element = (ModelElement) o;
648
747
                
649
                if (element instanceof javax.jmi.model.MofClass) {
748
                if (element instanceof javax.jmi.model.MofClass) {
650
                    createClassProxyHandler((javax.jmi.model.MofClass) element, newPackage, localClassProxies);
749
                    createClassProxyHandler((javax.jmi.model.MofClass) element, newPackage, localClassProxies);
651
                } else if (element instanceof  javax.jmi.model.Association) {
750
                } else if (element instanceof  javax.jmi.model.Association) {
652
                    Association assoc = (Association) element;
751
                    Association assoc = (Association) element;
653
752
                    
654
                    Collection content = assoc.getContents();
753
                    Collection content = assoc.getContents();
655
                    int i = 0;
754
                    int i = 0;
656
                    AssociationEnd ends[] = new AssociationEnd[2];
755
                    AssociationEnd ends[] = new AssociationEnd[2];
Lines 664-670 Link Here
664
                    boolean orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, indexedA, indexedB;
763
                    boolean orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, indexedA, indexedB;
665
                    int minA, maxA, minB, maxB;
764
                    int minA, maxA, minB, maxB;
666
                    Class typeA, typeB;
765
                    Class typeA, typeB;
667
766
                    
668
                    minA = ends[0].getMultiplicity().getLower();
767
                    minA = ends[0].getMultiplicity().getLower();
669
                    maxA = ends[0].getMultiplicity().getUpper();
768
                    maxA = ends[0].getMultiplicity().getUpper();
670
                    minB = ends[1].getMultiplicity().getLower();
769
                    minB = ends[1].getMultiplicity().getLower();
Lines 680-715 Link Here
680
                    orderB = (ends[1].getMultiplicity().isOrdered());
779
                    orderB = (ends[1].getMultiplicity().isOrdered());
681
                    uniqueA = (ends[0].getMultiplicity().isUnique());
780
                    uniqueA = (ends[0].getMultiplicity().isUnique());
682
                    uniqueB = (ends[1].getMultiplicity().isUnique());
781
                    uniqueB = (ends[1].getMultiplicity().isUnique());
683
782
                    
684
                    aggrA = ends[0].getAggregation().equals(AggregationKindEnum.COMPOSITE);
783
                    aggrA = ends[0].getAggregation().equals(AggregationKindEnum.COMPOSITE);
685
                    aggrB = ends[1].getAggregation().equals(AggregationKindEnum.COMPOSITE);
784
                    aggrB = ends[1].getAggregation().equals(AggregationKindEnum.COMPOSITE);
686
                    
785
                    
687
                    indexedA = TagSupport.getTagValue ((StorableObject) ((BaseObjectHandler) ends[0])._getDelegate(), TAGID_INDEX) != null;
786
                    indexedA = TagSupport.getTagValue((StorableObject) ((BaseObjectHandler) ends[0])._getDelegate(), TAGID_INDEX) != null;
688
                    indexedB = TagSupport.getTagValue ((StorableObject) ((BaseObjectHandler) ends[1])._getDelegate(), TAGID_INDEX) != null;
787
                    indexedB = TagSupport.getTagValue((StorableObject) ((BaseObjectHandler) ends[1])._getDelegate(), TAGID_INDEX) != null;
689
                    if (TagProvider.getTagValue (ends[0].getType (), TRANSIENT_TAG_ID, "").equals (TAG_VALUE_TRUE)
788
                    if (TagProvider.getTagValue(ends[0].getType(), TRANSIENT_TAG_ID, "").equals(TAG_VALUE_TRUE)
690
                     || TagProvider.getTagValue (ends[1].getType (), TRANSIENT_TAG_ID, "").equals (TAG_VALUE_TRUE)) {
789
                    || TagProvider.getTagValue(ends[1].getType(), TRANSIENT_TAG_ID, "").equals(TAG_VALUE_TRUE)) {
691
                         createTransientAssociationHandler((javax.jmi.model.Association) element, newPackage, ends[0].getName(), ends[0].refMofId(), ends[1].getName(), ends[1].refMofId(), typeA, typeB, minA, maxA, minB, maxB, orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, localAssocProxies);
790
                        createTransientAssociationHandler((javax.jmi.model.Association) element, newPackage, ends[0].getName(), ends[0].refMofId(), ends[1].getName(), ends[1].refMofId(), typeA, typeB, minA, maxA, minB, maxB, orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, localAssocProxies);
692
                    }
791
                    }
693
                    else {
792
                    else {
694
                        createAssociationHandler((javax.jmi.model.Association) element, newPackage, ends[0].getName(), ends[0].refMofId(), ends[1].getName(), ends[1].refMofId(), typeA, typeB, minA, maxA, minB, maxB, orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, indexedA, indexedB, localAssocProxies);
793
                        createAssociationHandler((javax.jmi.model.Association) element, newPackage, ends[0].getName(), ends[0].refMofId(), ends[1].getName(), ends[1].refMofId(), typeA, typeB, minA, maxA, minB, maxB, orderA, orderB, uniqueA, uniqueB, aggrA, aggrB, indexedA, indexedB, localAssocProxies);
695
                    }
794
                    }
696
                    
795
                    
697
                } else if (element instanceof  MofPackage) {
796
                } else if (element instanceof  MofPackage) {
698
    //                System.out.println("found inner package");
797
                    //                System.out.println("found inner package");
699
    //                System.out.println("creating: META: " + element.refMofId() + ", IMMEDIATE: " + newPackage.refMofId() + ", CONTEXT: " + context);
798
                    //                System.out.println("creating: META: " + element.refMofId() + ", IMMEDIATE: " + newPackage.refMofId() + ", CONTEXT: " + context);
700
                    String storageId = MdrStorage.getStorageIdFromMofId (newPackage.getMofId());
799
                    String storageId = MdrStorage.getStorageIdFromMofId(newPackage.getMofId());
701
                    StorablePackage pkg = createPackageHandler((MofPackage) element, newPackage, null, storageId, false);
800
                    StorablePackage pkg = createPackageHandler((MofPackage) element, newPackage, null, storageId, false);
702
                    instantiatePackageContent((MofPackage) element, pkg, clusteredInstances, localClassProxies, localAssocProxies);
801
                    instantiatePackageContent((MofPackage) element, pkg, clusteredInstances, localClassProxies, localAssocProxies);
703
                } else if (element instanceof Import) {
802
                } else if (element instanceof Import) {
704
                    Import imp = (Import) element;
803
                    Import imp = (Import) element;
705
804
                    
706
                    if (imp.isClustered()) {
805
                    if (imp.isClustered()) {
707
                        ModelElement metaElement = imp.getImportedNamespace();
806
                        ModelElement metaElement = imp.getImportedNamespace();
708
                        if (metaElement instanceof MofPackage) {
807
                        if (metaElement instanceof MofPackage) {
709
                            MofPackage metaPkg = (MofPackage) metaElement;
808
                            MofPackage metaPkg = (MofPackage) metaElement;
710
                            RefPackage pkg = (RefPackage) clusteredInstances.get(metaPkg.refMofId());
809
                            RefPackage pkg = (RefPackage) clusteredInstances.get(metaPkg.refMofId());
711
                            if (pkg == null) {
810
                            if (pkg == null) {
712
                                String storageId = MdrStorage.getStorageIdFromMofId (newPackage.getMofId());
811
                                String storageId = MdrStorage.getStorageIdFromMofId(newPackage.getMofId());
713
                                pkg = instantiatePackage(null, newPackage, metaPkg, clusteredInstances, storageId, true);
812
                                pkg = instantiatePackage(null, newPackage, metaPkg, clusteredInstances, storageId, true);
714
                                clusteredInstances.put(metaPkg.refMofId(), pkg);
813
                                clusteredInstances.put(metaPkg.refMofId(), pkg);
715
                            } else {
814
                            } else {
Lines 750-763 Link Here
750
                // this package was already collected
849
                // this package was already collected
751
                return;
850
                return;
752
            }
851
            }
753
            classProxies.put((MofClass) cls.refMetaObject(), ((BaseObjectHandler) cls)._getDelegate()); 
852
            classProxies.put((MofClass) cls.refMetaObject(), ((BaseObjectHandler) cls)._getDelegate());
754
        }
853
        }
755
        
854
        
756
        for (Iterator it = pkg.refAllPackages().iterator(); it.hasNext();) {
855
        for (Iterator it = pkg.refAllPackages().iterator(); it.hasNext();) {
757
            collectAllProxies((RefPackage) it.next());
856
            collectAllProxies((RefPackage) it.next());
758
        }
857
        }
759
    }
858
    }
760
859
    
761
    /* -------------------------------------------------------------------- */
860
    /* -------------------------------------------------------------------- */
762
    /* -- Helper methods for handler creation (private) ------------------- */
861
    /* -- Helper methods for handler creation (private) ------------------- */
763
    /* -------------------------------------------------------------------- */
862
    /* -------------------------------------------------------------------- */
Lines 778-784 Link Here
778
                    ModelElement me;
877
                    ModelElement me;
779
                    List members = new ArrayList();
878
                    List members = new ArrayList();
780
                    List memberTypes = new ArrayList();
879
                    List memberTypes = new ArrayList();
781
880
                    
782
                    for (Iterator it2 = ((StructureType) element).getContents().iterator(); it2.hasNext();) {
881
                    for (Iterator it2 = ((StructureType) element).getContents().iterator(); it2.hasNext();) {
783
                        me = (ModelElement) it2.next();
882
                        me = (ModelElement) it2.next();
784
                        if (me instanceof StructureField) {
883
                        if (me instanceof StructureField) {
Lines 795-801 Link Here
795
                    datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, element.getQualifiedName(), members, memberTypes, ifcName, storageId));
894
                    datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, element.getQualifiedName(), members, memberTypes, ifcName, storageId));
796
                }
895
                }
797
            }
896
            }
798
897
            
799
            StorablePackage result = null;
898
            StorablePackage result = null;
800
            if (storageId != null) {
899
            if (storageId != null) {
801
                result = new StorablePackage(mdrStorage, immediatePackage == null ? null : immediatePackage.getMofId(), metaObject.refMofId(), context, datatypes, storageId);
900
                result = new StorablePackage(mdrStorage, immediatePackage == null ? null : immediatePackage.getMofId(), metaObject.refMofId(), context, datatypes, storageId);
Lines 806-818 Link Here
806
            if (immediatePackage != null && !clustered) {
905
            if (immediatePackage != null && !clustered) {
807
                immediatePackage.addPackage(metaObject.getName(), result.getMofId());
906
                immediatePackage.addPackage(metaObject.getName(), result.getMofId());
808
            }
907
            }
809
                
908
            
810
            return result;
909
            return result;
811
        } catch ( StorageException e ) {
910
        } catch ( StorageException e ) {
812
            throw new DebugException("Storage exception: " + e.getMessage());
911
            throw new DebugException("Storage exception: " + e.getMessage());
813
        }
912
        }
814
    }
913
    }
815
914
    
816
    /** Creates handler for Class Proxy */
915
    /** Creates handler for Class Proxy */
817
    private StorableClass createClassProxyHandler(javax.jmi.model.MofClass metaObject, StorablePackage immediatePackage, Map localClassProxies) {
916
    private StorableClass createClassProxyHandler(javax.jmi.model.MofClass metaObject, StorablePackage immediatePackage, Map localClassProxies) {
818
        ModelElement element;
917
        ModelElement element;
Lines 854-865 Link Here
854
                    if (element instanceof EnumerationType) {
953
                    if (element instanceof EnumerationType) {
855
                        List members = new ArrayList(((EnumerationType) element).getLabels());
954
                        List members = new ArrayList(((EnumerationType) element).getLabels());
856
                        String ifcName = TagSupport.getTypeFullName((StorableObject) ((BaseObjectHandler) element)._getDelegate());
955
                        String ifcName = TagSupport.getTypeFullName((StorableObject) ((BaseObjectHandler) element)._getDelegate());
857
                        datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, members, ifcName, MdrStorage.getStorageIdFromMofId (immediatePackage.getMofId())));
956
                        datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, members, ifcName, MdrStorage.getStorageIdFromMofId(immediatePackage.getMofId())));
858
                    } else if (element instanceof StructureType) {
957
                    } else if (element instanceof StructureType) {
859
                        ModelElement me;
958
                        ModelElement me;
860
                        List members = new ArrayList();
959
                        List members = new ArrayList();
861
                        List memberTypes = new ArrayList();
960
                        List memberTypes = new ArrayList();
862
961
                        
863
                        for (Iterator it2 = ((StructureType) element).getContents().iterator(); it2.hasNext();) {
962
                        for (Iterator it2 = ((StructureType) element).getContents().iterator(); it2.hasNext();) {
864
                            me = (ModelElement) it2.next();
963
                            me = (ModelElement) it2.next();
865
                            if (me instanceof StructureField) {
964
                            if (me instanceof StructureField) {
Lines 873-879 Link Here
873
                            }
972
                            }
874
                        }
973
                        }
875
                        String ifcName = TagSupport.getTypeFullName((StorableObject) ((BaseObjectHandler) element)._getDelegate());
974
                        String ifcName = TagSupport.getTypeFullName((StorableObject) ((BaseObjectHandler) element)._getDelegate());
876
                        datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, element.getQualifiedName(), members, memberTypes, ifcName, MdrStorage.getStorageIdFromMofId (immediatePackage.getMofId())));
975
                        datatypes.put(element.getName(), new DatatypeDescriptor(mdrStorage, element.getQualifiedName(), members, memberTypes, ifcName, MdrStorage.getStorageIdFromMofId(immediatePackage.getMofId())));
877
                    }
976
                    }
878
                    isDerived = false;
977
                    isDerived = false;
879
                    isInterceptable = false;
978
                    isInterceptable = false;
Lines 888-947 Link Here
888
                }
987
                }
889
            }
988
            }
890
            
989
            
891
            String tagValue = TagProvider.getTagValue (metaObject, TRANSIENT_TAG_ID, "");
990
            String tagValue = TagProvider.getTagValue(metaObject, TRANSIENT_TAG_ID, "");
892
            if (tagValue.equals (TAG_VALUE_TRUE)) {
991
            if (tagValue.equals(TAG_VALUE_TRUE)) {
893
                storable = new TransientStorableClass(mdrStorage, immediatePackage.getMofId(), 
992
                storable = new TransientStorableClass(mdrStorage, immediatePackage.getMofId(),
894
                    metaObject.refMofId(), attrDescs, clAttrDescs, datatypes, classDerived, 
993
                metaObject.refMofId(), attrDescs, clAttrDescs, datatypes, classDerived,
895
                    instanceDerived, metaObject.isSingleton(), metaObject.isAbstract());
994
                instanceDerived, metaObject.isSingleton(), metaObject.isAbstract());
896
            }
995
            }
897
            else {
996
            else {
898
                storable = new StorableClass(mdrStorage, immediatePackage.getMofId(), 
997
                storable = new StorableClass(mdrStorage, immediatePackage.getMofId(),
899
                    metaObject.refMofId(), attrDescs, clAttrDescs, datatypes, classDerived, 
998
                metaObject.refMofId(), attrDescs, clAttrDescs, datatypes, classDerived,
900
                    instanceDerived, metaObject.isSingleton(), metaObject.isAbstract());
999
                instanceDerived, metaObject.isSingleton(), metaObject.isAbstract());
901
            }
1000
            }
902
1001
            
903
            immediatePackage.addClass(metaObject.getName(), storable.getMofId());
1002
            immediatePackage.addClass(metaObject.getName(), storable.getMofId());
904
            classProxies.put(metaObject, storable);
1003
            classProxies.put(metaObject, storable);
905
            classProxiesMofIds.put(metaObject.refMofId(), storable.getMofId());
1004
            classProxiesMofIds.put(metaObject.refMofId(), storable.getMofId());
906
            localClassProxies.put(metaObject, storable);
1005
            localClassProxies.put(metaObject, storable);
907
            return storable;
1006
            return storable;
908
        } catch ( StorageException e ) {
1007
        } catch ( StorageException e ) {
909
            e.printStackTrace ();
1008
            e.printStackTrace();
910
            throw new DebugException("Storage exception: " + e.getMessage());
1009
            throw new DebugException("Storage exception: " + e.getMessage());
911
        }
1010
        }
912
    }
1011
    }
913
1012
    
914
    /** Creates handler for Association */
1013
    /** Creates handler for Association */
915
    private StorableAssociation createAssociationHandler(
1014
    private StorableAssociation createAssociationHandler(
916
        javax.jmi.model.Association metaObject,
1015
    javax.jmi.model.Association metaObject,
917
        StorablePackage immediatePackage,
1016
    StorablePackage immediatePackage,
918
        String assocationEnd1, String assocEnd1MofId,
1017
    String assocationEnd1, String assocEnd1MofId,
919
        String assocationEnd2, String assocEnd2MofId,
1018
    String assocationEnd2, String assocEnd2MofId,
920
        Class type1, Class type2,
1019
    Class type1, Class type2,
921
        int min1, int max1,
1020
    int min1, int max1,
922
        int min2, int max2,
1021
    int min2, int max2,
923
        boolean isOrdered1,
1022
    boolean isOrdered1,
924
        boolean isOrdered2,
1023
    boolean isOrdered2,
925
        boolean isUnique1,
1024
    boolean isUnique1,
926
        boolean isUnique2,
1025
    boolean isUnique2,
927
        boolean isAggr1,
1026
    boolean isAggr1,
928
        boolean isAggr2,
1027
    boolean isAggr2,
929
        boolean isIndexed1,
1028
    boolean isIndexed1,
930
        boolean isIndexed2,
1029
    boolean isIndexed2,
931
        Set localAssocProxies) {
1030
    Set localAssocProxies) {
932
        
1031
        
933
        try {
1032
        try {
934
            StorableAssociation result = new StorableAssociation(
1033
            StorableAssociation result = new StorableAssociation(
935
                           mdrStorage,
1034
            mdrStorage,
936
                           immediatePackage.getMofId(),
1035
            immediatePackage.getMofId(),
937
                           metaObject.refMofId(),
1036
            metaObject.refMofId(),
938
                           assocationEnd1, assocEnd1MofId, assocationEnd2, assocEnd2MofId,
1037
            assocationEnd1, assocEnd1MofId, assocationEnd2, assocEnd2MofId,
939
                           type1, type2,
1038
            type1, type2,
940
                           min1, max1, min2, max2,
1039
            min1, max1, min2, max2,
941
                           isOrdered1, isOrdered2,
1040
            isOrdered1, isOrdered2,
942
                           isUnique1, isUnique2,
1041
            isUnique1, isUnique2,
943
                           isAggr1, isAggr2,
1042
            isAggr1, isAggr2,
944
                           isIndexed1, isIndexed2);
1043
            isIndexed1, isIndexed2);
945
            immediatePackage.addAssociation(metaObject.getName(), result.getMofId());
1044
            immediatePackage.addAssociation(metaObject.getName(), result.getMofId());
946
            associationProxies.put(metaObject.refMofId(), result.getMofId());
1045
            associationProxies.put(metaObject.refMofId(), result.getMofId());
947
            localAssocProxies.add(result.getMofId());
1046
            localAssocProxies.add(result.getMofId());
Lines 952-983 Link Here
952
    }
1051
    }
953
    
1052
    
954
    private StorableAssociation createTransientAssociationHandler(
1053
    private StorableAssociation createTransientAssociationHandler(
955
        javax.jmi.model.Association metaObject,
1054
    javax.jmi.model.Association metaObject,
956
        StorablePackage immediatePackage,
1055
    StorablePackage immediatePackage,
957
        String assocationEnd1, String assocEnd1MofId,
1056
    String assocationEnd1, String assocEnd1MofId,
958
        String assocationEnd2, String assocEnd2MofId,
1057
    String assocationEnd2, String assocEnd2MofId,
959
        Class type1, Class type2,
1058
    Class type1, Class type2,
960
        int min1, int max1,
1059
    int min1, int max1,
961
        int min2, int max2,
1060
    int min2, int max2,
962
        boolean isOrdered1,
1061
    boolean isOrdered1,
963
        boolean isOrdered2,
1062
    boolean isOrdered2,
964
        boolean isUnique1,
1063
    boolean isUnique1,
965
        boolean isUnique2,
1064
    boolean isUnique2,
966
        boolean isAggr1,
1065
    boolean isAggr1,
967
        boolean isAggr2,
1066
    boolean isAggr2,
968
        Set localAssocProxies) {
1067
    Set localAssocProxies) {
969
        
1068
        
970
        try {
1069
        try {
971
            StorableAssociation result = new TransientStorableAssociation(
1070
            StorableAssociation result = new TransientStorableAssociation(
972
                           mdrStorage,
1071
            mdrStorage,
973
                           immediatePackage.getMofId(),
1072
            immediatePackage.getMofId(),
974
                           metaObject.refMofId(),
1073
            metaObject.refMofId(),
975
                           assocationEnd1, assocEnd1MofId, assocationEnd2, assocEnd2MofId,
1074
            assocationEnd1, assocEnd1MofId, assocationEnd2, assocEnd2MofId,
976
                           type1, type2,
1075
            type1, type2,
977
                           min1, max1, min2, max2,
1076
            min1, max1, min2, max2,
978
                           isOrdered1, isOrdered2,
1077
            isOrdered1, isOrdered2,
979
                           isUnique1, isUnique2,
1078
            isUnique1, isUnique2,
980
                           isAggr1, isAggr2);
1079
            isAggr1, isAggr2);
981
            immediatePackage.addAssociation(metaObject.getName(), result.getMofId());
1080
            immediatePackage.addAssociation(metaObject.getName(), result.getMofId());
982
            associationProxies.put(metaObject.refMofId(), result.getMofId());
1081
            associationProxies.put(metaObject.refMofId(), result.getMofId());
983
            localAssocProxies.add(result.getMofId());
1082
            localAssocProxies.add(result.getMofId());
Lines 990-996 Link Here
990
    /* -------------------------------------------------------------------- */
1089
    /* -------------------------------------------------------------------- */
991
    /* -- Methods for bootstrapping (private) ----------------------------- */
1090
    /* -- Methods for bootstrapping (private) ----------------------------- */
992
    /* -------------------------------------------------------------------- */
1091
    /* -------------------------------------------------------------------- */
993
1092
    
994
    /**
1093
    /**
995
     * Main bootstrapping method.
1094
     * Main bootstrapping method.
996
     */
1095
     */
Lines 1002-1008 Link Here
1002
        try {
1101
        try {
1003
            beginTrans(true);
1102
            beginTrans(true);
1004
            installFakeMof();
1103
            installFakeMof();
1005
            installPureMof();   
1104
            installPureMof();
1006
            fail = false;
1105
            fail = false;
1007
        } catch (Throwable e) {
1106
        } catch (Throwable e) {
1008
            e.printStackTrace();
1107
            e.printStackTrace();
Lines 1011-1037 Link Here
1011
            endTrans(fail);
1110
            endTrans(fail);
1012
        }
1111
        }
1013
        Log.out.unindent();
1112
        Log.out.unindent();
1014
    }    
1113
    }
1015
1114
    
1016
    /** Installs the fake MOF
1115
    /** Installs the fake MOF
1017
    */
1116
     */
1018
    private void installFakeMof() {
1117
    private void installFakeMof() {
1019
        Log.out.println("Creating boot MOF metamodel ...");
1118
        Log.out.println("Creating boot MOF metamodel ...");
1020
1119
        
1021
        try {
1120
        createBootMOF();
1022
            RefPackage p = createExtent(BOOT_MOF, null, null);
1121
        if (getExtent(BOOT_MOF) == null) {
1023
        } catch (CreationFailedException e) {
1122
            throw new DebugException("Cannot create instance of BOOT_MOF: Fatal error during bootstrapping.");
1024
            e.printStackTrace();
1025
            throw new DebugException("Cannot create instance of BOOT_MOF: " + e.getMessage());
1026
        }
1123
        }
1027
    }
1124
    }
1028
1125
    
1029
    /**  Programatically installs the pure MOF model.
1126
    /**  Programatically installs the pure MOF model.
1030
     */
1127
     */
1031
    private void installPureMof() {
1128
    private void installPureMof() {
1032
        Log.out.println("Installing pure MOF Metamodel ... ");
1129
        Log.out.println("Installing pure MOF Metamodel ... ");
1033
        Log.out.indent();
1130
        Log.out.indent();
1034
1131
        
1035
        try {
1132
        try {
1036
            Log.out.println("Parsing MOF model to DOM represtentation ....");
1133
            Log.out.println("Parsing MOF model to DOM represtentation ....");
1037
            ModelPackage modelPackage = (ModelPackage) createExtent(PURE_MOF, getBMModelPackage());
1134
            ModelPackage modelPackage = (ModelPackage) createExtent(PURE_MOF, getBMModelPackage());
Lines 1045-1051 Link Here
1045
            Log.out.unindent();
1142
            Log.out.unindent();
1046
        }
1143
        }
1047
    }
1144
    }
1048
1145
    
1049
    /**
1146
    /**
1050
     * Returns the MOF Model package as a model element of the
1147
     * Returns the MOF Model package as a model element of the
1051
     * bootstrapping MOF model. Needed only during bootstrapping.
1148
     * bootstrapping MOF model. Needed only during bootstrapping.
Lines 1063-1071 Link Here
1063
        }
1160
        }
1064
        return null;
1161
        return null;
1065
    }
1162
    }
1066
1163
    
1067
    /** Reads the XMI description of the mof directly into reporitory
1164
    /** Reads the XMI description of the mof directly into reporitory
1068
    */
1165
     */
1069
    private void createBootMOF() {
1166
    private void createBootMOF() {
1070
        try {
1167
        try {
1071
            BootReader br = new BootReader(mdrStorage, BOOTMOF_XML_URL);
1168
            BootReader br = new BootReader(mdrStorage, BOOTMOF_XML_URL);
(-)src/org/netbeans/mdr/handlers/AssociationHandler.java (-5 / +30 lines)
Lines 302-321 Link Here
302
    /*
302
    /*
303
    public void replace(RefObject oldEnd1, RefObject oldEnd2, RefObject newEnd1, RefObject newEnd2) {
303
    public void replace(RefObject oldEnd1, RefObject oldEnd2, RefObject newEnd1, RefObject newEnd2) {
304
    }
304
    }
305
306
    /* -------------------------------------------------------------------- */
307
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
308
    /* -------------------------------------------------------------------- */
309
    
310
    /** Registers a listener for receiving event notifications with are
311
     *  initially fired on this object.
312
     * @param listener Object that implements {@link MDRChangeListener} interface.
305
     */
313
     */
314
    public void addListener(MDRChangeListener listener) {
315
        addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
316
    }
317
    
306
    /** Registers a listener for receiving event notifications.
318
    /** Registers a listener for receiving event notifications.
307
     * @param listener Object that implements {@link Listener} interface.
319
     * @param listener Object that implements {@link MDRChangeListener} interface.
320
     * @param mask bitmask to filter types of events the listener listens on
308
     */
321
     */
309
    public void addListener(MDRChangeListener listener) {
322
    public void addListener(MDRChangeListener listener, int mask) {
310
        _getMdrStorage().getEventNotifier().ASSOCIATION.addListener(listener, this);
323
        _getMdrStorage().getEventNotifier().ASSOCIATION.addListener(listener, mask, this);
311
    }
324
    }
312
    
325
    
313
    /** Removes listener from the list of objects registered for events notifications.
326
    /** Removes listener from the list of objects registered for event notifications.
314
     * @param listener Object that implements {@link Listener} interface.
327
     * @param listener Object that implements {@link MDRChangeListener} interface.
315
     */
328
     */
316
    public void removeListener(MDRChangeListener listener) {
329
    public void removeListener(MDRChangeListener listener) {
317
        _getMdrStorage().getEventNotifier().ASSOCIATION.removeListener(listener, this);
330
        _getMdrStorage().getEventNotifier().ASSOCIATION.removeListener(listener, this);
318
    }
331
    }
332
    
333
    /** Removes listener from the list of objects registered for event notifications.
334
     * @param listener Object that implements {@link MDRChangeListener} interface.
335
     * @param mask determines type of the events the listeners stops to listen on
336
     */
337
    public void removeListener(MDRChangeListener listener, int mask) {
338
        _getMdrStorage().getEventNotifier().ASSOCIATION.removeListener(listener, mask, this);
339
    }
340
341
    /* --------------------------------------------------------------------- */
342
    /* --        -- */
343
    /* --------------------------------------------------------------------- */
319
    
344
    
320
    static void _removeExternalLink(AssociationHandler associationHandler, RefObject thisEnd, RefObject otherEnd) {
345
    static void _removeExternalLink(AssociationHandler associationHandler, RefObject thisEnd, RefObject otherEnd) {
321
        if (MdrStorage.isTransientMofId (thisEnd.refMofId ()) || MdrStorage.isTransientMofId (otherEnd.refMofId ()))
346
        if (MdrStorage.isTransientMofId (thisEnd.refMofId ()) || MdrStorage.isTransientMofId (otherEnd.refMofId ()))
(-)src/org/netbeans/mdr/handlers/BaseObjectHandler.java (-74 / +195 lines)
Lines 34-90 Link Here
34
 * @version 
34
 * @version 
35
 */
35
 */
36
public abstract class BaseObjectHandler extends ImplClass implements MDRObject/*, OclAny*/ {
36
public abstract class BaseObjectHandler extends ImplClass implements MDRObject/*, OclAny*/ {
37
    
38
    /* --------------------------------------------------------------------- */
39
    /* -- Static attributes ------------------------------------------------ */
40
    /* --------------------------------------------------------------------- */
41
    
42
    /**
43
     * Maps storage objects (instances of {@link StorableBaseObject}) to
44
     * JMI compliant handler objects (instances of {@link RefBaseObject}).
45
     */
37
    private static final Map facilityCache = new FacilityCache();
46
    private static final Map facilityCache = new FacilityCache();
47
    
48
    /**
49
     * Maps mof ids of meta-objects to the appropriate JMI interfaces (String =&gt; Class).
50
     */
38
    private static final Hashtable classCache = new Hashtable();
51
    private static final Hashtable classCache = new Hashtable();
39
52
40
    private static MDRClassLoader defaultLoader = null;
53
    private static MDRClassLoader defaultLoader = null;
41
    private static ClassLoaderProvider provider = null;
54
    private static ClassLoaderProvider provider = null;
42
43
    /** The object in strorage to delegate to
44
    */
45
//    private final StorableBaseObject storableDelegate;
46
    private final String mofId;
47
    private final MdrStorage mdrStorage;
48
    private StorableBaseObject storable;
49
    
55
    
50
    protected final void _lock() {
56
    /* --------------------------------------------------------------------- */
51
        _lock(true);
57
    /* -- Static setters/getters ------------------------------------------- */
52
    }
58
    /* --------------------------------------------------------------------- */
53
    
59
    
54
    protected final void _lock(boolean write) {
60
    public static synchronized void setClassLoaderProvider(ClassLoaderProvider provider) {
55
        mdrStorage.getRepositoryMutex().enter(write);
61
        BaseObjectHandler.provider = provider;
56
    }
62
    }
57
    
63
    
58
    protected final void _unlock() {
64
    public static synchronized MDRClassLoader getDefaultClassLoader() {
59
        mdrStorage.getRepositoryMutex().leave();
65
        if (defaultLoader == null) {
60
    }
66
            defaultLoader = new MDRClassLoader(provider);
61
67
        }
62
    protected final void _unlock(boolean fail) {
68
//	System.out.println(defaultLoader.toString() + " : " + defaultLoader.getClass().getName());
63
        mdrStorage.getRepositoryMutex().leave(fail);
69
        return defaultLoader;   
64
    }
70
    }
65
    
71
    
66
    public final MDRepository repository() {
72
    /* --------------------------------------------------------------------- */
67
        return mdrStorage.getRepository();
73
    /* -- Static helper methods (private) ---------------------------------- */
68
    }
74
    /* --------------------------------------------------------------------- */
69
75
76
    /**
77
     * Returns the handler class for JMI interface <code>ifc</code> and storage object <code>s</code>.
78
     *
79
     * @param loader the class loader for the definition of new classes
80
     * @param ifc JMI interface to be implemented by the class
81
     * @param s storage object to be wrapped by an instances of the class
82
     * @return class implementing <code>ifc</code>
83
     */
70
    private static Class getHandlerClass(MDRClassLoader loader, Class ifc, StorableBaseObject s) throws IllegalArgumentException {
84
    private static Class getHandlerClass(MDRClassLoader loader, Class ifc, StorableBaseObject s) throws IllegalArgumentException {
85
        /* check if the loader may load the interface */
71
        check(loader, ifc);
86
        check(loader, ifc);
87
        /* try to load from cache */
72
        Map cache = getLoaderCache(loader);
88
        Map cache = getLoaderCache(loader);
73
        String className = getName(ifc);
89
        String className = getName(ifc);
74
        Class result = getFromCache(cache, ifc, className);
90
        Class result = getFromCache(cache, ifc, className);
75
        
91
        
76
        if (result == null) {
92
        if (result == null) {
77
            try {
93
            try {
94
                /* generate and define handler class */
78
                byte[] handlerClassFile = HandlerGenerator.generateHandler(className, ifc, s);
95
                byte[] handlerClassFile = HandlerGenerator.generateHandler(className, ifc, s);
79
/*
96
                
80
                try {
97
                /* [XXX] Allow the use of a system property org.netbeans.mdr.byteCodeDir, write class
81
                    java.io.FileOutputStream file = new java.io.FileOutputStream("e:/classes/" + className.substring(className.lastIndexOf('.') + 1) + ".class");
98
                 * files to that directory, if the system property is set.
82
                    file.write(handlerClassFile);
99
                 */
83
                    file.close();
100
//                try {
84
                } catch (Exception e) {
101
//                    java.io.FileOutputStream file = new java.io.FileOutputStream("e:/classes/" + className.substring(className.lastIndexOf('.') + 1) + ".class");
85
                    e.printStackTrace();
102
//                    file.write(handlerClassFile);
86
                }
103
//                    file.close();
87
*/
104
//                } catch (Exception e) {
105
//                    e.printStackTrace();
106
//                }
107
                
88
                result = loader.defineClass(className, handlerClassFile);
108
                result = loader.defineClass(className, handlerClassFile);
89
            } finally {
109
            } finally {
90
                releaseCache(cache, result, className);
110
                releaseCache(cache, result, className);
Lines 94-104 Link Here
94
        return result;
114
        return result;
95
    }
115
    }
96
116
117
    /**
118
     * Returns the JMI interface to be implemented by the handler of <code>s</code>.
119
     *
120
     * @param s a storage object
121
     * @return the JMI interface for <code>s</code>
122
     */
97
    private static Class resolveClass(StorableBaseObject s) {
123
    private static Class resolveClass(StorableBaseObject s) {
98
        try {
124
        try {
99
            StorableObject metaObject = s.getMetaObject();
125
            StorableObject metaObject = s.getMetaObject();
100
            String suffix;
126
            String suffix;
101
127
128
            /* cache lookup */
102
            if (s instanceof StorableObject || s instanceof StorableAssociation) {
129
            if (s instanceof StorableObject || s instanceof StorableAssociation) {
103
                suffix = "";
130
                suffix = "";
104
            } else if (s instanceof StorablePackage) {
131
            } else if (s instanceof StorablePackage) {
Lines 112-117 Link Here
112
            String key = metaObject.getMofId() + ":" + suffix;
139
            String key = metaObject.getMofId() + ":" + suffix;
113
            Class result = (Class) classCache.get(key);
140
            Class result = (Class) classCache.get(key);
114
141
142
            /* interface resolution */
115
            if (result == null) {
143
            if (result == null) {
116
                try {
144
                try {
117
                    String metaName = TagSupport.getTypeFullName(metaObject);
145
                    String metaName = TagSupport.getTypeFullName(metaObject);
Lines 128-139 Link Here
128
            throw new DebugException();
156
            throw new DebugException();
129
        }
157
        }
130
    }
158
    }
131
159
    
160
    /* --------------------------------------------------------------------- */
161
    /* -- Static methods (public) ------------------------------------------ */
162
    /* --------------------------------------------------------------------- */
163
164
    /**
165
     * Frees the caches of JMI compliant handler objects (for storage objects)
166
     * and of JMI implementation classes (for meta-objects).
167
     */
132
    public static void _freeCache() {
168
    public static void _freeCache() {
133
        facilityCache.clear();
169
        facilityCache.clear();
134
        classCache.clear();
170
        classCache.clear();
135
    }
171
    }
136
    
172
    
173
    /**
174
     * Returns JMI compliant handler object for <code>s</code>.
175
     *
176
     * @param s the storage object to be wrapped or <code>null</code>
177
     * @return handler implementing JMI interface or <code>null</code>
178
     */
137
    public static RefBaseObject getHandler(StorableBaseObject s) throws IllegalArgumentException {
179
    public static RefBaseObject getHandler(StorableBaseObject s) throws IllegalArgumentException {
138
        if (s == null) {
180
        if (s == null) {
139
            return null;
181
            return null;
Lines 151-161 Link Here
151
        return getHandler(s, ifc);
193
        return getHandler(s, ifc);
152
    }
194
    }
153
    
195
    
196
    /**
197
     * Returns JMI compliant handler object for <code>s</code>.
198
     *
199
     * @param s the storage object to be wrapped or <code>null</code>
200
     * @param ifc the JMI interface to be implemented by the handler
201
     * @return handler implementing JMI interface or <code>null</code>
202
     */
154
    public static RefBaseObject getHandler(StorableBaseObject s, Class ifc) throws IllegalArgumentException {
203
    public static RefBaseObject getHandler(StorableBaseObject s, Class ifc) throws IllegalArgumentException {
155
	if (s == null) {
204
	if (s == null) {
156
	    return null;
205
	    return null;
157
	}
206
	}
207
208
        /* [XXX] For performance reasons the following piece of code should
209
         * be enabled, when it is expected that cache lookup succeeds quite
210
         * often. hkrug@rationalizer.com */
211
//        Object oldRecord;
212
//        synchronized (facilityCache) {
213
//            oldRecord = facilityCache.get(s.getMofId());
214
//        }
215
//        if ( oldRecord != null ) {
216
//            return oldRecord;
217
//        }
158
        
218
        
219
        /* load the handler class */
159
        MDRClassLoader loader = getDefaultClassLoader();
220
        MDRClassLoader loader = getDefaultClassLoader();
160
	Class cl = getHandlerClass(loader, ifc, s);
221
	Class cl = getHandlerClass(loader, ifc, s);
161
222
Lines 170-175 Link Here
170
            else if (cls.equals (TransientStorableAssociation.class)) {
231
            else if (cls.equals (TransientStorableAssociation.class)) {
171
                cls = StorableAssociation.class;
232
                cls = StorableAssociation.class;
172
            }
233
            }
234
            /* create handler object, if necessary */
173
            Constructor cons = cl.getConstructor(new Class[] {cls});
235
            Constructor cons = cl.getConstructor(new Class[] {cls});
174
236
175
            synchronized (facilityCache) {
237
            synchronized (facilityCache) {
Lines 196-213 Link Here
196
	}
258
	}
197
    }
259
    }
198
    
260
    
199
    public static synchronized void setClassLoaderProvider(ClassLoaderProvider provider) {
261
    /**
200
        BaseObjectHandler.provider = provider;
262
     * Returns interface <code>ifcName</code>. The interface is not generated on the
201
    }
263
     * fly, but must be available for loading by the default class-loader
202
    
264
     * (see {@link #getDefaultClassLoader()}).
203
    public static synchronized MDRClassLoader getDefaultClassLoader() {
265
     *
204
        if (defaultLoader == null) {
266
     * @param ifcName name of the interface to be loaded
205
            defaultLoader = new MDRClassLoader(provider);
267
     * @return the interface named <code>ifcName</code>
206
        }
268
     */
207
//	System.out.println(defaultLoader.toString() + " : " + defaultLoader.getClass().getName());
208
        return defaultLoader;   
209
    }
210
    
211
    public static Class resolveInterface(String ifcName) throws ClassNotFoundException {
269
    public static Class resolveInterface(String ifcName) throws ClassNotFoundException {
212
        try {
270
        try {
213
            return Class.forName(ifcName, true, getDefaultClassLoader());
271
            return Class.forName(ifcName, true, getDefaultClassLoader());
Lines 222-227 Link Here
222
	}
280
	}
223
    }
281
    }
224
        
282
        
283
    /**
284
     * Loads the class <code>implName</code> from the default class loader.
285
     *
286
     * @param implName class name
287
     * @return the class
288
     */
225
    public static Class resolveImplementation(String implName) throws ClassNotFoundException {
289
    public static Class resolveImplementation(String implName) throws ClassNotFoundException {
226
        try {
290
        try {
227
            return Class.forName(implName, true, getDefaultClassLoader());
291
            return Class.forName(implName, true, getDefaultClassLoader());
Lines 238-243 Link Here
238
            throw e;
302
            throw e;
239
        }
303
        }
240
    }
304
    }
305
    
306
    /* --------------------------------------------------------------------- */
307
    /* -- Private attributes ----------------------------------------------- */
308
    /* --------------------------------------------------------------------- */
309
310
//    /** The object in strorage to delegate to
311
//    */
312
//    private final StorableBaseObject storableDelegate;
313
    private final String mofId;
314
    private final MdrStorage mdrStorage;
315
    private StorableBaseObject storable;
316
    
317
    /* --------------------------------------------------------------------- */
318
    /* -- Constructor(s) --------------------------------------------------- */
319
    /* --------------------------------------------------------------------- */
241
320
242
    /** Creates new RefBaseObjectHandler */
321
    /** Creates new RefBaseObjectHandler */
243
    protected BaseObjectHandler(StorableBaseObject storable) {
322
    protected BaseObjectHandler(StorableBaseObject storable) {
Lines 255-291 Link Here
255
            this.storable = null;
334
            this.storable = null;
256
        }
335
        }
257
    }
336
    }
258
337
    
259
    public final StorableBaseObject _getDelegate() {
338
    /* --------------------------------------------------------------------- */
260
/*        
339
    /* -- Transaction related methods -------------------------------------- */
261
        StorableBaseObject storable = (StorableBaseObject) storableDelegate.get();
340
    /* --------------------------------------------------------------------- */
262
        if (storable == null) {
341
    
263
            try {
342
    protected final void _lock() {
264
                storable = mdrStorage.getObject(mofId);
343
        _lock(true);
265
                storableDelegate = new SoftReference(storable);
266
            } catch (StorageException e) {
267
                throw new DebugException("Storage exception: " + e);
268
            }
269
        }
270
 */
271
        try {
272
            if (this.storable != null)
273
                return this.storable;
274
            else
275
                return mdrStorage.getObject(mofId);
276
        } catch (StorageBadRequestException e) {
277
            throw new InvalidObjectException(null, "Object with MOFID " + mofId + " no longer exists.");
278
        } catch (StorageException e) {
279
            throw new DebugException(e.toString());
280
        }
281
        //return storableDelegate;
282
    }
344
    }
283
    
345
    
284
    protected final MdrStorage _getMdrStorage() {
346
    protected final void _lock(boolean write) {
285
        return mdrStorage;
347
        mdrStorage.getRepositoryMutex().enter(write);
348
    }
349
    
350
    protected final void _unlock() {
351
        mdrStorage.getRepositoryMutex().leave();
286
    }
352
    }
287
353
288
    // Overriding the java.lang.object methods -----------------------------------
354
    protected final void _unlock(boolean fail) {
355
        mdrStorage.getRepositoryMutex().leave(fail);
356
    }
357
    
358
    /* --------------------------------------------------------------------- */
359
    /* -- Implements org.netbeans.api.mdr.MDRObject ------------------------ */
360
    /* --------------------------------------------------------------------- */
361
    
362
    public final MDRepository repository() {
363
        return mdrStorage.getRepository();
364
    }
365
    
366
    /* --------------------------------------------------------------------- */
367
    /* -- Extends java.lang.Object ----------------------------------------- */
368
    /* --------------------------------------------------------------------- */
289
369
290
    public final boolean equals(Object obj) {
370
    public final boolean equals(Object obj) {
291
        if (obj instanceof BaseObjectHandler) {
371
        if (obj instanceof BaseObjectHandler) {
Lines 316-323 Link Here
316
    public final int hashCode() {
396
    public final int hashCode() {
317
        return refMofId().hashCode();
397
        return refMofId().hashCode();
318
    }
398
    }
319
399
    
320
    // Implementation of the RefBaseObject ---------------------------------------
400
    /* --------------------------------------------------------------------- */
401
    /* -- Implements javax.jmi.reflect.RefBaseObject ----------------------- */
402
    /* --------------------------------------------------------------------- */
321
403
322
    public final RefObject refMetaObject() {
404
    public final RefObject refMetaObject() {
323
        try {
405
        try {
Lines 360-369 Link Here
360
        else return _verify(new ArrayList());
442
        else return _verify(new ArrayList());
361
    }
443
    }
362
    
444
    
445
    /* --------------------------------------------------------------------- */
446
    /* -- --------------------------------------------------- */
447
    /* --------------------------------------------------------------------- */
448
449
    public final StorableBaseObject _getDelegate() {
450
/*        
451
        StorableBaseObject storable = (StorableBaseObject) storableDelegate.get();
452
        if (storable == null) {
453
            try {
454
                storable = mdrStorage.getObject(mofId);
455
                storableDelegate = new SoftReference(storable);
456
            } catch (StorageException e) {
457
                throw new DebugException("Storage exception: " + e);
458
            }
459
        }
460
 */
461
        try {
462
            if (this.storable != null)
463
                return this.storable;
464
            else
465
                return mdrStorage.getObject(mofId);
466
        } catch (StorageBadRequestException e) {
467
            throw new InvalidObjectException(null, "Object with MOFID " + mofId + " no longer exists.");
468
        } catch (StorageException e) {
469
            throw new DebugException(e.toString());
470
        }
471
        //return storableDelegate;
472
    }
473
    
474
    protected final MdrStorage _getMdrStorage() {
475
        return mdrStorage;
476
    }
477
    
478
    /* --------------------------------------------------------------------- */
479
    /* -- Methods to be overridden by sub-classes -------------------------- */
480
    /* --------------------------------------------------------------------- */
481
363
    protected abstract Collection _recursiveVerify(Collection violations, Set visited);
482
    protected abstract Collection _recursiveVerify(Collection violations, Set visited);
364
    protected abstract Collection _verify(Collection violations);
483
    protected abstract Collection _verify(Collection violations);
365
484
366
    // private classes ---------------------------------------------
485
    /* --------------------------------------------------------------------- */
486
    /* -- FacilityCache (static inner class) ------------------------------- */
487
    /* --------------------------------------------------------------------- */
367
488
368
    /** Weak cache for created Handlers
489
    /** Weak cache for created Handlers
369
    */
490
    */
(-)src/org/netbeans/mdr/handlers/ClassProxyHandler.java (-5 / +23 lines)
Lines 259-277 Link Here
259
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
259
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
260
    /* -------------------------------------------------------------------- */
260
    /* -------------------------------------------------------------------- */
261
    
261
    
262
    /** Registers a listener for receiving event notifications.
262
    /** Registers a listener for receiving event notifications with are
263
     * @param listener Object that implements {@link Listener} interface.
263
     *  initially fired on this object.
264
     * @param listener Object that implements {@link MDRChangeListener} interface.
264
     */
265
     */
265
    public void addListener(MDRChangeListener listener) {
266
    public void addListener(MDRChangeListener listener) {
266
        _getMdrStorage().getEventNotifier().CLASS.addListener(listener, this);
267
        addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
268
    }
269
    
270
    /** Registers a listener for receiving event notifications.
271
     * @param listener Object that implements {@link MDRChangeListener} interface.
272
     * @param mask bitmask to filter types of events the listener listens on
273
     */
274
    public void addListener(MDRChangeListener listener, int mask) {
275
        _getMdrStorage().getEventNotifier().CLASS.addListener(listener, mask, this);
267
    }
276
    }
268
    
277
    
269
    /** Removes listener from the list of objects registered for events notifications.
278
    /** Removes listener from the list of objects registered for event notifications.
270
     * @param listener Object that implements {@link Listener} interface.
279
     * @param listener Object that implements {@link MDRChangeListener} interface.
271
     */
280
     */
272
    public void removeListener(MDRChangeListener listener) {
281
    public void removeListener(MDRChangeListener listener) {
273
        _getMdrStorage().getEventNotifier().CLASS.removeListener(listener, this);
282
        _getMdrStorage().getEventNotifier().CLASS.removeListener(listener, this);
274
    }
283
    }
284
    
285
    /** Removes listener from the list of objects registered for event notifications.
286
     * @param listener Object that implements {@link MDRChangeListener} interface.
287
     * @param mask determines type of the events the listeners stops to listen on
288
     */
289
    public void removeListener(MDRChangeListener listener, int mask) {
290
        _getMdrStorage().getEventNotifier().CLASS.removeListener(listener, mask, this);
291
    }
292
    
275
    /* -------------------------------------------------------------------- */
293
    /* -------------------------------------------------------------------- */
276
    /* -- ClassProxyHandler.CreateInstanceEvent (inner class) ------------- */
294
    /* -- ClassProxyHandler.CreateInstanceEvent (inner class) ------------- */
277
    /* -------------------------------------------------------------------- */
295
    /* -------------------------------------------------------------------- */
(-)src/org/netbeans/mdr/handlers/FeaturedHandler.java (-1 / +1 lines)
Lines 88-94 Link Here
88
    }
88
    }
89
    
89
    
90
90
91
    // Methods to refine for classes with the intercaptable tag set --------------
91
    // Methods to refine for classes with the interceptable tag set --------------
92
92
93
    protected void _interceptPreSet(String featureName, Object newValue) {
93
    protected void _interceptPreSet(String featureName, Object newValue) {
94
    }
94
    }
(-)src/org/netbeans/mdr/handlers/InstanceHandler.java (-5 / +22 lines)
Lines 391-408 Link Here
391
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
391
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
392
    /* -------------------------------------------------------------------- */
392
    /* -------------------------------------------------------------------- */
393
    
393
    
394
    /** Registers a listener for receiving event notifications.
394
    /** Registers a listener for receiving event notifications with are
395
     * @param listener Object that implements {@link Listener} interface.
395
     *  initially fired on this object.
396
     * @param listener Object that implements {@link MDRChangeListener} interface.
396
     */
397
     */
397
    public void addListener(MDRChangeListener listener) {
398
    public void addListener(MDRChangeListener listener) {
398
        _getMdrStorage().getEventNotifier().INSTANCE.addListener(listener, this);
399
        addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
400
    }
401
    
402
    /** Registers a listener for receiving event notifications.
403
     * @param listener Object that implements {@link MDRChangeListener} interface.
404
     * @param mask bitmask to filter types of events the listener listens on
405
     */
406
    public void addListener(MDRChangeListener listener, int mask) {
407
        _getMdrStorage().getEventNotifier().INSTANCE.addListener(listener, mask, this);
399
    }
408
    }
400
    
409
    
401
    /** Removes listener from the list of objects registered for events notifications.
410
    /** Removes listener from the list of objects registered for event notifications.
402
     * @param listener Object that implements {@link Listener} interface.
411
     * @param listener Object that implements {@link MDRChangeListener} interface.
403
     */
412
     */
404
    public void removeListener(MDRChangeListener listener) {
413
    public void removeListener(MDRChangeListener listener) {
405
        _getMdrStorage().getEventNotifier().INSTANCE.removeListener(listener, this);
414
        _getMdrStorage().getEventNotifier().INSTANCE.removeListener(listener, this);
415
    }
416
    
417
    /** Removes listener from the list of objects registered for event notifications.
418
     * @param listener Object that implements {@link MDRChangeListener} interface.
419
     * @param mask determines type of the events the listeners stops to listen on
420
     */
421
    public void removeListener(MDRChangeListener listener, int mask) {
422
        _getMdrStorage().getEventNotifier().INSTANCE.removeListener(listener, mask, this);
406
    }
423
    }
407
424
408
    /* ---------------------------------------------------------------- */
425
    /* ---------------------------------------------------------------- */
(-)src/org/netbeans/mdr/handlers/PackageProxyHandler.java (-6 / +23 lines)
Lines 387-405 Link Here
387
    /* -------------------------------------------------------------------- */
387
    /* -------------------------------------------------------------------- */
388
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
388
    /* -- Implementation of org.netbeans.api.mdr.events.MDRChangeSource --- */
389
    /* -------------------------------------------------------------------- */
389
    /* -------------------------------------------------------------------- */
390
390
    
391
    /** Registers a listener for receiving event notifications.
391
    /** Registers a listener for receiving event notifications with are
392
     * @param listener Object that implements {@link Listener} interface.
392
     *  initially fired on this object.
393
     * @param listener Object that implements {@link MDRChangeListener} interface.
393
     */
394
     */
394
    public void addListener(MDRChangeListener listener) {
395
    public void addListener(MDRChangeListener listener) {
395
        _getMdrStorage().getEventNotifier().PACKAGE.addListener(listener, this);
396
        addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
396
    }
397
    }
397
    
398
    
398
    /** Removes listener from the list of objects registered for events notifications.
399
    /** Registers a listener for receiving event notifications.
399
     * @param listener Object that implements {@link Listener} interface.
400
     * @param listener Object that implements {@link MDRChangeListener} interface.
401
     * @param mask bitmask to filter types of events the listener listens on
402
     */
403
    public void addListener(MDRChangeListener listener, int mask) {
404
        _getMdrStorage().getEventNotifier().PACKAGE.addListener(listener, mask, this);
405
    }
406
    
407
    /** Removes listener from the list of objects registered for event notifications.
408
     * @param listener Object that implements {@link MDRChangeListener} interface.
400
     */
409
     */
401
    public void removeListener(MDRChangeListener listener) {
410
    public void removeListener(MDRChangeListener listener) {
402
        _getMdrStorage().getEventNotifier().PACKAGE.removeListener(listener, this);
411
        _getMdrStorage().getEventNotifier().PACKAGE.removeListener(listener, this);
412
    }
413
    
414
    /** Removes listener from the list of objects registered for event notifications.
415
     * @param listener Object that implements {@link MDRChangeListener} interface.
416
     * @param mask determines type of the events the listeners stops to listen on
417
     */
418
    public void removeListener(MDRChangeListener listener, int mask) {
419
        _getMdrStorage().getEventNotifier().PACKAGE.removeListener(listener, mask, this);
403
    }
420
    }
404
    
421
    
405
    /* ---------------------------------------------------------------- */
422
    /* ---------------------------------------------------------------- */
(-)src/org/netbeans/mdr/handlers/StructGenerator.java (-4 / +5 lines)
Lines 19-24 Link Here
19
import java.util.*;
19
import java.util.*;
20
20
21
/**
21
/**
22
 * [XXX]: put this class into correct package !
22
 *
23
 *
23
 * @author  mmatula
24
 * @author  mmatula
24
 * @version 
25
 * @version 
Lines 32-43 Link Here
32
33
33
    private static final String CONSTRUCTOR_DESCRIPTOR = "(Ljava/util/List;Ljava/util/Map;Ljava/util/List;)V";
34
    private static final String CONSTRUCTOR_DESCRIPTOR = "(Ljava/util/List;Ljava/util/Map;Ljava/util/List;)V";
34
35
35
    private StructGenerator(String className, Class ifc) {
36
    private StructGenerator(String className, Class ifc, Class superClass) {
36
        super(className, ifc, StructImpl.class);
37
        super(className, ifc, superClass);
37
    }
38
    }
38
39
39
    public static byte[] generateStruct(final String name, Class ifc) {
40
    public static byte[] generateStruct(final String name, Class ifc, Class superClass) {
40
	StructGenerator gen = new StructGenerator(name, ifc);
41
	StructGenerator gen = new StructGenerator(name, ifc, superClass);
41
	final byte[] classFile = gen.generateClassFile();
42
	final byte[] classFile = gen.generateClassFile();
42
43
43
	return classFile;
44
	return classFile;
(-)src/org/netbeans/mdr/handlers/StructImpl.java (-34 / +87 lines)
Lines 1-11 Link Here
1
/*
1
/*
2
 *                 Sun Public License Notice
2
 *                 Sun Public License Notice
3
 * 
3
 *
4
 * The contents of this file are subject to the Sun Public License
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
Lines 22-39 Link Here
22
import org.netbeans.mdr.storagemodel.*;
22
import org.netbeans.mdr.storagemodel.*;
23
23
24
/**
24
/**
25
 * Abstract base class for generated structure implementations.
26
 *
27
 * <p>[XXX]: Replacing this class by a repository parameter is not yet
28
 *   implemented. The problem is, that in {@link #newInstance(Class, List, Map, List)}
29
 *   there is no access to the <code>MdrStorage</code> which holds this parameter.</p>
25
 *
30
 *
26
 * @author  mmatula
31
 * @author  mmatula
27
 * @version 
32
 * @version
28
 */
33
 */
29
public abstract class StructImpl extends ImplClass implements RefStruct {
34
public abstract class StructImpl extends ImplClass implements RefStruct {
30
    private final List fields;
35
    
31
    // field values
36
    /* -------------------------------------------------------------------- */
32
    private final Map values;
37
    /* -- Factory methods (static) ---------------------------------------- */
33
    // fully qualified name of metaobject
38
    /* -------------------------------------------------------------------- */
34
    private final List qualifiedName;
39
    
35
40
    /**
36
    private static Class getStructClass(MDRClassLoader loader, Class ifc) throws IllegalArgumentException {
41
     * Returns the structure implementation implementing <code>ifc</code>.
42
     *
43
     * @param loader the class-loader for the definition of the implementation class
44
     * @param ifc the interface to be implementated by the implementation class
45
     * @param superClass the super class for structure implementations
46
     * @return a class implementing <code>ifc</code>
47
     */
48
    private static Class getStructClass(MDRClassLoader loader, Class ifc, Class superClass) throws IllegalArgumentException {
37
        check(loader, ifc);
49
        check(loader, ifc);
38
        Map cache = getLoaderCache(loader);
50
        Map cache = getLoaderCache(loader);
39
        String className = getName(ifc);
51
        String className = getName(ifc);
Lines 41-47 Link Here
41
        
53
        
42
        if (result == null) {
54
        if (result == null) {
43
            try {
55
            try {
44
                byte[] structClassFile = StructGenerator.generateStruct(className, ifc);
56
                byte[] structClassFile = StructGenerator.generateStruct(className, ifc, superClass);
45
                result = loader.defineClass(className, structClassFile);
57
                result = loader.defineClass(className, structClassFile);
46
            } finally {
58
            } finally {
47
                releaseCache(cache, result, className);
59
                releaseCache(cache, result, className);
Lines 51-56 Link Here
51
        return result;
63
        return result;
52
    }
64
    }
53
    
65
    
66
    private static Class getStructClass(MDRClassLoader loader, Class ifc) throws IllegalArgumentException {
67
        return getStructClass(loader, ifc, StructImpl.class);
68
    }
69
    
54
    public static RefStruct newInstance(DatatypeDescriptor dataType, Object fieldValues[]) {
70
    public static RefStruct newInstance(DatatypeDescriptor dataType, Object fieldValues[]) {
55
        try {
71
        try {
56
            HashMap values = new HashMap(fieldValues.length, 1);
72
            HashMap values = new HashMap(fieldValues.length, 1);
Lines 70-119 Link Here
70
        }
86
        }
71
    }
87
    }
72
    
88
    
89
    /**
90
     * @param ifc  the specific JMI interface for the structure type
91
     * @param fields list of field names
92
     * @param values maps field names to field values
93
     * @param qualifiedName fully qualified name of the structure type
94
     */
73
    public static RefStruct newInstance(Class ifc, List fields, Map values, List qualifiedName) {
95
    public static RefStruct newInstance(Class ifc, List fields, Map values, List qualifiedName) {
74
        MDRClassLoader loader = BaseObjectHandler.getDefaultClassLoader();
96
        MDRClassLoader loader = BaseObjectHandler.getDefaultClassLoader();
75
	Class cl = getStructClass(loader, ifc);
97
        Class cl = getStructClass(loader, ifc, StructImpl.class);
76
98
        
77
        try {
99
        try {
78
            Constructor cons = cl.getConstructor(new Class[] {List.class, Map.class, List.class});
100
            Constructor cons = cl.getConstructor(new Class[] {List.class, Map.class, List.class});
79
            RefStruct struct = (RefStruct) cons.newInstance(new Object[] {fields, values, qualifiedName});
101
            RefStruct struct = (RefStruct) cons.newInstance(new Object[] {fields, values, qualifiedName});
80
102
            
81
            return struct;
103
            return struct;
82
	} catch (NoSuchMethodException e) {
104
        } catch (NoSuchMethodException e) {
83
            e.printStackTrace();
105
            e.printStackTrace();
84
	    throw new DebugException(e.toString());
106
            throw new DebugException(e.toString());
85
	} catch (IllegalAccessException e) {
107
        } catch (IllegalAccessException e) {
86
            e.printStackTrace();
108
            e.printStackTrace();
87
	    throw new DebugException(e.toString());
109
            throw new DebugException(e.toString());
88
	} catch (InstantiationException e) {
110
        } catch (InstantiationException e) {
89
            e.printStackTrace();
111
            e.printStackTrace();
90
	    throw new DebugException(e.toString());
112
            throw new DebugException(e.toString());
91
	} catch (InvocationTargetException e) {
113
        } catch (InvocationTargetException e) {
92
            e.printStackTrace();
114
            e.printStackTrace();
93
	    throw new DebugException(e.toString());
115
            throw new DebugException(e.toString());
94
	}
116
        }
95
    }
117
    }
96
118
    
119
    /* -------------------------------------------------------------------- */
120
    /* -- Attributes (private) -------------------------------------------- */
121
    /* -------------------------------------------------------------------- */
122
123
    /**
124
     * Field names
125
     */
126
    private final List fields;
127
    /**
128
     * Field names =&gt; values
129
     */
130
    private final Map values;
131
    /**
132
     * Fully qualified name of metaobject
133
     */
134
    private final List qualifiedName;
135
    
136
    /* -------------------------------------------------------------------- */
137
    /* -- Constructor (protected) ----------------------------------------- */
138
    /* -------------------------------------------------------------------- */
139
    
97
    /** Creates new StructHandler */
140
    /** Creates new StructHandler */
98
    protected StructImpl(List fields, Map values, List qualifiedName) {
141
    protected StructImpl(List fields, Map values, List qualifiedName) {
99
        this.values = values;
142
        this.values = values;
100
        this.qualifiedName = Collections.unmodifiableList(qualifiedName);
143
        this.qualifiedName = qualifiedName;
101
        this.fields = Collections.unmodifiableList(fields);
144
        this.fields = fields;
102
    }
145
    }
103
146
    
104
    // --- handler methods
147
    /* -------------------------------------------------------------------- */
105
148
    /* -- Methods to be called by generated classes ----------------------- */
149
    /* -------------------------------------------------------------------- */
150
    
106
    protected Object handleGet(String memberName) {
151
    protected Object handleGet(String memberName) {
107
        return refGetValue(memberName);
152
        return refGetValue(memberName);
108
    }
153
    }
109
154
    
110
    // --- implementation of RefStruct interface -------------------------------
155
    /* -------------------------------------------------------------------- */
111
156
    /* -- Implements of javax.jmi.reflect.RefStruct ----------------------- */
157
    /* -------------------------------------------------------------------- */
158
    
112
    public Object refGetValue(String memberName) {
159
    public Object refGetValue(String memberName) {
113
        if (values.containsKey(memberName)) {
160
        if (values.containsKey(memberName)) {
114
            return values.get(memberName);
161
            return values.get(memberName);
115
        } else {
162
        } else {
116
            throw new DebugException("Wrong item name: " + memberName);
163
            throw new InvalidNameException(memberName);
117
        }
164
        }
118
    }
165
    }
119
    
166
    
Lines 124-130 Link Here
124
    public List refTypeName() {
171
    public List refTypeName() {
125
        return this.qualifiedName;
172
        return this.qualifiedName;
126
    }
173
    }
127
174
    
175
    /* -------------------------------------------------------------------- */
176
    /* -- Extends java.lang.Object ---------------------------------------- */
177
    /* -------------------------------------------------------------------- */
178
    
179
    // [XXX]: hashCode() must be implemented, too !
180
    
128
    public boolean equals(Object other) {
181
    public boolean equals(Object other) {
129
        // check whether other is instance of the same structure
182
        // check whether other is instance of the same structure
130
        if ((other instanceof RefStruct) && ((RefStruct) other).refTypeName().equals(qualifiedName)) {
183
        if ((other instanceof RefStruct) && ((RefStruct) other).refTypeName().equals(qualifiedName)) {
(-)src/org/netbeans/mdr/handlers/gen/HandlerGenerator.java (-1 / +6 lines)
Lines 56-61 Link Here
56
    /**
56
    /**
57
     * Generate a handler class given a name, interface and storable object to
57
     * Generate a handler class given a name, interface and storable object to
58
     * be wrapped by a handler object.
58
     * be wrapped by a handler object.
59
     *
60
     * @param name the name of the handler class
61
     * @param ifc JMI interface to be implemented by the handler class
62
     * @param storable informs about the super-class for the handler class
63
     * @return the byte code for the class implementing <code>ifc</code>
59
     */
64
     */
60
    public static byte[] generateHandler(final String name, Class ifc, StorableBaseObject storable) {
65
    public static byte[] generateHandler(final String name, Class ifc, StorableBaseObject storable) {
61
        HandlerGenerator gen;
66
        HandlerGenerator gen;
Lines 65-71 Link Here
65
            } else if (storable instanceof StorableClass) {
70
            } else if (storable instanceof StorableClass) {
66
                gen = new ClassGenerator(name, ifc, ((StorableClass) storable).getClassSuperclass(), (StorableClass)storable);
71
                gen = new ClassGenerator(name, ifc, ((StorableClass) storable).getClassSuperclass(), (StorableClass)storable);
67
            } else if (storable instanceof StorablePackage) {
72
            } else if (storable instanceof StorablePackage) {
68
                gen = new PackageGenerator(name, ifc, PackageProxyHandler.class, (StorablePackage)storable);
73
                gen = new PackageGenerator(name, ifc, ((StorablePackage)storable).getPackageSuperclass(), (StorablePackage)storable);
69
            } else if (storable instanceof StorableObject) {
74
            } else if (storable instanceof StorableObject) {
70
                gen = new InstanceGenerator(name, ifc, ((StorableObject) storable).getClassProxy().getInstanceSuperclass(), (StorableObject)storable);
75
                gen = new InstanceGenerator(name, ifc, ((StorableObject) storable).getClassProxy().getInstanceSuperclass(), (StorableObject)storable);
71
            } else {
76
            } else {
(-)src/org/netbeans/mdr/persistence/MultivaluedIndex.java (-1 / +1 lines)
Lines 19-25 Link Here
19
 */
19
 */
20
public interface MultivaluedIndex extends Index {
20
public interface MultivaluedIndex extends Index {
21
    /** Returns a collection view of the values associated in the index with specified key.
21
    /** Returns a collection view of the values associated in the index with specified key.
22
     * Returned collection is read only and may not be modified.
22
     * Returned collection is live and modifiable.
23
     * If there are no values associated with the key empty collection is returned.
23
     * If there are no values associated with the key empty collection is returned.
24
     * @return
24
     * @return
25
     * @param key
25
     * @param key
(-)src/org/netbeans/mdr/persistence/MultivaluedOrderedIndex.java (-1 / +1 lines)
Lines 19-25 Link Here
19
 */
19
 */
20
public interface MultivaluedOrderedIndex extends MultivaluedIndex {
20
public interface MultivaluedOrderedIndex extends MultivaluedIndex {
21
    /** Returns a list view of the values assosiated in the index with specified key.
21
    /** Returns a list view of the values assosiated in the index with specified key.
22
     * Returned collection is read only and may not be modified.
22
     * Returned collection is live and modifiable.
23
     * If there are no values associated with the key empty collection is returned.
23
     * If there are no values associated with the key empty collection is returned.
24
     * @param key
24
     * @param key
25
     * @return
25
     * @return
(-)src/org/netbeans/mdr/shell/Main.java (-5 / +43 lines)
Lines 1-17 Link Here
1
/*
1
/*
2
 *                 Sun Public License Notice
2
 *                 Sun Public License Notice
3
 * 
3
 *
4
 * The contents of this file are subject to the Sun Public License
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
package org.netbeans.mdr.shell;
13
package org.netbeans.mdr.shell;
14
14
15
import java.io.FileInputStream;
16
import java.io.FileNotFoundException;
17
import java.io.InputStream;
18
15
import java.util.Collection;
19
import java.util.Collection;
16
import java.util.ArrayList;
20
import java.util.ArrayList;
17
import java.util.Iterator;
21
import java.util.Iterator;
Lines 29-40 Link Here
29
import javax.jmi.reflect.*;
33
import javax.jmi.reflect.*;
30
34
31
public class Main extends Object {
35
public class Main extends Object {
32
    public static void main( String[] args ) {
36
    
37
    /**
38
     * Resources names of the standard library files
39
     */
40
    public static String[] STANDARD_LIBS = new String[] { "resources/start.ms", "resources/ext.ms" };
41
    
42
    /**
43
     *  Command line interface of the MDRShell. The MDRShell is a
44
     *  <em>Dynamic Java</em> shell with preprocessor. Before user input
45
     *  is processed the files <code>start.ms</code> and <code>ext.ms</code>
46
     *  in the package <code>org.netbeans.mdr.shell.resources</code> and the
47
     *  files given as command line arguments are processed.
48
     *
49
     *  @param args a list of file names read into the shell
50
     *  @throws FileNotFoundException if one of the arguments does not denote a
51
     *                         valid file name
52
     *  @throws SecurityException if there is no read access to a file given as
53
     *                          argument
54
     */
55
    public static void main( String[] args ) throws FileNotFoundException {
56
        /* the input streams */
57
        InputStream[] iss = new InputStream[STANDARD_LIBS.length+args.length+1];
58
        
59
        /* standard library files */
60
        for ( int i=0; i<STANDARD_LIBS.length; i++ ) {
61
            iss[i] = Main.class.getResourceAsStream(STANDARD_LIBS[i]);
62
        }
63
        /* files given as arguments */
64
        for ( int i=0; i<args.length; i++ ) {
65
            iss[STANDARD_LIBS.length+i] = new FileInputStream(args[i]);
66
        }
67
        /* System.in for user input */
68
        iss[STANDARD_LIBS.length+args.length] = System.in;
69
        
33
        // Create and run the shell
70
        // Create and run the shell
34
        new Shell().run( null );
71
        
72
        new Shell().run( iss );
35
        //System.out.println("saving data...");
73
        //System.out.println("saving data...");
36
        MDRManager.getDefault().shutdownAll();
74
        MDRManager.getDefault().shutdownAll();
37
75
        
38
        Log.out.unindent();
76
        Log.out.unindent();
39
    }
77
    }
40
}
78
}
(-)src/org/netbeans/mdr/shell/Shell.java (-2 / +17 lines)
Lines 188-198 Link Here
188
    // Public methods ----------------------------------------------------------
188
    // Public methods ----------------------------------------------------------
189
    
189
    
190
    /** Starts interpretting commands in the InputStream.
190
    /** Starts interpretting commands in the InputStream.
191
    * @param is InputStream to read commands from. If null the System.in is used.
191
    * @param is InputStream to read commands from. If <code>null</code>
192
     * <code>System.in</code> is used.
192
    */
193
    */
193
    public void run( InputStream is ) {
194
    public void run( InputStream is ) {
195
        run( new InputStream[] { is } );
196
    }
197
    
198
    /** Starts interpretting commands in the InputStreams.
199
    * @param iss InputStreams to read commands from. If <code>null</code>
200
    * <code>System.in</code> is used.
201
    */
202
    public void run( InputStream[] iss ) {
194
203
195
        pushInput( is == null ? System.in : is );
204
        if ( iss == null ) {
205
            pushInput(System.in);
206
        } else {
207
            for ( int i = iss.length-1; i >= 0; i-- ) {
208
                pushInput(iss[i]);
209
            }
210
        }
196
 
211
 
197
        DJava.initialize();
212
        DJava.initialize();
198
        DJava.declareVariable( "SHELL", this );
213
        DJava.declareVariable( "SHELL", this );
(-)src/org/netbeans/mdr/storagemodel/BootReader.java (-1 lines)
Lines 159-165 Link Here
159
    private Collection createInstances(Node xmiContent) {
159
    private Collection createInstances(Node xmiContent) {
160
        XmiUtils.XmiNodeIterator classes = new XmiUtils.XmiNodeIterator(xmiContent);
160
        XmiUtils.XmiNodeIterator classes = new XmiUtils.XmiNodeIterator(xmiContent);
161
        Collection result = createInstances(classes, null, "", null);
161
        Collection result = createInstances(classes, null, "", null);
162
        classes = new XmiUtils.XmiNodeIterator(xmiContent);
163
        resolveSuperClasses();
162
        resolveSuperClasses();
164
        resolveReferences();
163
        resolveReferences();
165
        setValues();
164
        setValues();
(-)src/org/netbeans/mdr/storagemodel/CompositeCollection.java (-8 / +41 lines)
Lines 23-30 Link Here
23
import org.netbeans.mdr.util.*;
23
import org.netbeans.mdr.util.*;
24
24
25
/**
25
/**
26
 * Instances of <code>CompositeCollection</code> are collections uniting several
26
 * Instances of <code>CompositeCollection</code> are immutable collections uniting
27
 * other collections. The methods of this class must be called in the following
27
 * several other collections. The methods of this class must be called in the following
28
 * order:
28
 * order:
29
 *
29
 *
30
 * <p><ol>
30
 * <p><ol>
Lines 32-41 Link Here
32
 *    <li>{@link addCollection(Collection} to add a collection forming a part of
32
 *    <li>{@link addCollection(Collection} to add a collection forming a part of
33
 *         the current collection</li>
33
 *         the current collection</li>
34
 *    <li>any accessor method</li>
34
 *    <li>any accessor method</li>
35
 * </ol>
35
 * </ol></p>
36
 *
36
 *
37
 * It is not allowed to add further collections after any of the accessors has
37
 * <p>It is not allowed to add further collections after any of the accessors has
38
 * been called.
38
 * been called.</p>
39
 *
40
 * <p>Because the collections added using @link addCollection(Collection} are added
41
 * as is and their members are accessed only, when to be returned by methods of
42
 * this class resp. its {@link Iterator}, instances of <code>CompositeCollection</code>
43
 * are live if and only if all of the composed collections are live.</p>
44
 *
45
 * <p><b>[XXX]:</b> Put this class into <code>org.netbeans.mdr.util</code>
46
 *  package.</p>
39
 *
47
 *
40
 * @author  mm109185
48
 * @author  mm109185
41
 */
49
 */
Lines 44-56 Link Here
44
    private final ArrayList innerCollections = new ArrayList();
52
    private final ArrayList innerCollections = new ArrayList();
45
    private volatile boolean canChange = true;
53
    private volatile boolean canChange = true;
46
    
54
    
47
    CompositeCollection() {
55
    public CompositeCollection() {
48
    }
56
    }
49
    
57
    
50
    /**
58
    /**
51
     * Adds a new collection. Can only be called before any accessor call.
59
     * Adds a new collection. Can only be called before any accessor call.
52
     */
60
     */
53
    void addCollection(Collection collection) {
61
    public void addCollection(Collection collection) {
54
        if (canChange) {
62
        if (canChange) {
55
            innerCollections.add(collection);
63
            innerCollections.add(collection);
56
        } else {
64
        } else {
Lines 122-151 Link Here
122
    public Object[] toArray() {
130
    public Object[] toArray() {
123
        return toArray(new Object[0]);
131
        return toArray(new Object[0]);
124
    }
132
    }
125
    
133
134
    /**
135
     * operation not supported
136
     */
126
    public void clear() {
137
    public void clear() {
127
        throw new UnsupportedOperationException();
138
        throw new UnsupportedOperationException();
128
    }
139
    }
129
    
140
    
141
    /**
142
     * operation not supported
143
     */
130
    public boolean addAll(Collection collection) {
144
    public boolean addAll(Collection collection) {
131
        throw new UnsupportedOperationException();
145
        throw new UnsupportedOperationException();
132
    }
146
    }
133
    
147
    
148
    /**
149
     * operation not supported
150
     */
134
    public boolean remove(Object obj) {
151
    public boolean remove(Object obj) {
135
        throw new UnsupportedOperationException();
152
        throw new UnsupportedOperationException();
136
    }
153
    }
137
    
154
    
155
    /**
156
     * operation not supported
157
     */
138
    public boolean add(Object obj) {
158
    public boolean add(Object obj) {
139
        throw new UnsupportedOperationException();
159
        throw new UnsupportedOperationException();
140
    }
160
    }
141
    
161
    
162
    /**
163
     * operation not supported
164
     */
142
    public boolean retainAll(Collection collection) {
165
    public boolean retainAll(Collection collection) {
143
        throw new UnsupportedOperationException();
166
        throw new UnsupportedOperationException();
144
    }
167
    }
145
    
168
    
169
    /**
170
     * operation not supported
171
     */
146
    public boolean removeAll(Collection collection) {
172
    public boolean removeAll(Collection collection) {
147
        throw new UnsupportedOperationException();
173
        throw new UnsupportedOperationException();
148
    }
174
    }
175
176
    /* --------------------------------------------------------------------- */
177
    /* -- CompositeIterator (inner class) ---------------------------------- */
178
    /* --------------------------------------------------------------------- */
149
    
179
    
150
    protected class CompositeIterator implements Iterator {
180
    protected class CompositeIterator implements Iterator {
151
        private final Iterator innerIterators;
181
        private final Iterator innerIterators;
Lines 174-179 Link Here
174
            return result;
204
            return result;
175
        }
205
        }
176
        
206
        
207
       /**
208
        * operation not supported
209
        */
177
        public void remove() {
210
        public void remove() {
178
            throw new UnsupportedOperationException();
211
            throw new UnsupportedOperationException();
179
        }
212
        }
(-)src/org/netbeans/mdr/storagemodel/DatatypeDescriptor.java (-37 / +144 lines)
Lines 1-11 Link Here
1
/*
1
/*
2
 *                 Sun Public License Notice
2
 *                 Sun Public License Notice
3
 * 
3
 *
4
 * The contents of this file are subject to the Sun Public License
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
Lines 24-49 Link Here
24
 */
24
 */
25
25
26
public class DatatypeDescriptor extends Object {
26
public class DatatypeDescriptor extends Object {
27
    
28
    /* --------------------------------------------------------------------- */
29
    /* -- Attributes (private) --------------------------------------------- */
30
    /* --------------------------------------------------------------------- */
31
    
32
    /**
33
     *
34
     */
27
    private final int memberIDs[];
35
    private final int memberIDs[];
36
    
37
    /**
38
     *
39
     */
28
    private final int memberTypeIDs[];
40
    private final int memberTypeIDs[];
41
    
42
    /**
43
     *
44
     */
29
    private final int ifcIndex;
45
    private final int ifcIndex;
46
    
47
    /**
48
     *
49
     */
30
    private final int typeNameIndex;
50
    private final int typeNameIndex;
31
    
51
    
52
    /**
53
     *
54
     */
32
    private final transient MdrStorage storage;
55
    private final transient MdrStorage storage;
33
    
56
    
34
    // name of the interface that the datatype maps to
57
    /**
58
     * name of the interface that the datatype maps to
59
     */
35
    private transient String ifcName = null;
60
    private transient String ifcName = null;
36
    // list of datatype members (enum. literals/structure fields)
61
    
62
    /**
63
     * list of datatype members (enum. literals/structure fields)
64
     */
37
    private transient List members = null;
65
    private transient List members = null;
38
    // list of datatypes of members (applicable for structure fields only)
66
    
67
    /**
68
     * list of datatypes of members (applicable for structure fields only)
69
     */
39
    private transient List memberTypes = null;
70
    private transient List memberTypes = null;
40
    // fully qualified name of datatype
71
    
41
    // (stored only for structs - FQNs for enums are hardcoded in their impls)
72
    /** fully qualified name of datatype
73
     * (stored only for structs - FQNs for enums are hardcoded in their impls)
74
     **/
42
    private transient List typeName = null;
75
    private transient List typeName = null;
43
    // storage id
76
    
77
    /**
78
     * storage id
79
     */
44
    private transient String storageId = null;
80
    private transient String storageId = null;
45
81
    
46
    // used for constructing structure descriptor
82
    /* --------------------------------------------------------------------- */
83
    /* -- Constructors (public/private) ------------------------------------ */
84
    /* --------------------------------------------------------------------- */
85
    
86
    /**
87
     * Creates a new structure descriptor.
88
     *
89
     * @param storage
90
     * @param typeName
91
     * @param memberTypes
92
     * @param ifcName
93
     * @param storageId
94
     */
47
    public DatatypeDescriptor(MdrStorage storage, List typeName, List members, List memberTypes, String ifcName, String storageId) {
95
    public DatatypeDescriptor(MdrStorage storage, List typeName, List members, List memberTypes, String ifcName, String storageId) {
48
        this.storage = storage;
96
        this.storage = storage;
49
        this.ifcName = ifcName;
97
        this.ifcName = ifcName;
Lines 58-64 Link Here
58
            this.typeNameIndex = 0;
106
            this.typeNameIndex = 0;
59
        } else {
107
        } else {
60
            this.typeName = Collections.unmodifiableList(typeName);
108
            this.typeName = Collections.unmodifiableList(typeName);
61
            this.typeNameIndex = storage.storageValues (this.storageId).store(typeName);
109
            this.typeNameIndex = storage.storageValues(this.storageId).store(typeName);
62
        }
110
        }
63
        if (memberTypes == null) {
111
        if (memberTypes == null) {
64
            this.memberTypeIDs = null;
112
            this.memberTypeIDs = null;
Lines 71-81 Link Here
71
        }
119
        }
72
    }
120
    }
73
    
121
    
74
    // used for creating enumeration descriptor
122
    /**
123
     * Create a new enumeration descriptor.
124
     *
125
     * @param storage
126
     * @param members
127
     * @param ifcName
128
     * @param storageId
129
     */
75
    public DatatypeDescriptor(MdrStorage storage, List members, String ifcName, String storageId) {
130
    public DatatypeDescriptor(MdrStorage storage, List members, String ifcName, String storageId) {
76
        this(storage, null, members, null, ifcName, storageId);
131
        this(storage, null, members, null, ifcName, storageId);
77
    }
132
    }
78
    
133
134
    /**
135
     * Constructor used during deserialization.
136
     *
137
     * @param storage
138
     * @param typeNameIndex
139
     * @param memberIDs
140
     * @param memberTypeIDs
141
     * @param ifcIndex
142
     * @param storageId
143
     */
79
    private DatatypeDescriptor(MdrStorage storage, int typeNameIndex, int[] memberIDs, int[] memberTypeIDs, int ifcIndex, String storageId) {
144
    private DatatypeDescriptor(MdrStorage storage, int typeNameIndex, int[] memberIDs, int[] memberTypeIDs, int ifcIndex, String storageId) {
80
        this.storage = storage;
145
        this.storage = storage;
81
        this.typeNameIndex = typeNameIndex;
146
        this.typeNameIndex = typeNameIndex;
Lines 85-133 Link Here
85
        this.storageId = storageId;
150
        this.storageId = storageId;
86
    }
151
    }
87
    
152
    
88
    public synchronized List getMembers() {
153
    /* --------------------------------------------------------------------- */
154
    /* -- Getters (with lazy initialization) ------------------------------- */
155
    /* --------------------------------------------------------------------- */
156
    
157
    /**
158
     *
159
     */
160
    public List getMembers() {
89
        if (members == null) {
161
        if (members == null) {
90
            members = new ArrayList(memberIDs.length);
162
            synchronized(this) {
91
            for (int i = 0; i < memberIDs.length; i++) {
163
                if (members == null ) {
92
                members.add(storage.storageValues(this.storageId).resolve(memberIDs[i]));
164
                    members = new ArrayList(memberIDs.length);
165
                    for (int i = 0; i < memberIDs.length; i++) {
166
                        members.add(storage.storageValues(this.storageId).resolve(memberIDs[i]));
167
                    }
168
                    members = Collections.unmodifiableList(members);
169
                }
93
            }
170
            }
94
            members = Collections.unmodifiableList(members);
95
        }
171
        }
96
        return members;
172
        return members;
97
    }
173
    }
98
174
    
99
    public synchronized List getMemberTypes() {
175
    /**
100
        if (memberTypeIDs == null) return null;
176
     *
177
     */
178
    public List getMemberTypes() {
101
        if (memberTypes == null) {
179
        if (memberTypes == null) {
102
            memberTypes = new ArrayList(memberTypeIDs.length);
180
            if (memberTypeIDs == null) return null;
103
            for (int i = 0; i < memberTypeIDs.length; i++) {
181
            synchronized(this) {
104
                try {
182
                if (memberTypes == null) {
105
                    memberTypes.add(BaseObjectHandler.resolveInterface((String) storage.storageValues(this.storageId).resolve(memberTypeIDs[i])));
183
                    memberTypes = new ArrayList(memberTypeIDs.length);
106
                } catch (ClassNotFoundException e) {
184
                    for (int i = 0; i < memberTypeIDs.length; i++) {
107
                    e.printStackTrace();
185
                        try {
108
                    throw new DebugException();
186
                            memberTypes.add(BaseObjectHandler.resolveInterface((String) storage.storageValues(this.storageId).resolve(memberTypeIDs[i])));
187
                        } catch (ClassNotFoundException e) {
188
                            e.printStackTrace();
189
                            throw new DebugException();
190
                        }
191
                    }
192
                    memberTypes = Collections.unmodifiableList(memberTypes);
109
                }
193
                }
110
            }
194
            }
111
            memberTypes = Collections.unmodifiableList(memberTypes);
112
        }
195
        }
113
        return memberTypes;
196
        return memberTypes;
114
    }
197
    }
115
198
    
116
    public synchronized List getTypeName() {
199
    /**
200
     *
201
     */
202
    public List getTypeName() {
117
        if (typeName == null) {
203
        if (typeName == null) {
118
            typeName = (List) storage.storageValues(this.storageId).resolve(typeNameIndex);
204
            synchronized(this) {
205
                if (typeName == null ) {
206
                    typeName = (List) storage.storageValues(this.storageId).resolve(typeNameIndex);
207
                    typeName = Collections.unmodifiableList(typeName);
208
                }
209
            }
119
        }
210
        }
120
        return typeName;
211
        return typeName;
121
    }
212
    }
122
213
    
123
    public synchronized String getIfcName() {
214
    /**
215
     *
216
     */
217
    public String getIfcName() {
124
        if (ifcName == null) {
218
        if (ifcName == null) {
125
            ifcName = (String) storage.storageValues(this.storageId).resolve(ifcIndex);
219
            synchronized(this) {
220
                if (ifcName == null) {
221
                    ifcName = (String) storage.storageValues(this.storageId).resolve(ifcIndex);
222
                }
223
            }
126
        }
224
        }
127
        
128
        return ifcName;
225
        return ifcName;
129
    }
226
    }
130
    
227
228
    /* --------------------------------------------------------------------- */
229
    /* -- Read/Write ------------------------------------------------------- */
230
    /* --------------------------------------------------------------------- */
231
    
232
    /**
233
     *
234
     */
131
    static DatatypeDescriptor readResolve(java.io.InputStream inputStream, StorableBaseObject storable) throws java.io.IOException {
235
    static DatatypeDescriptor readResolve(java.io.InputStream inputStream, StorableBaseObject storable) throws java.io.IOException {
132
        int typeNameIndex = IOUtils.readInt(inputStream);
236
        int typeNameIndex = IOUtils.readInt(inputStream);
133
        int[] memberIDs = new int[IOUtils.readInt(inputStream)];
237
        int[] memberIDs = new int[IOUtils.readInt(inputStream)];
Lines 146-151 Link Here
146
        return new DatatypeDescriptor(storable.getMdrStorage(), typeNameIndex, memberIDs, memberTypeIDs, IOUtils.readInt(inputStream), MdrStorage.getStorageIdFromMofId(storable.getMofId()));
250
        return new DatatypeDescriptor(storable.getMdrStorage(), typeNameIndex, memberIDs, memberTypeIDs, IOUtils.readInt(inputStream), MdrStorage.getStorageIdFromMofId(storable.getMofId()));
147
    }
251
    }
148
    
252
    
253
    /**
254
     *
255
     */
149
    void write(java.io.OutputStream outputStream) throws java.io.IOException {
256
    void write(java.io.OutputStream outputStream) throws java.io.IOException {
150
        IOUtils.writeInt(outputStream, typeNameIndex);
257
        IOUtils.writeInt(outputStream, typeNameIndex);
151
        IOUtils.writeInt(outputStream, memberIDs.length);
258
        IOUtils.writeInt(outputStream, memberIDs.length);
(-)src/org/netbeans/mdr/storagemodel/IndexImmutSet.java (+52 lines)
Lines 18-36 Link Here
18
import org.netbeans.mdr.util.DebugException;
18
import org.netbeans.mdr.util.DebugException;
19
19
20
/**
20
/**
21
 * Instances of this class are immutable, live collections representing
22
 * results of index access.
21
 *
23
 *
22
 * @author  mm109185
24
 * @author  mm109185
23
 */
25
 */
24
public class IndexImmutSet implements Collection {
26
public class IndexImmutSet implements Collection {
27
    
28
    /* --------------------------------------------------------------------- */
29
    /* -- Attributes (protected) ------------------------------------------- */
30
    /* --------------------------------------------------------------------- */
31
    
25
    protected final MdrStorage storage;
32
    protected final MdrStorage storage;
26
    protected final MultivaluedIndex index;
33
    protected final MultivaluedIndex index;
27
    protected final Object indexKey;
34
    protected final Object indexKey;
28
    
35
    
36
    /* --------------------------------------------------------------------- */
37
    /* -- Constructor (protected) ------------------------------------------ */
38
    /* --------------------------------------------------------------------- */
39
    
40
    /**
41
     * @param storage
42
     * @param index  the index where to look up the members of the current collection
43
     * @param indexKey the key under which to look up the members of the current collection
44
     */
29
    protected IndexImmutSet(MdrStorage storage, MultivaluedIndex index, Object indexKey) {
45
    protected IndexImmutSet(MdrStorage storage, MultivaluedIndex index, Object indexKey) {
30
        this.storage = storage;
46
        this.storage = storage;
31
        this.index = index;
47
        this.index = index;
32
        this.indexKey = indexKey;
48
        this.indexKey = indexKey;
33
    }
49
    }
50
51
    /* --------------------------------------------------------------------- */
52
    /* -- Methods for index access ----------------------------------------- */
53
    /* --------------------------------------------------------------------- */
34
    
54
    
35
    protected Collection getItems() {
55
    protected Collection getItems() {
36
        try {
56
        try {
Lines 50-55 Link Here
50
        }
70
        }
51
    }
71
    }
52
    
72
    
73
    /* --------------------------------------------------------------------- */
74
    /* -- implements java.util.Collection ---------------------------------- */
75
    /* --------------------------------------------------------------------- */
76
    
53
    public int size() {
77
    public int size() {
54
        return getItems().size();
78
        return getItems().size();
55
    }
79
    }
Lines 78-107 Link Here
78
        return getObjects().toArray();
102
        return getObjects().toArray();
79
    }
103
    }
80
    
104
    
105
   /**
106
    * operation not supported
107
    */
81
    public boolean remove(Object o) {
108
    public boolean remove(Object o) {
82
        throw new UnsupportedOperationException();
109
        throw new UnsupportedOperationException();
83
    }        
110
    }        
84
    
111
    
112
   /**
113
    * operation not supported
114
    */
85
    public boolean add(Object obj) {
115
    public boolean add(Object obj) {
86
        throw new UnsupportedOperationException();
116
        throw new UnsupportedOperationException();
87
    }
117
    }
88
    
118
    
119
   /**
120
    * operation not supported
121
    */
89
    public boolean removeAll(Collection collection) {
122
    public boolean removeAll(Collection collection) {
90
        throw new UnsupportedOperationException();
123
        throw new UnsupportedOperationException();
91
    }
124
    }
92
    
125
    
126
   /**
127
    * operation not supported
128
    */
93
    public boolean addAll(Collection collection) {
129
    public boolean addAll(Collection collection) {
94
        throw new UnsupportedOperationException();
130
        throw new UnsupportedOperationException();
95
    }
131
    }
96
    
132
    
133
   /**
134
    * operation not supported
135
    */
97
    public boolean retainAll(Collection collection) {
136
    public boolean retainAll(Collection collection) {
98
        throw new UnsupportedOperationException();
137
        throw new UnsupportedOperationException();
99
    }
138
    }
100
    
139
    
140
   /**
141
    * operation not supported
142
    */
101
    public void clear() {
143
    public void clear() {
102
        throw new UnsupportedOperationException();
144
        throw new UnsupportedOperationException();
103
    }
145
    }
104
    
146
    
147
    /* --------------------------------------------------------------------- */
148
    /* -- IndexImmutIterator (inner class) --------------------------------- */
149
    /* --------------------------------------------------------------------- */
150
    
151
    /**
152
     * Wrapper for the index access iterator diabling modifying accesses.
153
     */
105
    protected class IndexImmutIterator implements Iterator {
154
    protected class IndexImmutIterator implements Iterator {
106
        protected Iterator innerIterator;
155
        protected Iterator innerIterator;
107
        
156
        
Lines 117-122 Link Here
117
            return innerIterator.next();
166
            return innerIterator.next();
118
        }
167
        }
119
        
168
        
169
       /**
170
        * operation not supported
171
        */
120
        public void remove() {
172
        public void remove() {
121
            throw new UnsupportedOperationException();
173
            throw new UnsupportedOperationException();
122
        }
174
        }
(-)src/org/netbeans/mdr/storagemodel/MdrStorage.java (-22 / +179 lines)
Lines 48-54 Link Here
48
    /* -------------------------------------------------------------------- */
48
    /* -------------------------------------------------------------------- */
49
    /* -- Private static constants ---------------------------------------- */
49
    /* -- Private static constants ---------------------------------------- */
50
    /* -------------------------------------------------------------------- */
50
    /* -------------------------------------------------------------------- */
51
51
    
52
    private static final int STORAGE_VERSION = 12;
52
    private static final int STORAGE_VERSION = 12;
53
    
53
    
54
    // names of global storage indexes
54
    // names of global storage indexes
Lines 156-161 Link Here
156
    /* -- Transient support ---*/
156
    /* -- Transient support ---*/
157
    private long transientSerialNumber = 0;
157
    private long transientSerialNumber = 0;
158
    
158
    
159
    /**
160
     * The default super-class for package proxy implementations.
161
     */
162
    private Class packageProxyHandlerClass = null;
163
    
164
    /**
165
     * The default super-class for class proxy implementations.
166
     */
167
    private Class classProxyHandlerClass = null;
168
    
169
    /**
170
     * The default super-class for instance implementations.
171
     */
172
    private Class instanceHandlerClass = null;
173
    
174
    /**
175
     * The default super-class for association implementations.
176
     */
177
    private Class associationHandlerClass = null;
178
    
179
    /**
180
     * The super-class for structure implementations.
181
     */
182
    private Class structureHandlerClass = null;
183
    
184
    /** The constructor parameters */
185
    private Map params;
186
    
159
    /* -- boot specific stuff --------------------------------------------- */
187
    /* -- boot specific stuff --------------------------------------------- */
160
    
188
    
161
    /**
189
    /**
Lines 169-175 Link Here
169
    /** boot association proxies */
197
    /** boot association proxies */
170
    private Collection bootAssociations = null;
198
    private Collection bootAssociations = null;
171
    
199
    
172
    
173
    /* -------------------------------------------------------------------- */
200
    /* -------------------------------------------------------------------- */
174
    /* -- Setters/Getters (public) ---------------------------------------- */
201
    /* -- Setters/Getters (public) ---------------------------------------- */
175
    /* -------------------------------------------------------------------- */
202
    /* -------------------------------------------------------------------- */
Lines 199-219 Link Here
199
    }
226
    }
200
    
227
    
201
    /* -------------------------------------------------------------------- */
228
    /* -------------------------------------------------------------------- */
229
    /* -- Getters for names of implementation classes --------------------- */
230
    /* -------------------------------------------------------------------- */
231
    
232
    /**
233
     * Returns the class to be used as base class for package proxy
234
     * implementations.
235
     */
236
    Class getPackageProxyHandlerClass() throws ClassNotFoundException {
237
        if (packageProxyHandlerClass == null) {
238
          synchronized ( this ) {
239
            if (packageProxyHandlerClass == null) {
240
//              String className = (String) params.get("PackageProxyHandler");
241
//              if ( className != null ) {
242
//                try {
243
//                    packageProxyHandlerClass = BaseObjectHandler.resolveImplementation(className);
244
//                } catch (ClassNotFoundException e) {
245
//                    e.printStackTrace();
246
//                }
247
//              }
248
//              if ( packageProxyHandlerClass == null ) {
249
                packageProxyHandlerClass = PackageProxyHandler.class;
250
//              }
251
            }
252
          }
253
        }
254
        return packageProxyHandlerClass;
255
    }
256
    
257
    /**
258
     * Returns the default class to be used as base class for class proxy
259
     * implementations.
260
     */
261
    Class getClassProxyHandlerClass() throws ClassNotFoundException {
262
        if (classProxyHandlerClass == null) {
263
            synchronized(this) {
264
                if (classProxyHandlerClass == null) {
265
//                    String className = (String) params.get("ClassProxyHandler");
266
//                    if ( className != null ) {
267
//                        try {
268
//                            classProxyHandlerClass = BaseObjectHandler.resolveImplementation(className);
269
//                        } catch (ClassNotFoundException e) {
270
//                            e.printStackTrace();
271
//                        }
272
//                    }
273
//                    if ( classProxyHandlerClass == null ) {
274
                        classProxyHandlerClass = ClassProxyHandler.class;
275
//                    }
276
                }
277
            }
278
        }
279
        return classProxyHandlerClass;
280
    }
281
    
282
    /**
283
     * Returns the default class to be used as base class for instance
284
     * implementations.
285
     */
286
    Class getInstanceHandlerClass() throws ClassNotFoundException {
287
        if (instanceHandlerClass == null) {
288
            synchronized(this) {
289
                if (instanceHandlerClass == null) {
290
//                    String className = (String) params.get("InstanceHandler");
291
//                    if ( className != null ) {
292
//                        try {
293
//                            instanceHandlerClass = BaseObjectHandler.resolveImplementation(className);
294
//                        } catch (ClassNotFoundException e) {
295
//                            e.printStackTrace();
296
//                        }
297
//                    }
298
//                    if ( instanceHandlerClass == null ) {
299
                        instanceHandlerClass = InstanceHandler.class;
300
//                    }
301
                }
302
            }
303
        }
304
        return instanceHandlerClass;
305
    }
306
    
307
    /**
308
     * Returns the default class to be used as base class for association proxy
309
     * implementations.
310
     */
311
    Class getAssociationHandlerClass() throws ClassNotFoundException {
312
        if (associationHandlerClass == null) {
313
            synchronized(this) {
314
                if (associationHandlerClass == null) {
315
//                    String className = (String) params.get("AssociationHandler");
316
//                    if ( className != null ) {
317
//                        try {
318
//                            associationHandlerClass = BaseObjectHandler.resolveImplementation(className);
319
//                        } catch (ClassNotFoundException e) {
320
//                            e.printStackTrace();
321
//                        }
322
//                    }
323
//                    if ( associationHandlerClass == null ) {
324
                        associationHandlerClass = AssociationHandler.class;
325
//                    }
326
                }
327
            }
328
        }
329
        return associationHandlerClass;
330
    }
331
    
332
    /**
333
     * Returns the class to be used as base class for structure
334
     * implementations.
335
     */
336
    public Class getStructureHandlerClass() throws ClassNotFoundException {
337
        if (structureHandlerClass == null) {
338
            synchronized(this) {
339
                if (structureHandlerClass == null) {
340
//                    String className = (String) params.get("StructureHandler");
341
//                    if ( className != null ) {
342
//                        try {
343
//                            structureHandlerClass = BaseObjectHandler.resolveImplementation(className);
344
//                        } catch (ClassNotFoundException e) {
345
//                            e.printStackTrace();
346
//                        }
347
//                    }
348
//                    if ( structureHandlerClass == null ) {
349
                        structureHandlerClass = StructImpl.class;
350
//                    }
351
                }
352
            }
353
        }
354
        return structureHandlerClass;
355
    }
356
    
357
    /* -------------------------------------------------------------------- */
202
    /* -- Constructor (public) -------------------------------------------- */
358
    /* -- Constructor (public) -------------------------------------------- */
203
    /* -------------------------------------------------------------------- */
359
    /* -------------------------------------------------------------------- */
204
    
360
    
205
    /** Creates a new <code>MdrStorage</code> using factory <code>storageClass</code>
361
    /** Creates a new <code>MdrStorage</code> using factory <code>storageFactoryClassName</code>
206
     *  and parameters <code>properties</code>. Creates a default storage, if the
362
     *  and parameters <code>params</code>. Creates a default storage, if the
207
     *  <code>storageClass</code> is not a
363
     *  <code>storageFactoryClassName</code> is not a
208
     * {@link org.netbeans.mdr.persistence.StorageFactory} or cannot be instantiated.
364
     * {@link org.netbeans.mdr.persistence.StorageFactory} or cannot be instantiated.
209
     *
365
     *
210
     *  @param repository
366
     *  @param repository
211
     *  @param storageClass fully qualified name of class implementing
367
     *  @param storageFactoryClassName fully qualified name of class implementing
212
     *         {@link org.netbeans.mdr.persistence.StorageFactory}
368
     *         {@link org.netbeans.mdr.persistence.StorageFactory}
213
     *  @param properties parameters for storage creation
369
     *  @param params parameters for storage creation
214
     *  @exception DebugException if the storage cannot be created
370
     *  @exception DebugException if the storage cannot be created
215
     */
371
     */
216
    public MdrStorage(NBMDRepositoryImpl repository, String storageClass, Map properties) {
372
    public MdrStorage(NBMDRepositoryImpl repository, String storageFactoryClassName, Map params) {
217
        this.storages = new HashMap();
373
        this.storages = new HashMap();
218
        this.nullMofId = new HashMap();
374
        this.nullMofId = new HashMap();
219
        this.objects = new HashMap();
375
        this.objects = new HashMap();
Lines 223-232 Link Here
223
        this.valuesObjects = new HashMap();
379
        this.valuesObjects = new HashMap();
224
        
380
        
225
        this.repository = repository;
381
        this.repository = repository;
382
        
383
        this.params = params;
226
        StorageFactory storageFactory = null;
384
        StorageFactory storageFactory = null;
227
        try {
385
        try {
228
            // try to instantiate storage factory (its class name was passed as storageClass argument)
386
            // try to instantiate storage factory (its class name was passed as storageClass argument)
229
            Class storageFactoryClass = Class.forName(storageClass);
387
            Class storageFactoryClass = Class.forName(storageFactoryClassName);
230
            // does the class implement StorageFactory interface?
388
            // does the class implement StorageFactory interface?
231
            if (StorageFactory.class.isAssignableFrom(storageFactoryClass)) {
389
            if (StorageFactory.class.isAssignableFrom(storageFactoryClass)) {
232
                // yes - create new instance
390
                // yes - create new instance
Lines 234-240 Link Here
234
            } else {
392
            } else {
235
                // no - throw exception
393
                // no - throw exception
236
                // (this exception will not be propagated - it will be caught immediately - see following lines)
394
                // (this exception will not be propagated - it will be caught immediately - see following lines)
237
                throw new Exception("class "+storageClass+" does not implement StorageFactory");
395
                throw new Exception("class "+storageFactoryClassName+" does not implement StorageFactory");
238
            }
396
            }
239
        } catch (Exception e) {
397
        } catch (Exception e) {
240
            // in case the passed StorageFactory class could not be created, create default implementation
398
            // in case the passed StorageFactory class could not be created, create default implementation
Lines 246-252 Link Here
246
        
404
        
247
        try {
405
        try {
248
            // create storage passing the parameters to the factory method
406
            // create storage passing the parameters to the factory method
249
            this.bootStorage = storageFactory.createStorage(properties);
407
            this.bootStorage = storageFactory.createStorage(params);
250
            // cache the NULL MOFID of the boot storage
408
            // cache the NULL MOFID of the boot storage
251
            this.bootNullMofId = storageFactory.createNullMOFID();
409
            this.bootNullMofId = storageFactory.createNullMOFID();
252
        } catch (StorageException e) {
410
        } catch (StorageException e) {
Lines 256-262 Link Here
256
        
414
        
257
        // create the utilities for storage management
415
        // create the utilities for storage management
258
        eventNotifier = new EventNotifier();
416
        eventNotifier = new EventNotifier();
259
        repositoryMutex = new TransactionMutex(this, eventNotifier);
417
        repositoryMutex = new TransactionMutex(this, eventNotifier, repository);
260
    }
418
    }
261
    
419
    
262
    /* -------------------------------------------------------------------- */
420
    /* -------------------------------------------------------------------- */
Lines 329-335 Link Here
329
    /* -- Methods for initialization and reinitialization (public/private)  */
487
    /* -- Methods for initialization and reinitialization (public/private)  */
330
    /* -------------------------------------------------------------------- */
488
    /* -------------------------------------------------------------------- */
331
    
489
    
332
    
333
    /** Initializes MdrStorage instance.
490
    /** Initializes MdrStorage instance.
334
     * This method is called by the {@link org.netbeans.mdr.NBMDRepositoryImpl repository}
491
     * This method is called by the {@link org.netbeans.mdr.NBMDRepositoryImpl repository}
335
     * during its initialization. It initializes resp. creates the boot storage.
492
     * during its initialization. It initializes resp. creates the boot storage.
Lines 910-916 Link Here
910
     *
1067
     *
911
     * @param context
1068
     * @param context
912
     * @param indexName
1069
     * @param indexName
913
     * @return  the index for the given attribute or <code>null</code> */    
1070
     * @return  the index for the given attribute or <code>null</code> */
914
    private MultivaluedIndex getAdditionalIndex(String context, String indexName) {
1071
    private MultivaluedIndex getAdditionalIndex(String context, String indexName) {
915
        try {
1072
        try {
916
            Storage storage = getStorageByMofId(context);
1073
            Storage storage = getStorageByMofId(context);
Lines 1234-1240 Link Here
1234
        Hashtable temp = new Hashtable();
1391
        Hashtable temp = new Hashtable();
1235
        Object key;
1392
        Object key;
1236
        String extent = getContextOutermostPackage(mofContext).getMofId();
1393
        String extent = getContextOutermostPackage(mofContext).getMofId();
1237
        
1394
         
1238
        // rebuild attribute indexes
1395
        // rebuild attribute indexes
1239
        SinglevaluedIndex attributeIndexes = bootStorage.getSinglevaluedIndex(PREFIX_ATTR_INDEXES_BY_NAME + extent);
1396
        SinglevaluedIndex attributeIndexes = bootStorage.getSinglevaluedIndex(PREFIX_ATTR_INDEXES_BY_NAME + extent);
1240
        String oldValue;
1397
        String oldValue;
Lines 1255-1261 Link Here
1255
            }
1412
            }
1256
            bootStorage.dropIndex(oldAttributeIndex.getName());
1413
            bootStorage.dropIndex(oldAttributeIndex.getName());
1257
        }
1414
        }
1258
        */
1415
         */
1259
        
1416
        
1260
        Object key;
1417
        Object key;
1261
        String newValue;
1418
        String newValue;
Lines 1515-1521 Link Here
1515
    private String getContextAssocEndIndexName(String context, String assocMofId, int end) {
1672
    private String getContextAssocEndIndexName(String context, String assocMofId, int end) {
1516
        return PREFIX_ASSOC_END + context + ":" + assocMofId + end;
1673
        return PREFIX_ASSOC_END + context + ":" + assocMofId + end;
1517
    }
1674
    }
1518
1675
    
1519
    public Storage getStorageByMofId(String mofId) {
1676
    public Storage getStorageByMofId(String mofId) {
1520
        String storageId = getStorageIdFromMofId(mofId);
1677
        String storageId = getStorageIdFromMofId(mofId);
1521
        if (storageId == null) {
1678
        if (storageId == null) {
Lines 1564-1576 Link Here
1564
    
1721
    
1565
    /** Transient support **/
1722
    /** Transient support **/
1566
    void registerTransientObjectsContainer(String mofId, TransientStorableClass tsc) {
1723
    void registerTransientObjectsContainer(String mofId, TransientStorableClass tsc) {
1567
        org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex tir = (org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex) 
1724
        org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex tir = (org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex)
1568
            this.objects.get (org.netbeans.mdr.storagemodel.transientimpl.MOFID.TRANSIENT_STORAGE_PREFIX);
1725
        this.objects.get(org.netbeans.mdr.storagemodel.transientimpl.MOFID.TRANSIENT_STORAGE_PREFIX);
1569
        if (tir == null) {
1726
        if (tir == null) {
1570
            tir = new org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex ();
1727
            tir = new org.netbeans.mdr.storagemodel.transientimpl.TransientObjectResolverIndex();
1571
            this.objects.put (org.netbeans.mdr.storagemodel.transientimpl.MOFID.TRANSIENT_STORAGE_PREFIX, tir);
1728
            this.objects.put(org.netbeans.mdr.storagemodel.transientimpl.MOFID.TRANSIENT_STORAGE_PREFIX, tir);
1572
        }
1729
        }
1573
        tir.register (mofId, tsc);
1730
        tir.register(mofId, tsc);
1574
    }
1731
    }
1575
    
1732
    
1576
    void unregisterTransientObjectsContainer(String mofId) throws StorageException {
1733
    void unregisterTransientObjectsContainer(String mofId) throws StorageException {
(-)src/org/netbeans/mdr/storagemodel/StorableAssociation.java (-18 / +156 lines)
Lines 150-156 Link Here
150
        if (((Boolean) getMetaObject().getAttribute(MOFConstants.SH_MODEL_ASSOCIATION_IS_DERIVED)).booleanValue() || TagSupport.getTagValue(getMetaObject(), INTERCEPTABLE_TAG_ID, "").equals("true"))
150
        if (((Boolean) getMetaObject().getAttribute(MOFConstants.SH_MODEL_ASSOCIATION_IS_DERIVED)).booleanValue() || TagSupport.getTagValue(getMetaObject(), INTERCEPTABLE_TAG_ID, "").equals("true"))
151
            return BaseObjectHandler.resolveImplementation(TagSupport.getImplFullName(getMetaObject(), TagSupport.ASSOCIATION));
151
            return BaseObjectHandler.resolveImplementation(TagSupport.getImplFullName(getMetaObject(), TagSupport.ASSOCIATION));
152
        else
152
        else
153
            return AssociationHandler.class;
153
            return getMdrStorage().getAssociationHandlerClass();
154
    }
154
    }
155
155
156
    /** Returns multiplicity of the first association end.
156
    /** Returns multiplicity of the first association end.
Lines 246-271 Link Here
246
    }
246
    }
247
247
248
    /**
248
    /**
249
     * Returns immutable, live collection of all links managed by this association
250
     * proxy.
251
     *
249
     * @throws StorageException
252
     * @throws StorageException
250
     * @return
253
     * @return immutable, live collection of all links
251
     */
254
     */
252
    public Collection getAllLinks() throws StorageException {
255
    public Collection getAllLinks() throws StorageException {
253
        ArrayList allLinks = new ArrayList ();
256
        return new LinkSetCollection();
254
255
        for (Iterator it = bIndex.keySet().iterator (); it.hasNext();) {
256
            String a = (String) it.next();
257
            if (isMultivaluedB()) {
258
                Collection bees = getMdrStorage().getObjectsFromIndex((MultivaluedIndex) bIndex, a);
259
                for (Iterator it2 = bees.iterator (); it2.hasNext();){
260
                    AssociationLink oneLink = new AssociationLink((StorableObject) getMdrStorage().getObject(a), (StorableObject) it2.next());
261
                    allLinks.add(oneLink);
262
                }
263
            } else {
264
                AssociationLink oneLink = new AssociationLink((StorableObject) getMdrStorage().getObject(a), (StorableObject) getMdrStorage().getObjectFromIndexIfExists((SinglevaluedIndex) bIndex, a));
265
                allLinks.add(oneLink);
266
            }
267
        }
268
        return Collections.unmodifiableCollection(allLinks);
269
    }
257
    }
270
258
271
    /**
259
    /**
Lines 567-571 Link Here
567
            e.printStackTrace();
555
            e.printStackTrace();
568
            throw new RuntimeException();
556
            throw new RuntimeException();
569
        }
557
        }
558
    }
559
    
560
    /* --------------------------------------------------------------------- */
561
    /* -- LinkSetCollection (inner class) ---------------------------------- */
562
    /* --------------------------------------------------------------------- */
563
    
564
    protected class LinkSetCollection extends AbstractCollection {
565
        
566
        public Iterator iterator() {
567
            return new LinkSetIterator();
568
        }
569
        
570
        public int size() {
571
            int size = 0;
572
            LinkSetIterator it = new LinkSetIterator();
573
            it.initCheck();
574
            while (it.b != null) {
575
                size++;
576
                it.fetchNext();
577
            }
578
            return size;
579
        }
580
    }
581
    
582
    /* --------------------------------------------------------------------- */
583
    /* -- LinkSetIterator (inner class) ------------------------------------ */
584
    /* --------------------------------------------------------------------- */
585
    
586
    protected class LinkSetIterator implements Iterator {
587
588
        boolean initialized = false;
589
        
590
        /**
591
         * Iterator through all instances at the a-side of this association or
592
         * <code>null</code> before the first access or if a storage problem
593
         * occured.
594
         */
595
        Iterator as = null;
596
        
597
        /**
598
         * MOF ID of the current instance at the a side. <code>null</code>
599
         * only before the first call to <code>fetchNext()</code>.
600
         */
601
        String aID = null;
602
        
603
        /**
604
         * Object with ID <code>aID</code> or <code>null</code> if not yet
605
         * retrieved.
606
         */
607
        StorableObject a = null;
608
        
609
        /**
610
         * If the association if multi-valued at b's end, <code>bs</code>
611
         * contains the iterator for the b's associated with the current a.
612
         * Shall only be accessed inside <code>fetchNext()</code>.
613
         */
614
        Iterator bs = null;
615
        
616
        /**
617
         * The current b object, <code>null</code> initially and after the
618
         * last link has been retrieved.
619
         */
620
        StorableObject b = null;
621
        
622
        private void initCheck() {
623
            if ( ! initialized ) {
624
                initialized = true;
625
                try {
626
                    as = bIndex.keySet().iterator();
627
                } catch ( StorageException se ) {
628
                    // [XXX]: probably throw a DebugException here
629
                    as = null;
630
                }
631
                fetchNext();
632
            }
633
        }
634
        
635
        private void fetchNext() {
636
            if ( as == null ) {
637
                return;
638
            }
639
            b = null;
640
            //  check if there is yet another b for the current a
641
            if ( bs != null ) {
642
                if ( bs.hasNext() ) {
643
                    b = (StorableObject) bs.next();
644
                    return;
645
                }
646
            }
647
            
648
            try {
649
                // fetch the next a
650
                while ( as.hasNext() ) {
651
                    aID = (String) as.next();
652
                    a = null;
653
                    // fetch the first b for the given a, if exists
654
                    if ( isMultivaluedB() ) {
655
                        bs = getMdrStorage().getObjectsFromIndex((MultivaluedIndex) bIndex, aID).iterator();
656
                        if ( bs.hasNext() ) {
657
                            b = (StorableObject) bs.next();
658
                        }
659
                    } else {
660
                        b = (StorableObject) getMdrStorage().getObjectFromIndexIfExists((SinglevaluedIndex) bIndex, aID);
661
                    }
662
                    // check, if a b was found, return, if yes
663
                    if ( b != null ) {
664
                        return;
665
                    }
666
                }
667
            } catch (StorageException se) {
668
                // [XXX]: probably throw a DebugException here
669
                as = null;
670
                b = null;
671
            }
672
            
673
            // there are not more links !
674
            return;
675
        }
676
        
677
        public boolean hasNext() {
678
            initCheck();
679
            return b != null;
680
        }
681
        
682
        public Object next() {
683
            initCheck();
684
            if ( b == null ) {
685
                throw new NoSuchElementException();
686
            }
687
            if ( a == null ) {
688
                try {
689
                    a = (StorableObject) getMdrStorage().getObject(aID);
690
                } catch (StorageException se) {
691
                    // {XXX]: better exception handling
692
                    se.printStackTrace();
693
                    throw new DebugException();
694
                }
695
            }
696
            AssociationLink link = new AssociationLink(a,b);
697
            fetchNext();
698
            return link;
699
        }
700
        
701
       /**
702
        * operation not supported
703
        */
704
        public void remove() {
705
            throw new UnsupportedOperationException();
706
        }
707
        
570
    }
708
    }
571
}
709
}
(-)src/org/netbeans/mdr/storagemodel/StorableClass.java (-11 / +43 lines)
Lines 224-232 Link Here
224
        return (DatatypeDescriptor) datatypes.get(name);
224
        return (DatatypeDescriptor) datatypes.get(name);
225
    }
225
    }
226
226
227
    /** Returns all instances of MOF class represented by this proxy within the current context.
227
    /** Returns immutable, live collection of all instances of MOF class
228
     * represented by this proxy.
229
     *
230
     * @param subclasses if <code>true</code> also the instances of sub-classes
231
     *     will be returned, otherwise only the instances of the current class
232
     * @return collection of instances of this class (and its sub-classes)
228
     * @throws StorageException problem in storage
233
     * @throws StorageException problem in storage
229
     * @return collection of instances
230
     */
234
     */
231
    public Collection allObjects(boolean subclasses) throws StorageException {
235
    public Collection allObjects(boolean subclasses) throws StorageException {
232
        if (subclasses) {
236
        if (subclasses) {
Lines 240-249 Link Here
240
        }
244
        }
241
    }
245
    }
242
246
247
    /**
248
     *  Adds the instances of this class and its super-classes to <code>result</code>
249
     *  and adds the MOF IDs of all visited class proxies to <code>visited</code>.
250
     *  Instances of a class already being a member of <code>visited</code> are
251
     *  not added to <code>result</code> a second time. 
252
     *
253
     * @param result the collection where to add the instances
254
     * @param visited MOF IDs of class proxies already visited
255
     */
243
    private void collectObjects(CompositeCollection result, Set visited) throws StorageException {
256
    private void collectObjects(CompositeCollection result, Set visited) throws StorageException {
244
        if (!visited.contains(getMofId())) {
257
        if (visited.add(getMofId())) {
245
            result.addCollection(allObjects(false));
258
            result.addCollection(allObjects(false));
246
            visited.add(getMofId());
247
            for (Iterator it = subclasses.iterator(); it.hasNext();) {
259
            for (Iterator it = subclasses.iterator(); it.hasNext();) {
248
                ((StorableClass) getMdrStorage().getObject((String) it.next())).collectObjects(result, visited);
260
                ((StorableClass) getMdrStorage().getObject((String) it.next())).collectObjects(result, visited);
249
            }
261
            }
Lines 449-454 Link Here
449
        visited.add(getMofId());
461
        visited.add(getMofId());
450
    }
462
    }
451
463
464
    /**
465
     * Returns the super-class for generated handler classes.
466
     */
452
    public Class getClassSuperclass() throws StorageException, ClassNotFoundException {
467
    public Class getClassSuperclass() throws StorageException, ClassNotFoundException {
453
        if (classSuperclass == null) {
468
        if (classSuperclass == null) {
454
            synchronized (superclassMutex) {
469
            synchronized (superclassMutex) {
Lines 485-490 Link Here
485
        return false;
500
        return false;
486
    }
501
    }
487
502
503
    /**
504
     * Returns the implementation super-class for the generated handler.
505
     *
506
     * <p>If the class has derived or inceptable members, {@link
507
     * TagSupport#getImplFullName(StorableObject, int)} determines the class
508
     * name.</p>
509
     *
510
     * <p>If this model class has model super-classes then the return value
511
     * depends on if there is a most specific implementation class among the
512
     * implementation classes of those super-classes. If yes, this most
513
     * specific implementation class is returned, otherwise {@link
514
     * TagSupport#getImplFullName(StorableObject, int)} determines the class
515
     * name.</p>
516
     *
517
     * <p>If non of the cases above applies, <code>ClassProxyHandler.class</code>
518
     * is returned as default value.</p>
519
     */
488
    private Class resolveClassSuperclass() throws StorageException, ClassNotFoundException {
520
    private Class resolveClassSuperclass() throws StorageException, ClassNotFoundException {
489
        Class result = null;
521
        Class result = null;
490
        if (classDerived) {
522
        if (classDerived) {
Lines 505-520 Link Here
505
                }
537
                }
506
            }
538
            }
507
            if (result == null) {
539
            if (result == null) {
508
                result = ClassProxyHandler.class;
540
                result = getMdrStorage().getClassProxyHandlerClass();
509
            }
541
            }
510
        }
542
        }
511
        return result;
543
        return result;
512
    }
544
    }
513
545
514
    private Class resolveClass(String className) throws ClassNotFoundException {
515
        return BaseObjectHandler.resolveImplementation(className);
516
    }
517
518
    private Class resolveInstanceSuperclass() throws StorageException, ClassNotFoundException {
546
    private Class resolveInstanceSuperclass() throws StorageException, ClassNotFoundException {
519
        Class result = null;
547
        Class result = null;
520
        if (instanceDerived || TagSupport.getTagValue(getMetaObject(), INTERCEPTABLE_TAG_ID, "").equals("true")) try {
548
        if (instanceDerived || TagSupport.getTagValue(getMetaObject(), INTERCEPTABLE_TAG_ID, "").equals("true")) try {
Lines 540-550 Link Here
540
                    }
568
                    }
541
                }
569
                }
542
            }
570
            }
543
            if (result == null) {
571
            if ( result == null ) {
544
                result = InstanceHandler.class;
572
                result = getMdrStorage().getInstanceHandlerClass();
545
            }
573
            }
546
        }
574
        }
547
        return result;
575
        return result;
576
    }
577
578
    private Class resolveClass(String className) throws ClassNotFoundException {
579
        return BaseObjectHandler.resolveImplementation(className);
548
    }
580
    }
549
581
550
    protected void deleteRecursive() throws StorageException {
582
    protected void deleteRecursive() throws StorageException {
(-)src/org/netbeans/mdr/storagemodel/StorablePackage.java (+7 lines)
Lines 54-59 Link Here
54
    }
54
    }
55
    
55
    
56
    /**
56
    /**
57
     * Returns the super-class for generated handler classes.
58
     */
59
    public Class getPackageSuperclass() throws StorageException, ClassNotFoundException {
60
        return getMdrStorage().getPackageProxyHandlerClass();
61
    }
62
    
63
    /**
57
     * @param pkgMeta
64
     * @param pkgMeta
58
     * @param clustered
65
     * @param clustered
59
     * @throws StorageException  
66
     * @throws StorageException  
(-)src/org/netbeans/mdr/util/ImplClass.java (-35 / +506 lines)
Lines 1-11 Link Here
1
/*
1
/*
2
 *                 Sun Public License Notice
2
 *                 Sun Public License Notice
3
 * 
3
 *
4
 * The contents of this file are subject to the Sun Public License
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
Lines 14-19 Link Here
14
14
15
import org.netbeans.api.mdr.events.*;
15
import org.netbeans.api.mdr.events.*;
16
import org.netbeans.mdr.handlers.BaseObjectHandler;
16
import org.netbeans.mdr.handlers.BaseObjectHandler;
17
import org.netbeans.mdr.storagemodel.CompositeCollection;
17
import java.util.*;
18
import java.util.*;
18
import javax.jmi.reflect.*;
19
import javax.jmi.reflect.*;
19
20
Lines 22-434 Link Here
22
 * after transactions.
23
 * after transactions.
23
 *
24
 *
24
 * @author  mmatula
25
 * @author  mmatula
25
 * @version 
26
 * @author <a href="mailto:hkrug@rationalizer.com>Holger Krug</code>.
27
 * @version
26
 */
28
 */
27
public final class EventNotifier {
29
public final class EventNotifier {
28
30
  
29
    /* -------------------------------------------------------------------- */
31
  /* -------------------------------------------------------------------- */
30
    /* -- Public attributes ----------------------------------------------- */
32
  /* -- Constants ------------------------------------------------------- */
31
    /* -------------------------------------------------------------------- */
33
  /* -------------------------------------------------------------------- */
32
34
  
33
    public final Association ASSOCIATION = new Association();
35
  /** Bitmask representing all event types which may be received by listeners
34
    public final Clazz CLASS = new Clazz();
36
   * listening on associations. */
35
    public final Instance INSTANCE = new Instance();
37
  public static final int EVENTMASK_BY_ASSOCIATION = MDRChangeEvent.EVENTMASK_ON_ASSOCIATION;
36
    public final Package PACKAGE = new Package();
38
  /** Bitmask representing all event types which may be received by listeners
37
    public final Repository REPOSITORY = new Repository();
39
   * listening on instances. */
38
40
  public static final int EVENTMASK_BY_INSTANCE = EVENTMASK_BY_ASSOCIATION | MDRChangeEvent.EVENTMASK_ON_INSTANCE;
39
    /* -------------------------------------------------------------------- */
41
  /** Bitmask representing all event types which may be received by listeners
40
    /* -- Private attributes ---------------------------------------------- */
42
   * listening on class proxies. */
41
    /* -------------------------------------------------------------------- */
43
  public static final int EVENTMASK_BY_CLASS = EVENTMASK_BY_INSTANCE | MDRChangeEvent.EVENTMASK_ON_CLASS;
42
    
44
  /** Bitmask representing all event types which may be received by listeners
43
    /**
45
   * listening on package proxies. */
44
     * Thread for the dispatching of events after transaction success.
46
  public static final int EVENTMASK_BY_PACKAGE = EVENTMASK_BY_CLASS | MDRChangeEvent.EVENTMASK_ON_PACKAGE;
45
     */
47
  /** Bitmask representing all event types which may be received by listeners
46
    private final Thread dispatcher = new Thread(new EventsDelivery());
48
   * listening on repository proxies. */
47
49
  public static final int EVENTMASK_BY_REPOSITORY = EVENTMASK_BY_CLASS | MDRChangeEvent.EVENTMASK_ON_REPOSITORY;
48
    /**
50
  
49
     * Maps: event =&gt; set of pre-change listeners.
51
  /* -------------------------------------------------------------------- */
50
     */
52
  /* -- Methods for debugging purposes (static) ------------------------- */
51
    private final HashMap preChangeListeners = new HashMap();
53
  /* -------------------------------------------------------------------- */
52
54
  
55
  /**
56
   * Pretty prints an event type.
57
   *
58
   * <p>[XXX]: Probably this method should be used to a test utility
59
   * class ?!</p>
60
   */
61
  public static String prettyPrintType(MDRChangeEvent e) {
62
    if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD)) return "EVENT_ATTRIBUTE_ADD";
63
    else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE)) return "EVENT_ATTRIBUTE_REMOVE";
64
    else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET)) return "EVENT_ATTRIBUTE_SET";
65
    else if (e.isOfType(AttributeEvent.EVENT_CLASSATTR_ADD)) return "EVENT_CLASSATTR_ADD";
66
    else if (e.isOfType(AttributeEvent.EVENT_CLASSATTR_REMOVE)) return "EVENT_CLASSATTR_REMOVE";
67
    else if (e.isOfType(AttributeEvent.EVENT_CLASSATTR_SET)) return "EVENT_CLASSATTR_SET";
68
    else if (e.isOfType(InstanceEvent.EVENT_INSTANCE_CREATE)) return "EVENT_INSTANCE_CREATE";
69
    else if (e.isOfType(InstanceEvent.EVENT_INSTANCE_DELETE)) return "EVENT_INSTANCE_DELETE";
70
    else if (e.isOfType(AssociationEvent.EVENT_ASSOCIATION_ADD)) return "EVENT_ASSOCIATION_ADD";
71
    else if (e.isOfType(AssociationEvent.EVENT_ASSOCIATION_REMOVE)) return "EVENT_ASSOCIATION_REMOVE";
72
    else if (e.isOfType(AssociationEvent.EVENT_ASSOCIATION_SET)) return "EVENT_ASSOCIATION_SET";
73
    else if (e.isOfType(ExtentEvent.EVENT_EXTENT_CREATE)) return "EVENT_EXTENT_CREATE";
74
    else if (e.isOfType(ExtentEvent.EVENT_EXTENT_DELETE)) return "EVENT_EXTENT_DELETE";
75
    else if (e.isOfType(TransactionEvent.EVENT_TRANSACTION_COMMIT)) return "EVENT_TRANSACTION_COMMIT";
76
    else if (e.isOfType(TransactionEvent.EVENT_TRANSACTION_ROLLBACK)) return "EVENT_TRANSACTION_ROLLBACK";
77
    else if (e.isOfType(TransactionEvent.EVENT_TRANSACTION_START)) return "EVENT_TRANSACTION_START";
78
    else return "<UNKNOWN>";
79
  }
80
  /**
81
   * Pretty prints a event type mask.
82
   *
83
   * <p>[XXX]: Probably this method should be used to a test utility
84
   * class ?!</p>
85
   */
86
  public static String prettyPrintMask(int mask) {
87
    StringBuffer buf = new StringBuffer();
88
    if ( (mask & AttributeEvent.EVENT_ATTRIBUTE_ADD) ==  AttributeEvent.EVENT_ATTRIBUTE_ADD ) buf.append("IAA ");
89
    if ( (mask & AttributeEvent.EVENT_ATTRIBUTE_REMOVE) == AttributeEvent.EVENT_ATTRIBUTE_REMOVE ) buf.append("IAR ");
90
    if ( (mask & AttributeEvent.EVENT_ATTRIBUTE_SET) == AttributeEvent.EVENT_ATTRIBUTE_SET ) buf.append("IAS ");
91
    if ( (mask & AttributeEvent.EVENT_CLASSATTR_ADD) == AttributeEvent.EVENT_CLASSATTR_ADD ) buf.append("CAA ");
92
    if ( (mask & AttributeEvent.EVENT_CLASSATTR_REMOVE) == AttributeEvent.EVENT_CLASSATTR_REMOVE ) buf.append("CAR ");
93
    if ( (mask & AttributeEvent.EVENT_CLASSATTR_SET) == AttributeEvent.EVENT_CLASSATTR_SET ) buf.append("CAS ");
94
    if ( (mask & InstanceEvent.EVENT_INSTANCE_CREATE) == InstanceEvent.EVENT_INSTANCE_CREATE ) buf.append("IC ");
95
    if ( (mask & InstanceEvent.EVENT_INSTANCE_DELETE) == InstanceEvent.EVENT_INSTANCE_DELETE ) buf.append("ID ");
96
    if ( (mask & AssociationEvent.EVENT_ASSOCIATION_ADD) == AssociationEvent.EVENT_ASSOCIATION_ADD ) buf.append("AA ");
97
    if ( (mask & AssociationEvent.EVENT_ASSOCIATION_REMOVE) == AssociationEvent.EVENT_ASSOCIATION_REMOVE ) buf.append("AR ");
98
    if ( (mask & AssociationEvent.EVENT_ASSOCIATION_SET) == AssociationEvent.EVENT_ASSOCIATION_SET ) buf.append("AS ");
99
    if ( (mask & ExtentEvent.EVENT_EXTENT_CREATE) == ExtentEvent.EVENT_EXTENT_CREATE ) buf.append("EC ");
100
    if ( (mask & ExtentEvent.EVENT_EXTENT_DELETE) == ExtentEvent.EVENT_EXTENT_DELETE ) buf.append("ED ");
101
    if ( (mask & TransactionEvent.EVENT_TRANSACTION_COMMIT) == TransactionEvent.EVENT_TRANSACTION_COMMIT ) buf.append("TC ");
102
    if ( (mask & TransactionEvent.EVENT_TRANSACTION_ROLLBACK) == TransactionEvent.EVENT_TRANSACTION_ROLLBACK ) buf.append("TR ");
103
    if ( (mask & TransactionEvent.EVENT_TRANSACTION_START) == TransactionEvent.EVENT_TRANSACTION_START ) buf.append("TS ");
104
    if ( buf.length() > 0 ) buf.deleteCharAt(buf.length()-1);
105
    return buf.toString();
106
  }
107
  
108
  /* -------------------------------------------------------------------- */
109
  /* -- Public attributes ----------------------------------------------- */
110
  /* -------------------------------------------------------------------- */
111
  
112
  public final Association ASSOCIATION = new Association();
113
  public final Clazz CLASS = new Clazz();
114
  public final Instance INSTANCE = new Instance();
115
  public final Package PACKAGE = new Package();
116
  public final Repository REPOSITORY = new Repository();
117
  
118
  /* -------------------------------------------------------------------- */
119
  /* -- Private attributes ---------------------------------------------- */
120
  /* -------------------------------------------------------------------- */
121
  
122
  /**
123
   * Thread for the dispatching of events after transaction success.
124
   */
125
  private final Thread dispatcher = new Thread(new EventsDelivery());
126
  
127
  /**
128
   * Maps: event =&gt; instance of <code>QueuedListenerSet</code>.
129
   */
130
  private final Hashtable queuedListenerMap = new Hashtable();
131
  
132
  /**
133
   * Queue for the events of the currently running write transaction.
134
   * The events are stored to inform their listeners either about
135
   * rollback or success.
136
   */
137
  private final LinkedList localQueue = new LinkedList();
138
  
139
  /**
140
   * Queue for the events of successfully finished transactions, the
141
   * listeners of which still have to be informed.
142
   */
143
  private final LinkedList globalQueue = new LinkedList();
144
  
145
  /* -------------------------------------------------------------------- */
146
  /* -- Constructor (public) -------------------------------------------- */
147
  /* -------------------------------------------------------------------- */
148
  
149
  /**
150
   * Starts the dispatcher thread as daemon.
151
   */
152
  public EventNotifier() {
153
    dispatcher.setDaemon(true);
154
    dispatcher.start();
155
  }
156
  
157
  /* -------------------------------------------------------------------- */
158
  /* -- Methods to fire events at transaction commit or rollback time --- */
159
  /* -------------------------------------------------------------------- */
160
  
161
  /**
162
   * Calls {@link MDRPreChangeListener.changeCancelled(MDRChangeEvent)} for
163
   * all pre-change listeners on <code>event</code> to inform them
164
   * about cancelling the event.
165
   */
166
  public void fireCancelled(MDRChangeEvent event) {
167
    localQueue.remove(event);
168
    QueuedListenerSet collected = (QueuedListenerSet) queuedListenerMap.remove(event);
169
    if (collected == null) {
170
      System.err.println("Change cancelled event not corresponding to any planned change event.");
171
      Thread.dumpStack();
172
      return;
173
    }
174
    // fire changeCancelled event
175
    for (QueuedListenerSet.PreListenerIterator it = collected.preListenerIterator(); it.hasNext();) {
176
      try {
177
        it.next().changeCancelled(event);
178
      } catch (RuntimeException e) {
179
        // log the exception
180
        e.printStackTrace();
181
      }
182
    }
183
  }
184
  
185
  /**
186
   * Calls {@link MDRPreChangeListener.changeCancelled(MDRChangeEvent)}
187
   * on all pre-change listeners of all events of the transaction to be
188
   * rolled back.
189
   */
190
  public void fireCancelled() {
191
    while (!localQueue.isEmpty()) {
192
      MDRChangeEvent event = (MDRChangeEvent) localQueue.getFirst();
193
      fireCancelled(event);
194
    }
195
  }
196
  
197
  /**
198
   * Enqueues all events of a transaction successfully finished to inform
199
   * the listeners in a separate thread.
200
   */
201
  public void fireChanged() {
202
    synchronized (globalQueue) {
203
      globalQueue.addAll(localQueue);
204
      globalQueue.notify();
205
    }
206
    localQueue.clear();
207
  }
208
  
209
  /* -------------------------------------------------------------------- */
210
  /* -- EventNotifier.EventDelivery (inner class, private) -------------- */
211
  /* -------------------------------------------------------------------- */
212
  
213
  /**
214
   * Runnable to be executed by the event dispatcher thread. Waits on the
215
   * global queue if it is empty. Informs the listeners on queued events.
216
   * Catches all exceptions and logs the stack trace.
217
   *
218
   * <p>Returns if a queued change event was not planned before (i.e. does
219
   *   not correspond to an entry in {@link #changeListeners}.
220
   */
221
  private class EventsDelivery implements Runnable {
53
    /**
222
    /**
54
     * Maps: event =&gt; set of change listeners.
223
     *
55
     */
224
     */
56
    private final Hashtable changeListeners = new Hashtable();
225
    public void run() {
226
      QueuedListenerSet collected;
227
      MDRChangeEvent event;
228
      
229
      while (true) {
230
        synchronized (globalQueue) {
231
          while (globalQueue.isEmpty()) {
232
            try {
233
              globalQueue.wait();
234
            } catch (InterruptedException e) {
235
              e.printStackTrace();
236
            }
237
          }
238
          collected = (QueuedListenerSet) queuedListenerMap.remove(event = (MDRChangeEvent) globalQueue.removeFirst());
239
        }
240
        if (collected == null) {
241
          System.err.println("Change event not corresponding to any planned change event.");
242
          Thread.dumpStack();
243
          return;
244
        }
245
        for (QueuedListenerSet.AllListenerIterator it = collected.allListenerIterator(); it.hasNext();) {
246
          try {
247
            it.next().change(event);
248
          } catch (RuntimeException e) {
249
            // log the exception
250
            e.printStackTrace();
251
          }
252
        }
253
      }
254
    }
255
  }
256
  
257
  /* -------------------------------------------------------------------- */
258
  /* -- EventNotifier.Abstract (inner class, public abstract) ----------- */
259
  /* -------------------------------------------------------------------- */
260
  
261
  /**
262
   * This class and its derived classes are used to enqueue all changes into
263
   * the local queue and to fire the pre-change events.
264
   */
265
  public abstract class Abstract {
266
    /**
267
     * Maps repository objects to instances of <code>RegisteredListenerSet</code>.
268
     */
269
    private final HashMap RegisteredListenerSets = new HashMap();
270
    
271
    /**
272
     * Adds <code>listener</code> to <code>source</code> for event types
273
     * matching <code>mask</code>.
274
     */
275
    public void addListener(MDRChangeListener listener, int mask, Object source) {
276
      //System.out.println("-- CALLED: addListener on " + source + " with " + prettyPrintMask(mask));
277
      if ( (listener == null) || (mask == 0) ) return;
278
      
279
      synchronized (RegisteredListenerSets) {
280
        RegisteredListenerSet value = (RegisteredListenerSet) RegisteredListenerSets.get(source);
281
        if ( value == null ) {
282
          value = new RegisteredListenerSet();
283
          RegisteredListenerSets.put(source, value);
284
        }
285
        value.addListener(listener, mask);
286
      }
287
    }
288
    
289
    /**
290
     * Removes <code>listener</code> from <code>source</code> for all event types.
291
     */
292
    public void removeListener(MDRChangeListener listener, Object source) {
293
      if ( listener == null ) return;
294
      
295
      synchronized (RegisteredListenerSets) {
296
        RegisteredListenerSet value = (RegisteredListenerSet) RegisteredListenerSets.get(source);
297
        if ( value != null ) {
298
          value.removeListener(listener);
299
          if ( value.isEmpty() ) {
300
            RegisteredListenerSets.remove(source);
301
          }
302
        }
303
      }
304
    }
305
    
306
    /**
307
     * Removes <code>listener</code> from <code>source</code> for event types
308
     * matching <code>mask</code>.
309
     */
310
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
311
      if ( (listener == null) || (mask == 0) ) return;
312
      
313
      synchronized (RegisteredListenerSets) {
314
        RegisteredListenerSet value = (RegisteredListenerSet) RegisteredListenerSets.get(source);
315
        if ( value != null ) {
316
          value.removeListener(listener, mask);
317
          if ( value.isEmpty() ) {
318
            RegisteredListenerSets.remove(source);
319
          }
320
        }
321
      }
322
    }
323
    
324
    /** Informs pre-change listeners about the given event. Internally the
325
     * event is stored together with its pre-change listeners and change
326
     * listeners to allow further event processing at transaction rollback
327
     * resp. commit time.
328
     *
329
     * @param current The source object of this event.
330
     * @param event Event object.
331
     * @exception DebugException if the event was already fired
332
     */
333
    public void firePlannedChange(Object current, MDRChangeEvent event) {
334
      //System.out.println("-- CALLED: firePlannedChange on " + current + " with type " + prettyPrintType(event));
335
      localQueue.addLast(event);
336
      // collect all listeners
337
      QueuedListenerSet queuedListeners = new QueuedListenerSet(event);
338
      collectListeners(current, event, queuedListeners);
339
      for (QueuedListenerSet.PreListenerIterator it = queuedListeners.preListenerIterator(); it.hasNext();) {
340
        try {
341
          it.next().plannedChange(event);
342
        } catch (RuntimeException e) {
343
          // log the exception
344
          e.printStackTrace();
345
        }
346
      }
347
      if (queuedListenerMap.put(event,queuedListeners) != null) {
348
        throw new DebugException("Same event fired twice.");
349
      }
350
    }
57
    
351
    
58
    /**
352
    /**
59
     * Queue for the events of the currently running write transaction.
353
     * Collects the listeners for the given <code>event</code> on object
60
     * The events are stored to inform their listeners either about
354
     * <code>current</code>. This method has to be overwritten by derived
61
     * rollback or success.
355
     * classes to inform listeners on objects to which the events are
62
     */
356
     * propagated. Overwriting methods shall call this method first and
63
    private final LinkedList localQueue = new LinkedList();
357
     * then add any further listeners.
358
     *
359
     * @param current the object on which the event was fired
360
     * @param event the event
361
     * @param post if <code>false</code>, listeners implementing
362
     *    {@link org.netbeans.api.mdr.events.MDRPreChangeListener} are
363
     *    collected, otherwise listeners implementing only
364
     *    {@link org.netbeans.api.mdr.events.MDRChangeListener}
365
     * @param preChange the set where the pre-change listeners are collected
366
     * @param postChange the set where the post-change only listeners are collected
367
     */
368
    protected void collectListeners(Object current, MDRChangeEvent event, QueuedListenerSet queuedListeners) {
369
      // fire event on all listeners registered on this object
370
      synchronized (RegisteredListenerSets) {
371
        RegisteredListenerSet value = (RegisteredListenerSet) RegisteredListenerSets.get(current);
372
        if (value != null) {
373
          value.collectListeners(queuedListeners);
374
        }
375
      }
376
    }
377
  }
378
  
379
  /* -------------------------------------------------------------------- */
380
  /* -- EventNotifier.Assocation (inner class, public) ------------------ */
381
  /* -------------------------------------------------------------------- */
382
  
383
  /**
384
   * Handles events for associations.
385
   */
386
  public final class Association extends Abstract {
387
    private Association() {
388
      super();
389
    }
390
    
391
    public void addListener(MDRChangeListener listener, int mask, Object source) {
392
      super.addListener(listener, mask & EventNotifier.EVENTMASK_BY_ASSOCIATION, source);
393
    }
394
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
395
      super.removeListener(listener, mask & EventNotifier.EVENTMASK_BY_ASSOCIATION, source);
396
    }
397
    
398
    /**
399
     * Adds listeners on the instances participating in the association link
400
     * added resp. removed and on the owning package.
401
     */
402
    protected void collectListeners(Object current, MDRChangeEvent event, QueuedListenerSet queuedListeners) {
403
      super.collectListeners(current, event, queuedListeners);
404
      
405
      // fire event on all listeners registered on instances that were affected
406
      if (event instanceof AssociationEvent) {
407
        AssociationEvent assocEvent = (AssociationEvent) event;
408
        if (assocEvent.getFixedElement() != null) INSTANCE.collectListeners(assocEvent.getFixedElement(), event, queuedListeners);
409
        if (assocEvent.getOldElement() != null) INSTANCE.collectListeners(assocEvent.getOldElement(), event, queuedListeners);
410
        if (assocEvent.getNewElement() != null) INSTANCE.collectListeners(assocEvent.getNewElement(), event, queuedListeners);
411
      }
412
      
413
      // fire event on the immediate package extent
414
      PACKAGE.collectListeners(((RefAssociation) current).refImmediatePackage(), event, queuedListeners);
415
    }
416
  }
417
  
418
  /* -------------------------------------------------------------------- */
419
  /* -- EventNotifier.Clazz (inner class, public) ----------------------- */
420
  /* -------------------------------------------------------------------- */
421
  
422
  /**
423
   * Handles events for class proxies.
424
   */
425
  public final class Clazz extends Abstract {
426
    private Clazz() {
427
      super();
428
    }
429
    
430
    public void addListener(MDRChangeListener listener, int mask, Object source) {
431
      super.addListener(listener, mask & EventNotifier.EVENTMASK_BY_CLASS, source);
432
    }
433
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
434
      super.removeListener(listener, mask & EventNotifier.EVENTMASK_BY_CLASS, source);
435
    }
436
    
437
    /**
438
     * Adds listeners on the owning package.
439
     */
440
    protected void collectListeners(Object current, MDRChangeEvent event, QueuedListenerSet queuedListeners) {
441
      super.collectListeners(current, event, queuedListeners);
442
      PACKAGE.collectListeners(((RefClass) current).refImmediatePackage(), event, queuedListeners);
443
    }
444
  }
445
  
446
  /* -------------------------------------------------------------------- */
447
  /* -- EventNotifier.Instance (inner class, public) -------------------- */
448
  /* -------------------------------------------------------------------- */
449
  
450
  /**
451
   * Handles events for instances.
452
   */
453
  public final class Instance extends Abstract {
454
    private Instance() {
455
      super();
456
    }
457
    
458
    public void addListener(MDRChangeListener listener, int mask, Object source) {
459
      super.addListener(listener, mask & EventNotifier.EVENTMASK_BY_INSTANCE, source);
460
    }
461
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
462
      super.removeListener(listener, mask & EventNotifier.EVENTMASK_BY_INSTANCE, source);
463
    }
464
    
465
    /**
466
     * Adds listeners on the owning class proxy.
467
     */
468
    protected void collectListeners(Object current, MDRChangeEvent event, QueuedListenerSet queuedListeners) {
469
      super.collectListeners(current, event, queuedListeners);
470
      CLASS.collectListeners(((RefObject) current).refClass(), event, queuedListeners);
471
    }
472
  }
473
  
474
  /* -------------------------------------------------------------------- */
475
  /* -- EventNotifier.Package (inner class, public) --------------------- */
476
  /* -------------------------------------------------------------------- */
477
  
478
  /**
479
   * Handles events for packages.
480
   */
481
  public final class Package extends Abstract {
482
    private Package() {
483
      super();
484
    }
485
    
486
    public void addListener(MDRChangeListener listener, int mask, Object source) {
487
      super.addListener(listener, mask & EventNotifier.EVENTMASK_BY_PACKAGE, source);
488
    }
489
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
490
      super.removeListener(listener, mask & EventNotifier.EVENTMASK_BY_PACKAGE, source);
491
    }
492
    
493
    /**
494
     * Adds listeners on the owning package resp., if this package is
495
     * outermost, on the repository.
496
     */
497
    protected void collectListeners(Object current, MDRChangeEvent event, QueuedListenerSet queuedListeners) {
498
      super.collectListeners(current, event, queuedListeners);
499
      RefPackage immediate = ((RefPackage) current).refImmediatePackage();
500
      if (immediate != null) {
501
        collectListeners(immediate, event, queuedListeners);
502
      } else {
503
        REPOSITORY.collectListeners(((BaseObjectHandler) current)._getDelegate().getMdrStorage(), event, queuedListeners);
504
      }
505
    }
506
  }
507
  
508
  /* -------------------------------------------------------------------- */
509
  /* -- EventNotifier.Repository (inner class, public) ------------------ */
510
  /* -------------------------------------------------------------------- */
511
  
512
  /**
513
   * Handles events for repositories.
514
   */
515
  public final class Repository extends Abstract {
516
    private Repository() {
517
      super();
518
    }
519
    
520
    public void addListener(MDRChangeListener listener, int mask, Object source) {
521
      super.addListener(listener, mask & EventNotifier.EVENTMASK_BY_REPOSITORY, source);
522
    }
523
    public void removeListener(MDRChangeListener listener, int mask, Object source) {
524
      super.removeListener(listener, mask & EventNotifier.EVENTMASK_BY_REPOSITORY, source);
525
    }
526
  }
527
  
528
  /* ===================================================================== */
529
  /* == INNER CLASS CONTAINING OPTIMIZED/OPTIMIZABLE DATASTRUCTURES ====== */
530
  /* == FOR LISTENER MANAGEMENT ========================================== */
531
  /* ===================================================================== */
532
  Index: src/org/netbeans/mdr/util/ImplClass.java
Lines 24-29 Link Here
24
 * @version 
24
 * @version 
25
 */
25
 */
26
public abstract class ImplClass {
26
public abstract class ImplClass {
27
    
28
    /* Suffix for the names of implementation classes. */
27
    protected static final String classNameSuffix = "$Impl";
29
    protected static final String classNameSuffix = "$Impl";
28
    private static final ProtectionDomain pd;
30
    private static final ProtectionDomain pd;
29
31
(-)src/org/netbeans/mdr/util/TransactionMutex.java (-4 / +27 lines)
Lines 13-18 Link Here
13
package org.netbeans.mdr.util;
13
package org.netbeans.mdr.util;
14
14
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import org.netbeans.api.mdr.events.TransactionEvent;
17
import org.netbeans.mdr.NBMDRepositoryImpl;
16
import org.netbeans.mdr.storagemodel.MdrStorage;
18
import org.netbeans.mdr.storagemodel.MdrStorage;
17
import org.netbeans.mdr.persistence.StorageException;
19
import org.netbeans.mdr.persistence.StorageException;
18
20
Lines 52-65 Link Here
52
    // events notifier
54
    // events notifier
53
    private final EventNotifier notifier;
55
    private final EventNotifier notifier;
54
56
57
    // the repository (used as event source for transaction events)
58
    private final NBMDRepositoryImpl repository;
59
    
55
    /* -------------------------------------------------------------------- */
60
    /* -------------------------------------------------------------------- */
56
    /* -- Constructor (public) -------------------------------------------- */
61
    /* -- Constructor (public) -------------------------------------------- */
57
    /* -------------------------------------------------------------------- */
62
    /* -------------------------------------------------------------------- */
58
63
59
    /** Creates new TransactionMutex */
64
    /** Creates new TransactionMutex */
60
    public TransactionMutex(MdrStorage storage, EventNotifier notifier) {
65
    public TransactionMutex(MdrStorage storage, EventNotifier notifier, NBMDRepositoryImpl repository) {
61
        this.storage = storage;
66
        this.storage = storage;
62
        this.notifier = notifier;
67
        this.notifier = notifier;
68
        this.repository = repository;
63
    }
69
    }
64
70
65
    /* -------------------------------------------------------------------- */
71
    /* -------------------------------------------------------------------- */
Lines 107-114 Link Here
107
        }
113
        }
108
        
114
        
109
        if (writeAccess || counter > 0) {
115
        if (writeAccess || counter > 0) {
116
            if ( counter == 0 ) {
117
                writer = thread;
118
                TransactionEvent event = new TransactionEvent(
119
                    repository,
120
                    TransactionEvent.EVENT_TRANSACTION_START
121
                );
122
                notifier.REPOSITORY.firePlannedChange(storage, event);
123
            }
110
            counter++;
124
            counter++;
111
            writer = thread;
112
        } else {
125
        } else {
113
            Counter rCount = (Counter) readers.get(thread);
126
            Counter rCount = (Counter) readers.get(thread);
114
            if (rCount == null) {
127
            if (rCount == null) {
Lines 129-135 Link Here
129
    /**
142
    /**
130
     * Leave a transaction. If an outermost (i.e. not nested) write 
143
     * Leave a transaction. If an outermost (i.e. not nested) write 
131
     * transaction is left, the listeners are informed and the transaction
144
     * transaction is left, the listeners are informed and the transaction
132
     * is committed resp. rolled back. Finally all waiting thread are
145
     * is committed resp. rolled back. Finally all waiting threads are
133
     * notified.
146
     * notified.
134
     *
147
     *
135
     * @param fail  <code>false</code> indicates transaction
148
     * @param fail  <code>false</code> indicates transaction
Lines 146-156 Link Here
146
                    // left the last write lock -> commit/rollback and send events
159
                    // left the last write lock -> commit/rollback and send events
147
                    try {
160
                    try {
148
                        if (this.fail) {
161
                        if (this.fail) {
162
                            TransactionEvent event = new TransactionEvent(
163
                                repository,
164
                                TransactionEvent.EVENT_TRANSACTION_ROLLBACK
165
                            );
166
                            notifier.REPOSITORY.firePlannedChange(storage, event);
149
                            notifier.fireCancelled();
167
                            notifier.fireCancelled();
150
                            storage.rollback();
168
                            storage.rollback();
151
                            Thread.dumpStack();
169
                            Thread.dumpStack();
152
                            System.out.println("rolled back!");
170
                            System.out.println("rolled back!");
153
                        } else {
171
                        } else {
172
                            TransactionEvent event = new TransactionEvent(
173
                                repository,
174
                                TransactionEvent.EVENT_TRANSACTION_COMMIT
175
                            );
176
                            notifier.REPOSITORY.firePlannedChange(storage, event);
154
                            notifier.fireChanged();
177
                            notifier.fireChanged();
155
                            storage.commit();
178
                            storage.commit();
156
                            //System.out.println("commited");
179
                            //System.out.println("commited");
Lines 189-195 Link Here
189
    /* -------------------------------------------------------------------- */
212
    /* -------------------------------------------------------------------- */
190
    
213
    
191
    /**
214
    /**
192
     * Instances <code>Counter</code> are integer with {@link #dec() decrement}
215
     * Instances <code>Counter</code> are integers with {@link #dec() decrement}
193
     * and {@link #inc() increment} methods.
216
     * and {@link #inc() increment} methods.
194
     */
217
     */
195
    private static class Counter {
218
    private static class Counter {
(-)src/org/netbeans/modules/mdrexplorer/looks/MDREventHandler.java (-45 / +68 lines)
Lines 26-49 Link Here
26
import org.netbeans.api.looks.Look;
26
import org.netbeans.api.looks.Look;
27
27
28
/**
28
/**
29
 * Instances of <code>MDREventHandler</code> are event handlers which listen
30
 * on repository changes on behalf of {@link org.netbeans.api.looks.LookNodeSubstitutes
31
 * node substitutes}. They manage a map from repository objects to node substitutes
32
 * to be able to access the node substitute for a given repository object. Looks
33
 * have to register their node subsitutes by calling {@link #addNodeSubstitute(Look.NodeSubstitute)}
34
 * or {@link #addNodeSubstitute(Object, Look.NodeSubstitute)} from within
35
 * {@link org.netbeans.api.looks.Look#attachTo(ook.NodeSubstitute)}.
29
 *
36
 *
37
 * @deprecated register NodeSubstitutes directly on repository objects instead, see
38
 *     <a href="http://mdr.netbeans.org/issues/show_bug.cgi?id=25186">issue 25186</a>
30
 * @author  Tomas Zezula
39
 * @author  Tomas Zezula
31
 */
40
 */
32
public class MDREventHandler implements MDRPreChangeListener {
41
public class MDREventHandler implements MDRPreChangeListener {
33
    
42
    
43
    /* --------------------------------------------------------------------- */
44
    /* -- Attributes ------------------------------------------------------- */
45
    /* --------------------------------------------------------------------- */
46
47
    /**
48
     * Maps repository content to node substitutes.
49
     */
34
    private HashMap registeredNodeSubstitutes;
50
    private HashMap registeredNodeSubstitutes;
51
    
52
    /**
53
     * Map storing the parents of objects to be deleted. After an object has
54
     * been deleted, its parent node is not accessible any more. Nevertheless it
55
     * must be refreshed to reflect the deletion of the node representing the object.
56
     * Hence the parents of the objects to be deleted are stored in the map.
57
     */
35
    private HashMap pendingEvents;
58
    private HashMap pendingEvents;
36
    private ReferenceQueue queue;
59
    private ReferenceQueue queue;
37
    private MDRepository repository;
60
    private MDRepository repository;
38
    
61
    
62
    /* --------------------------------------------------------------------- */
63
    /* -- Constructor ------------------------------------------------------ */
64
    /* --------------------------------------------------------------------- */
65
    
39
    public MDREventHandler  (MDRepository repository) {
66
    public MDREventHandler  (MDRepository repository) {
40
        this.queue = new ReferenceQueue();
67
        this.queue = new ReferenceQueue();
41
        this.registeredNodeSubstitutes = new HashMap();
68
        this.registeredNodeSubstitutes = new HashMap();
42
        this.pendingEvents = new HashMap();
69
        this.pendingEvents = new HashMap();
43
        this.repository = repository;
70
        this.repository = repository;
44
        this.repository.addListener(this);
71
        this.repository.addListener(this, MDRChangeEvent.EVENTMASK_ALL);
45
    }
72
    }
46
    
73
    
74
    /* --------------------------------------------------------------------- */
75
    /* -- Management of NodeSubstitutes ------------------------------------ */
76
    /* --------------------------------------------------------------------- */
77
    
47
    public synchronized void addNodeSubstitute(Look.NodeSubstitute substitute) {
78
    public synchronized void addNodeSubstitute(Look.NodeSubstitute substitute) {
48
        if (substitute == null)
79
        if (substitute == null)
49
            return;
80
            return;
Lines 56-87 Link Here
56
        this.registeredNodeSubstitutes.put(key, new WeakReference(substitute,this.queue));
87
        this.registeredNodeSubstitutes.put(key, new WeakReference(substitute,this.queue));
57
    }
88
    }
58
    
89
    
59
    /** This method is called when the node was garbage collected. You shoud
90
    private synchronized Look.NodeSubstitute getNodeSubstituteForObject(Object object) {
60
     * unregister from all objects where this object was registered as a
91
        if (object ==null)
61
     * listener.
92
            return null;
62
     */
93
        Reference ref = (Reference) this.registeredNodeSubstitutes.get(object);
63
    
94
        if (ref == null) {
64
    /** This method gets called if a planned change (which was already announced
95
            return null; // Not registered object
65
     * by calling {@link #plannedChange} was cancelled (e.g. the operation that was
66
     * going to perform the change failed). This method is called synchronously by
67
     * the operation that tried to perform the change.<p>
68
     * Any run-time exception thrown by the implementation of this method should
69
     * not affect the events dispatching (i.e. it should be ignored by the event source).
70
     * @param e Object describing the cancelled change (has to be the same instance
71
     * as passed to the {@link #plannedChange} method).
72
     */
73
    public void changeCancelled(MDRChangeEvent e) {
74
        if ((e.getType() & 2) == 2) {
75
            this.pendingEvents.remove(e.getSource());
76
        }
96
        }
97
        Look.NodeSubstitute substitute = (Look.NodeSubstitute) ref.get();
98
        return substitute;
77
    }
99
    }
78
    
100
    
79
    /** This method gets called when a repository change is planned to occur.
101
    /* --------------------------------------------------------------------- */
80
     * Any operation that performs a change in MDR has to fire this notification
102
    /* -- Implements org.netbeans.api.mdr.MDRPreChangeListener ------------- */
81
     * synchronously on each registered pre-change listener before the change is performed.<p>
103
    /* --------------------------------------------------------------------- */
82
     * Any run-time exception thrown by the implementation of this method should
104
    
83
     * not affect the events dispatching (i.e. it should be ignored by the event source).
105
    /**
84
     * @param e Object describing the planned change.
106
     * Handles deletion events only. Stores the parents of objects to be deleted.
107
     * This is necessary to refresh parent nodes when the object to be deleted
108
     * has been deleted.
85
     */
109
     */
86
    public void plannedChange(MDRChangeEvent e) {
110
    public void plannedChange(MDRChangeEvent e) {
87
        if ((e.getType() & ExtentEvent.EVENT_EXTENT_DELETE) == ExtentEvent.EVENT_EXTENT_DELETE) {
111
        if ((e.getType() & ExtentEvent.EVENT_EXTENT_DELETE) == ExtentEvent.EVENT_EXTENT_DELETE) {
Lines 107-122 Link Here
107
        }
131
        }
108
    }
132
    }
109
    
133
    
110
    /** This method gets called after a repository change is performed. This method
134
    /**
111
     * is called asynchronously.
135
     * Removes the information stored for the pending event <code>e</code>.
112
     * If a listener implements {@link MDRPreChangeListener} which is a descedant
136
     * @see #plannedChange(MDRChangeEvent)
113
     * of this interface, the event object passed to this method must be the same
137
     */
114
     * instance as the event object previously passed to the corresponding
138
    public void changeCancelled(MDRChangeEvent e) {
115
     * {@link MDRPreChangeListener#plannedChange} method call of the listener.<p>
139
        if ((e.getType() & 2) == 2) {
116
     * Any run-time exception thrown by the implementation of this method should
140
            this.pendingEvents.remove(e.getSource());
117
     * not affect the events dispatching (i.e. it should be ignored by the event source).
141
        }
118
     *
142
    }
119
     * @param e Object describing the performed change.
143
144
    /**
145
     * Refreshes the nodes affected by <code>e</code>.
120
     */
146
     */
121
    public void change(MDRChangeEvent e) {
147
    public void change(MDRChangeEvent e) {
122
        if ((e.getType() & ExtentEvent.EVENT_EXTENT_CREATE) == ExtentEvent.EVENT_EXTENT_CREATE) {
148
        if ((e.getType() & ExtentEvent.EVENT_EXTENT_CREATE) == ExtentEvent.EVENT_EXTENT_CREATE) {
Lines 171-176 Link Here
171
        }
197
        }
172
    }
198
    }
173
    
199
    
200
    /* --------------------------------------------------------------------- */
201
    /* -- Clean-up dangling map entries ------------------------------------ */
202
    /* --------------------------------------------------------------------- */
203
    
204
    /**
205
     * Removes entries with garbage collected values from the map associating
206
     * repository objects with node substitutes.
207
     */
174
    synchronized void flushReferenceQueue() {
208
    synchronized void flushReferenceQueue() {
175
        if (this.queue.poll()!=null) {
209
        if (this.queue.poll()!=null) {
176
            Iterator values = this.registeredNodeSubstitutes.values().iterator();
210
            Iterator values = this.registeredNodeSubstitutes.values().iterator();
Lines 184-200 Link Here
184
        }
218
        }
185
    }
219
    }
186
    
220
    
187
    
188
    private synchronized Look.NodeSubstitute getNodeSubstituteForObject(Object object) {
189
        if (object ==null)
190
            return null;
191
        Reference ref = (Reference) this.registeredNodeSubstitutes.get(object);
192
        if (ref == null) {
193
            return null; // Not registered object
194
        }
195
        Look.NodeSubstitute substitute = (Look.NodeSubstitute) ref.get();
196
        return substitute;
197
    }
198
    
221
    
199
    
222
    
200
}
223
}
(-)test/build-qa-functional.xml (-2 / +2 lines)
Lines 158-164 Link Here
158
        <echo message="Using jars classpath for compilation."/>
158
        <echo message="Using jars classpath for compilation."/>
159
    	<!-- this classpath will be used for compiling tests against jars -->
159
    	<!-- this classpath will be used for compiling tests against jars -->
160
	<path id="compiletest.classpath">        	    
160
	<path id="compiletest.classpath">        	    
161
            <pathelement location="../../openide/netbeans/lib/openide.jar"/>
161
            <pathelement location="${openide.jar}"/>
162
	    <pathelement location="../netbeans/modules/mdr.jar"/>
162
	    <pathelement location="../netbeans/modules/mdr.jar"/>
163
	    <pathelement location="../netbeans/modules/mdrtoolkit.jar"/>
163
	    <pathelement location="../netbeans/modules/mdrtoolkit.jar"/>
164
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
164
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
Lines 204-210 Link Here
204
        <echo message="Using jars classpath."/>
204
        <echo message="Using jars classpath."/>
205
        <!-- this classpath will be used for executing tests against jars -->
205
        <!-- this classpath will be used for executing tests against jars -->
206
	<path id="codetest.classpath">
206
	<path id="codetest.classpath">
207
       	    <pathelement location="../../openide/netbeans/lib/openide.jar"/>
207
       	    <pathelement location="${openide.jar}"/>
208
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
208
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
209
	    <pathelement location="../netbeans/modules/ext/nbmdr.jar"/>
209
	    <pathelement location="../netbeans/modules/ext/nbmdr.jar"/>
210
            <pathelement location="../netbeans/modules/mdr.jar"/>
210
            <pathelement location="../netbeans/modules/mdr.jar"/>
(-)test/build-unit.xml (-2 / +2 lines)
Lines 158-164 Link Here
158
        <echo message="Using jars classpath for compilation."/>
158
        <echo message="Using jars classpath for compilation."/>
159
    	<!-- this classpath will be used for compiling tests against jars -->
159
    	<!-- this classpath will be used for compiling tests against jars -->
160
	<path id="compiletest.classpath">
160
	<path id="compiletest.classpath">
161
            <pathelement location="../../openide/netbeans/lib/openide.jar"/>
161
            <pathelement location="${openide.jar}"/>
162
	    <pathelement location="../netbeans/modules/mdr.jar"/>
162
	    <pathelement location="../netbeans/modules/mdr.jar"/>
163
	    <pathelement location="../netbeans/modules/mdrtoolkit.jar"/>
163
	    <pathelement location="../netbeans/modules/mdrtoolkit.jar"/>
164
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
164
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
Lines 207-213 Link Here
207
        <echo message="Using jars classpath."/>
207
        <echo message="Using jars classpath."/>
208
        <!-- this classpath will be used for executing tests against jars -->
208
        <!-- this classpath will be used for executing tests against jars -->
209
	<path id="codetest.classpath">
209
	<path id="codetest.classpath">
210
            <pathelement location="../../openide/netbeans/lib/openide.jar"/>
210
            <pathelement location="${openide.jar}"/>
211
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
211
	    <pathelement location="../netbeans/modules/ext/jmiutils.jar"/>
212
	    <pathelement location="../netbeans/modules/ext/nbmdr.jar"/>
212
	    <pathelement location="../netbeans/modules/ext/nbmdr.jar"/>
213
            <pathelement location="../netbeans/modules/mdr.jar"/>
213
            <pathelement location="../netbeans/modules/mdr.jar"/>
(-)test/build.xml (+3 lines)
Lines 14-19 Link Here
14
14
15
<project name="MDR test build script" basedir="." default="all">
15
<project name="MDR test build script" basedir="." default="all">
16
16
17
    <!-- Properties: external files -->
18
    <property name="openide.jar" location="../../openide/netbeans/lib/openide.jar"/>
19
17
    <!-- Points to directory with IDE to test-->
20
    <!-- Points to directory with IDE to test-->
18
    <property name="netbeans.home" location="../../nbbuild/netbeans"/>
21
    <property name="netbeans.home" location="../../nbbuild/netbeans"/>
19
    
22
    
(-)test/unit/src/org/netbeans/mdr/test/MDRTestAssociationEvents.java (-2 / +2 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
        
72
        
73
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
73
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
74
        Iterator iterAssoc = allMOFAssociations.iterator();
74
        Iterator iterAssoc = allMOFAssociations.iterator();
Lines 106-112 Link Here
106
        
106
        
107
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
107
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
108
        
108
        
109
        ((MDRChangeSource) repository).addListener(this);
109
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
110
        
110
        
111
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
111
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
112
        Iterator iterAssoc = allMOFAssociations.iterator();
112
        Iterator iterAssoc = allMOFAssociations.iterator();
(-)test/unit/src/org/netbeans/mdr/test/MDRTestAssociationPreEvents.java (-2 / +2 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
        
72
        
73
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
73
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
74
        Iterator iterAssoc = allMOFAssociations.iterator();
74
        Iterator iterAssoc = allMOFAssociations.iterator();
Lines 106-112 Link Here
106
        
106
        
107
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
107
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
108
        
108
        
109
        ((MDRChangeSource) repository).addListener(this);
109
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
110
        
110
        
111
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
111
        Collection allMOFAssociations = testMOFPackage.refAllAssociations();
112
        Iterator iterAssoc = allMOFAssociations.iterator();
112
        Iterator iterAssoc = allMOFAssociations.iterator();
(-)test/unit/src/org/netbeans/mdr/test/MDRTestAttributeEvents.java (-4 / +4 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
        
72
        
73
        RefObject newRefObj = null;
73
        RefObject newRefObj = null;
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 125-131 Link Here
125
            if (!metaClass.isAbstract()) {
125
            if (!metaClass.isAbstract()) {
126
                log("Creating instance for class: " + metaClass.getName());
126
                log("Creating instance for class: " + metaClass.getName());
127
                newRefObj = generator.generateInstance(metaClass);
127
                newRefObj = generator.generateInstance(metaClass);
128
                ((MDRChangeSource) newRefObj).addListener(listener);
128
                ((MDRChangeSource) newRefObj).addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
129
                generator.addAttribute(newRefObj, true, goldenPass, false);
129
                generator.addAttribute(newRefObj, true, goldenPass, false);
130
            } else {
130
            } else {
131
                log("Abstract class: " + metaClass.getName());
131
                log("Abstract class: " + metaClass.getName());
Lines 160-166 Link Here
160
        
160
        
161
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
161
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
162
        
162
        
163
        ((MDRChangeSource) repository).addListener(this);
163
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
164
        
164
        
165
        RefObject newRefObj = null;
165
        RefObject newRefObj = null;
166
        Collection allMOFClasses = testMOFPackage.refAllClasses();
166
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 218-224 Link Here
218
                log("Creating instance for class: " + metaClass.getName());
218
                log("Creating instance for class: " + metaClass.getName());
219
                newRefObj = generator.generateInstance(metaClass);
219
                newRefObj = generator.generateInstance(metaClass);
220
                // listening on class instance and repository too
220
                // listening on class instance and repository too
221
                ((MDRChangeSource) newRefObj).addListener(listener);                
221
                ((MDRChangeSource) newRefObj).addListener(listener, MDRChangeEvent.EVENTMASK_ALL);                
222
                generator.setAttribute(newRefObj, goldenPass, false);
222
                generator.setAttribute(newRefObj, goldenPass, false);
223
            } else {
223
            } else {
224
                log("Abstract class: " + metaClass.getName());
224
                log("Abstract class: " + metaClass.getName());
(-)test/unit/src/org/netbeans/mdr/test/MDRTestAttributePreEvents.java (-4 / +4 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
        
72
        
73
        RefObject newRefObj = null;
73
        RefObject newRefObj = null;
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 126-132 Link Here
126
                log("Creating instance for class: " + metaClass.getName());
126
                log("Creating instance for class: " + metaClass.getName());
127
                newRefObj = generator.generateInstance(metaClass);
127
                newRefObj = generator.generateInstance(metaClass);
128
                // listening on class instance and repository too
128
                // listening on class instance and repository too
129
                ((MDRChangeSource) newRefObj).addListener(listener);                
129
                ((MDRChangeSource) newRefObj).addListener(listener, MDRChangeEvent.EVENTMASK_ALL);                
130
                generator.setAttribute(newRefObj, goldenPass, true);
130
                generator.setAttribute(newRefObj, goldenPass, true);
131
            } else {
131
            } else {
132
                log("Abstract class: " + metaClass.getName());
132
                log("Abstract class: " + metaClass.getName());
Lines 161-167 Link Here
161
        
161
        
162
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
162
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
163
        
163
        
164
        ((MDRChangeSource) repository).addListener(this);
164
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
165
        
165
        
166
        RefObject newRefObj = null;
166
        RefObject newRefObj = null;
167
        Collection allMOFClasses = testMOFPackage.refAllClasses();
167
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 218-224 Link Here
218
            if (!metaClass.isAbstract()) {
218
            if (!metaClass.isAbstract()) {
219
                log("Creating instance for class: " + metaClass.getName());
219
                log("Creating instance for class: " + metaClass.getName());
220
                newRefObj = generator.generateInstance(metaClass);
220
                newRefObj = generator.generateInstance(metaClass);
221
                ((MDRChangeSource) newRefObj).addListener(listener);
221
                ((MDRChangeSource) newRefObj).addListener(listener, MDRChangeEvent.EVENTMASK_ALL);
222
                generator.addAttribute(newRefObj, true, goldenPass, true);
222
                generator.addAttribute(newRefObj, true, goldenPass, true);
223
            } else {
223
            } else {
224
                log("Abstract class: " + metaClass.getName());
224
                log("Abstract class: " + metaClass.getName());
(-)test/unit/src/org/netbeans/mdr/test/MDRTestExtentEvents.java (-1 / +1 lines)
Lines 42-48 Link Here
42
    
42
    
43
    protected void setUp() {
43
    protected void setUp() {
44
        super.setUp();
44
        super.setUp();
45
        ((MDRChangeSource) repository).addListener(this);
45
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
46
    }
46
    }
47
    
47
    
48
    protected void tearDown() {
48
    protected void tearDown() {
(-)test/unit/src/org/netbeans/mdr/test/MDRTestExtentPreEvents.java (-1 / +1 lines)
Lines 42-48 Link Here
42
    
42
    
43
    protected void setUp() {
43
    protected void setUp() {
44
        super.setUp();
44
        super.setUp();
45
        ((MDRChangeSource) repository).addListener(this);
45
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
46
    }
46
    }
47
    
47
    
48
    protected void tearDown() {
48
    protected void tearDown() {
(-)test/unit/src/org/netbeans/mdr/test/MDRTestInstanceEvents.java (-2 / +2 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
        
72
        
73
        RefObject newRefObj = null;
73
        RefObject newRefObj = null;
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 118-124 Link Here
118
        
118
        
119
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
119
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
120
        
120
        
121
        ((MDRChangeSource) repository).addListener(this);
121
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
122
        
122
        
123
        RefObject newRefObj = null;
123
        RefObject newRefObj = null;
124
        Collection allMOFClasses = testMOFPackage.refAllClasses();
124
        Collection allMOFClasses = testMOFPackage.refAllClasses();
(-)test/unit/src/org/netbeans/mdr/test/MDRTestInstancePreEvents.java (-3 / +3 lines)
Lines 68-74 Link Here
68
        
68
        
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
69
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
70
        
70
        
71
        ((MDRChangeSource) repository).addListener(this);
71
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
72
                
72
                
73
        RefObject newRefObj = null;
73
        RefObject newRefObj = null;
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
74
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 119-125 Link Here
119
        
119
        
120
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
120
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
121
        
121
        
122
        ((MDRChangeSource) repository).addListener(this);
122
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
123
        
123
        
124
        RefObject newRefObj = null;
124
        RefObject newRefObj = null;
125
        Collection allMOFClasses = testMOFPackage.refAllClasses();
125
        Collection allMOFClasses = testMOFPackage.refAllClasses();
Lines 174-180 Link Here
174
        
174
        
175
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
175
        EventsDataGenerator generator = new EventsDataGenerator(repository.getExtent(PKG_NAME));
176
        
176
        
177
        ((MDRChangeSource) repository).addListener(this);
177
        ((MDRChangeSource) repository).addListener(this, MDRChangeEvent.EVENTMASK_ALL);
178
        
178
        
179
        RefObject newRefObj = null;
179
        RefObject newRefObj = null;
180
        Collection allMOFClasses = testMOFPackage.refAllClasses();
180
        Collection allMOFClasses = testMOFPackage.refAllClasses();
(-)test/unit/src/org/netbeans/mdr/test/StaticFeaturesTest.java (-3 / +43 lines)
Lines 61-67 Link Here
61
    
61
    
62
    // classifier-level attribute test
62
    // classifier-level attribute test
63
    public void test_1 () {
63
    public void test_1 () {
64
        ModelPackage modelPackage = loadMOFModel ("StaticFeatures.xml", "model");
64
        ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model");
65
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
65
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
66
        
66
        
67
        int x, y;
67
        int x, y;
Lines 102-108 Link Here
102
102
103
    // static operator test
103
    // static operator test
104
    public void test_2 () {
104
    public void test_2 () {
105
        ModelPackage modelPackage = loadMOFModel ("StaticFeatures.xml", "model");
105
        ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model");
106
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
106
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
107
                
107
                
108
        ClassAClass proxyA = pkg.getClassA (); // staticFieldA (String), staticFieldB (int)
108
        ClassAClass proxyA = pkg.getClassA (); // staticFieldA (String), staticFieldB (int)
Lines 142-148 Link Here
142
    
142
    
143
    // derived classifier-level attribute test
143
    // derived classifier-level attribute test
144
    public void test_3 () {
144
    public void test_3 () {
145
        ModelPackage modelPackage = loadMOFModel ("StaticFeatures.xml", "model");
145
        ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model");
146
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
146
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
147
                        
147
                        
148
        ClassDClass proxyD = pkg.getClassD (); // staticFieldD (String), staticDerivedField (int), op. compute
148
        ClassDClass proxyD = pkg.getClassD (); // staticFieldD (String), staticDerivedField (int), op. compute
Lines 151-154 Link Here
151
            fail();
151
            fail();
152
    }
152
    }
153
    
153
    
154
    // classifier-level attribute test using reflective methods
155
    public void test_reflective () {
156
        ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model");
157
        StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures");
158
        
159
        int x, y;
160
        final int MAX = 100;
161
        final int INT_VALUE = 678;
162
        Random random = new Random (0);
163
        
164
        RefClass proxyA = pkg.getClassA (); // staticFieldA (String), staticFieldB (int)
165
        RefClass proxyB = pkg.getClassB ();
166
        RefClass proxyC = pkg.getClassC (); // staticFieldC (int), op. returnParam 
167
        RefClass proxyD = pkg.getClassD (); // staticFieldD (String), staticDerivedField (int), op. compute
168
        
169
        if (proxyD.refGetValue("staticFieldD") != null)
170
            fail ();
171
        proxyD.refSetValue("staticFieldD",  "123");
172
        proxyB.refSetValue("staticFieldA", "abcdef");
173
        
174
        for (x = 0; x < MAX; x++) {
175
            int value = random.nextInt ();
176
            proxyD.refSetValue("staticFieldB", new Integer(value));
177
            if ( (((Integer)proxyA.refGetValue("staticFieldB")).intValue() != value) || (((Integer)proxyD.refGetValue("staticFieldB")).intValue() != value))
178
                fail ();            
179
        }
180
                
181
        proxyD.refSetValue("staticFieldC", new Integer(INT_VALUE));
182
        
183
        if (!proxyD.refGetValue("staticFieldD").equals("123"))
184
            fail();
185
        if (!proxyB.refGetValue("staticFieldA").equals("abcdef"))
186
            fail();
187
        if (((Integer)proxyD.refGetValue("staticFieldC")).intValue() != INT_VALUE)
188
            fail();
189
                
190
        proxyD.refSetValue("staticFieldC", new Integer(22));        
191
        if (!proxyB.refGetValue("staticFieldA").equals("abcdef"))
192
            fail();        
193
    }
154
}
194
}

Return to bug 25186