KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.openide.cookies;
21
22 import java.io.IOException JavaDoc;
23 import org.openide.nodes.Node;
24
25 /**
26  * Cookie that should be provided by all nodes that are able
27  * to create a "instance".
28  * Generally this is used to register objects declaratively in XML layers.
29  *
30  * @author Jaroslav Tulach
31  */

32 public interface InstanceCookie/*<T>*/ extends Node.Cookie {
33
34     /**
35      * The name of {@link #instanceClass}.
36      * Should be the same as <code>instanceClass().getName()</code>
37      * but may be able to avoid actually loading the class.
38      * @return the instance class name
39      */

40     public String JavaDoc instanceName();
41
42     /**
43      * The type that the instance is expected to be assignable to.
44      * Can be used to test whether the instance is of an appropriate
45      * class without actually creating it.
46      *
47      * @return the type (or perhaps some interesting supertype) of the instance
48      * @exception IOException if metadata about the instance could not be read, etc.
49      * @exception ClassNotFoundException if the instance type could not be loaded
50      */

51     public Class JavaDoc<?/*T*/> instanceClass() throws IOException JavaDoc, ClassNotFoundException JavaDoc;
52
53     /**
54      * Create an instance.
55      * @return an object assignable to {@link #instanceClass}
56      * @throws IOException for the same reasons as {@link #instanceClass}, or an object could not be deserialized, etc.
57      * @throws ClassNotFoundException for the same reasons as {@link #instanceClass}
58     */

59     public Object JavaDoc/*T*/ instanceCreate() throws IOException JavaDoc, ClassNotFoundException JavaDoc;
60
61     /**
62      * Enhanced cookie that can answer queries about the type of the
63      * instance it creates. It does not add any additional ability except to
64      * improve performance, because it is not necessary to load
65      * the actual class of the object into memory.
66      *
67      * @since 1.4
68      */

69     public interface Of extends InstanceCookie {
70         /**
71          * Checks if the object created by this cookie is an
72          * instance of the given type. The same as
73          * <code>type.isAssignableFrom(instanceClass())</code>
74          * But this can prevent the actual class from being
75          * loaded into the Java VM.
76          *
77          * @param type the class type we want to check
78          * @return true if this cookie will produce an instance of the given type
79         */

80         public boolean instanceOf(Class JavaDoc<?> type);
81     }
82
83 }
84
Popular Tags