KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > cookies > ConnectionCookie


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.openide.cookies;
20
21 import java.util.Set JavaDoc;
22 import org.openide.nodes.Node;
23
24 import java.io.IOException JavaDoc;
25
26 import java.util.EventListener JavaDoc;
27
28
29 /** Cookie that allows connection between two objects. Also supporting
30 * persistent connections.
31 *
32 * @author Jaroslav Tulach
33  * @deprecated Should no longer be used.
34 */

35 @Deprecated JavaDoc
36 public interface ConnectionCookie extends Node.Cookie {
37     /** Attaches new node to listen to events produced by this
38     * event. The type must be one of event types supported by this
39     * cookie and the listener should have ConnectionCookie.Listener cookie
40     * attached so it can be notified when event of requested type occurs.
41     *
42     * @param type the type of event, must be supported by the cookie
43     * @param listener the node that should be notified
44     *
45     * @exception InvalidObjectException if the type is not supported by the cookie
46     * @exception IOException if the type is persistent and the listener does not
47     * have serializable handle (listener.getHandle () is null or its serialization
48     * throws an exception)
49     */

50     public void register(Type type, Node listener) throws IOException JavaDoc;
51
52     /** Unregisters an listener.
53     * @param type type of event to unregister the listener from listening to
54     * @param listener to unregister
55     * @exception IOException if there is I/O operation error when the removing
56     * the listener from persistent storage
57     */

58     public void unregister(Type type, Node listener) throws IOException JavaDoc;
59
60     /** Immutable set of types supported by this connection source.
61     * @return a set of types
62     */

63     public Set JavaDoc<? extends ConnectionCookie.Type> getTypes();
64
65     /** Cookie that must be provided by a node that is willing to register
66     * itself as a listener to a ConnectionCookie.
67     */

68     public interface Listener extends Node.Cookie, EventListener JavaDoc {
69         /** Notifies that the an event happended.
70         * @param ev event that describes the action
71         * @exception IllegalArgumentException if the event is not of valid type, then the
72         * caller should call the listener no more
73         * @exception ClassCastException if the event is not of valid type, then the
74         * caller should call the listener no more
75         */

76         public void notify(ConnectionCookie.Event ev) throws IllegalArgumentException JavaDoc, ClassCastException JavaDoc;
77     }
78
79     /** Interface describing cookie type of event a cookie can produce.
80     */

81     public interface Type extends java.io.Serializable JavaDoc {
82         /** The class that is passed into the listener's <CODE>notify</CODE>
83         * method when an event of this type is fired.
84         *
85         * @return event class
86         */

87         public Class JavaDoc<?> getEventClass();
88
89         /** Getter whether the registration to this type of event is persistent
90         * or is valid only till the source disappears (the IDE shutdowns).
91         */

92         public boolean isPersistent();
93
94         // Jesse, please improve the comment. [Petr]
95

96         /** Test whether the specified type could be accepted by this type.
97         * This method is similar to <CODE>equals(Object)</CODE> method,
98         * so default implementation could be delegated to it.
99         * @return <CODE>true</CODE> if type is similar to this type.
100         */

101         public boolean overlaps(Type type);
102     }
103
104     /** Event that is fired to listeners.
105     */

106     public class Event extends java.util.EventObject JavaDoc {
107         static final long serialVersionUID = 7177610435688865839L;
108         private Type type;
109
110         /** @param n the node that produced the action
111         * @param t type of the event
112         */

113         public Event(Node n, Type t) {
114             super(n);
115             type = t;
116         }
117
118         /** Getter for the node that produced the action.
119         * The node can be used to obtain additional information like cookies, etc.
120         * @return the node
121         */

122         public Node getNode() {
123             return (Node) getSource();
124         }
125
126         /** Getter for the type of the event.
127         * There can be more types of events and the listener can compare
128         * if two events are of the same type by using type1.equals (type2)
129         *
130         * @return type of the event
131         */

132         public Type getType() {
133             return type;
134         }
135     }
136 }
137
Popular Tags