KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > mdr > events > InstanceEvent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.mdr.events;
20
21 import java.util.List JavaDoc;
22 import javax.jmi.reflect.RefObject;
23 import javax.jmi.reflect.RefFeatured;
24
25 /** MDR Event used for representing events related to lifecycle of class instances
26  * (creation and deletion of instances). As this event contains attribute pointing
27  * to the affected (created/deleted) instance, it will need to be subclassed
28  * in repository implementation. This is because each implementation has to send
29  * the same event object to both pre-change and change events. In case of the
30  * instance create event, the actual instance is not known by the time the pre-change
31  * event is fired (so the event object is created providing null for this attribute),
32  * however the created instance has to be referenced from the event object passed to the
33  * change event. As the implementation is not allow to send a different instance of
34  * event object to the change event, it needs to be able to set the instance property
35  * of the original event object. For this purpose a subclass of this event object
36  * containing a package protected setter for the instance attribute should be used.
37  * Note that for this purpose the instance property is defined as protected instead
38  * of private final.
39  *
40  * @author Martin Matula
41  */

42 public class InstanceEvent extends MDRChangeEvent {
43     /** Bitmask representing all the events related to instance lifecycle. */
44     public static final int EVENTMASK_INSTANCE = 0x201FFFF;
45
46     /** Identifier for event type that indicates creation of a new instance of a class. */
47     public static final int EVENT_INSTANCE_CREATE = 0x2010001;
48     /** Identifier for event type that indicates an instance of a class is to be/was deleted. */
49     public static final int EVENT_INSTANCE_DELETE = 0x2010002;
50
51     private final List JavaDoc arguments;
52     protected RefObject instance;
53
54     /** Creates new InstanceEvent object.
55      * @param source Event source (class proxy in case of instance creation, instance in case of instance deletion).
56      * @param type Event type.
57      * @param arguments Immutable list of initial attribute values of the new instance (null in case of instance deletion).
58      * @param instance The created/deleted instance or null (in case of pre-change event indicating instance creation).
59      */

60     public InstanceEvent(RefFeatured source, int type, List JavaDoc arguments, RefObject instance) {
61         super(source, type);
62         this.arguments = arguments;
63         this.instance = instance;
64     }
65     
66     /** Returns list of initial values for instance attributes (only applicable for instance creation - otherwise null).
67      * @return List of initial attribute values.
68      */

69     public List JavaDoc getArguments() {
70         return arguments;
71     }
72     
73     /** Returns the created/deleted instance.
74      * @return Created/deleted instance.
75      */

76     public RefObject getInstance() {
77         return instance;
78     }
79 }
80
Popular Tags