KickJava   Java API By Example, From Geeks To Geeks.

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


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.EventObject JavaDoc;
22
23 /** Root abstract class for all MDR events.
24  * Every MDR event has a type uniquely identified by an integer.
25  * The integers representing the event types are chosen in such a way, that
26  * they can be uniquely combined into a bitmask without losing information
27  * about which event types are represented in the bitmask.
28  * This way the event listeners can filter the events using a bitmask.
29  *
30  * @author Martin Matula
31  * @author <a HREF="mailto:hkrug@rationalizer.com">Holger Krug</a>.
32  */

33 public abstract class MDRChangeEvent extends EventObject JavaDoc {
34     /** Bitmask representing all possible repository event types.
35      * Can be used for registering listener to receive all kinds of events.
36      */

37     public static final int EVENTMASK_ALL = 0x0FFFFFFF;
38     
39     /** Bitmask representing all event types which are initially fired on
40      * associations. */

41     public static final int EVENTMASK_ON_ASSOCIATION = AssociationEvent.EVENTMASK_ASSOCIATION;
42     /** Bitmask representing all event types which are initially fired on
43      * instance objects. */

44     public static final int EVENTMASK_ON_INSTANCE = InstanceEvent.EVENT_INSTANCE_CREATE | AttributeEvent.EVENTMASK_ATTRIBUTE;
45     /** Bitmask representing all event types which are initially fired on
46      * class proxies. */

47     public static final int EVENTMASK_ON_CLASS = InstanceEvent.EVENT_INSTANCE_DELETE | AttributeEvent.EVENTMASK_CLASSATTR;
48     /** Bitmask representing all event types which are initially fired on
49      * package proxies.
50      *
51      * <p><em>Note:</em> This bitmask is empty, because there are not
52      * events which originate on packages. Packages receive only events
53      * propagated from other objects. As a consequence this bitmask is
54      * useless. It is nevertheless part of the API to achieve greater
55      * uniformity of the API.</p>
56      */

57     public static final int EVENTMASK_ON_PACKAGE = 0x0000000;
58     /** Bitmask representing all event types which are initially fired on
59      * repositories. */

60     public static final int EVENTMASK_ON_REPOSITORY = ExtentEvent.EVENTMASK_EXTENT | TransactionEvent.EVENTMASK_TRANSACTION;
61
62     // event type
63
private final int eventType;
64
65     /** Creates a new instance of MDR event
66      * @param source Source object for this event.
67      * @param type Number indicating type of this event.
68      */

69     public MDRChangeEvent(Object JavaDoc source, int type) {
70         super(source);
71         eventType = type;
72     }
73
74     /** Returns type of this event.
75      * @return Number indicating type of this event.
76      */

77     public int getType() {
78         return eventType;
79     }
80
81     /** Returns <CODE>true</CODE> if the type of this event is contained in the provided
82      * bitmask.
83      * @param mask Bitmask.
84      * @return <CODE>true</CODE> - the type of this event is contained in the bitmask (i.e. type & mask == type)
85      * <CODE>false</CODE> - the type of this event is not contained in the bitmask (i.e. type & mask < type)
86      */

87     public boolean isOfType(int mask) {
88         return ((eventType & mask) == eventType);
89     }
90 }
91
Popular Tags