KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jmi.reflect.RefAssociation;
22 import javax.jmi.reflect.RefObject;
23
24 /** MDR Event used for representing association-related events.
25  * Any association event is described the way that there is one association end
26  * taken as "fixed". This means that the change will be described from the perspective
27  * of this association end. For changes to the association caused by modifying
28  * a reference or live collection returned from a getter for an association end this behavior
29  * is very intuitive - the fixed association end will be the exposed end of
30  * the reference (or the fixed element will be the element provided to getter for
31  * association end). For direct association proxy operations (i.e. remove or add),
32  * the event object looks as follows:<ul>
33  * <li> remove - the fixed element is any of the two linked elements, old element
34  * represents the element on the other side of the link, new element is null</li>
35  * <li> add - the fixed element is any of the two linked elements, old element
36  * is null, the element on the other side of the link is represented as the new
37  * element.</li>
38  *</ul>
39  *
40  * @author Martin Matula
41  */

42 public class AssociationEvent extends MDRChangeEvent {
43     /** Value indicating unspecified position */
44     public static final int POSITION_NONE = -1;
45     
46     /** Bitmask for event types related to operations with associations.
47      * Can be used for registering a listener for listening to all association-related events.
48      */

49     public static final int EVENTMASK_ASSOCIATION = 0x401FFFF;
50
51     /** Identifier of the event type indicating that one end of an existing
52      * association link is to be/was modified.
53      */

54     public static final int EVENT_ASSOCIATION_SET = 0x4010001;
55     /** Identifier of the event type indicating that a new link is to be/was added.
56      */

57     public static final int EVENT_ASSOCIATION_ADD = 0x4010002;
58     /** Identifier of the event type indicating that an existing link is to be/was removed.
59      */

60     public static final int EVENT_ASSOCIATION_REMOVE = 0x4010004;
61     
62     // element on fixed association end
63
private final RefObject fixedElement;
64     // name of fixed association end
65
private final String JavaDoc endName;
66     // original element on the non-fixed end
67
private final RefObject oldElement;
68     // new element on the non-fixed end
69
private final RefObject newElement;
70     // position of the affected element on the non-fixed end
71
private final int position;
72     
73     /** Creates new AssociationEvent object.
74      * @param source Event source (association proxy object).
75      * @param type Event type.
76      * @param fixedElement Element of the affected link on the side of fixed association end.
77      * @param endName Name of association end on the fixed side of the link.
78      * @param oldElement Original element of the affected link on the non-fixed side of the link or null.
79      * @param newElement New element of the affected link on the non-fixed side of the link or null.
80      * @param position Position of the element on the non-fixed side of the affected link or {@link #POSITION_NONE} if not applicable.
81      */

82     public AssociationEvent(RefAssociation source, int type, RefObject fixedElement, String JavaDoc endName, RefObject oldElement, RefObject newElement, int position) {
83         super(source, type);
84         this.fixedElement = fixedElement;
85         this.endName = endName;
86         this.oldElement = oldElement;
87         this.newElement = newElement;
88         this.position = position;
89     }
90
91     /** Returns the element on the fixed side of the affected link.
92      * @return Link element.
93      */

94     public RefObject getFixedElement() {
95         return fixedElement;
96     }
97     
98     /** Returns name of the fixed association end.
99      * @return Association end name.
100      */

101     public String JavaDoc getEndName() {
102         return endName;
103     }
104     
105     /** Returns the original element on the non-fixed side of the affected link.
106      * @return Link element or null.
107      */

108     public RefObject getOldElement() {
109         return oldElement;
110     }
111     
112     /** Returns the new element on the non-fixed side of the affected link.
113      * @return Link element or null.
114      */

115     public RefObject getNewElement() {
116         return newElement;
117     }
118     
119     /** Returns position of the non-fixed element of the affected link.
120      * @return Position of element or {@link #POSITION_NONE}.
121      */

122     public int getPosition() {
123         return position;
124     }
125 }
126
Popular Tags