KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > settings > Convertor


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 2002 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.settings;
21
22 import org.openide.util.Lookup;
23
24 /** Convertor allows to read/write objects in own format and notify about
25  * object changes.
26  *
27  * @author Jan Pokorsky
28  */

29 public abstract class Convertor {
30
31     /** Subclasses can implement own storing format.
32      * @param w stream into which inst is written
33      * @param inst the setting object to be written
34      * @exception IOException if the object cannot be written
35      */

36     public abstract void write (java.io.Writer JavaDoc w, Object JavaDoc inst) throws java.io.IOException JavaDoc;
37
38     /** Subclasses have to be able to read format implemented by {@link #write}.
39      * @param r stream containing stored object
40      * @return the read setting object
41      * @exception IOException if the object cannot be read
42      * @exception ClassNotFoundException if the object class cannot be resolved
43      */

44     public abstract Object JavaDoc read (java.io.Reader JavaDoc r) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc;
45     
46     /** register {@link Saver saver}; convertor can provide own policy notifing
47      * the saver about changes of setting object. (e.g. register property
48      * change listener)
49      * @param inst setting object
50      * @param s saver implementation
51      */

52     public abstract void registerSaver (Object JavaDoc inst, Saver s);
53     
54     /** unregister {@link Saver saver}
55      * @param inst setting object
56      * @param s saver implementation
57      * @see #registerSaver
58      */

59     public abstract void unregisterSaver (Object JavaDoc inst, Saver s);
60     
61     /** get a context associated with the reader <code>r</code>. It can contain
62      * various info like a file location of the read object etc.
63      * @param r stream containing stored object
64      * @return a context associated with the reader
65      * @since 1.2
66      */

67     protected static org.openide.util.Lookup findContext(java.io.Reader JavaDoc r) {
68         if (r instanceof Lookup.Provider) {
69             return ((Lookup.Provider) r).getLookup();
70         } else {
71             return Lookup.EMPTY;
72         }
73     }
74     
75     /** get a context associated with the writer <code>w</code>. It can contain
76      * various info like a file location of the written object etc.
77      * @param w stream into which inst is written
78      * @return a context associated with the reader
79      * @since 1.2
80      */

81     protected static org.openide.util.Lookup findContext(java.io.Writer JavaDoc w) {
82         if (w instanceof Lookup.Provider) {
83             return ((Lookup.Provider) w).getLookup();
84         } else {
85             return Lookup.EMPTY;
86         }
87     }
88     
89 }
90
Popular Tags