KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > core > DTDDataObject


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.modules.xml.core;
20
21 import org.openide.filesystems.*;
22 import org.openide.loaders.*;
23 import org.openide.cookies.*;
24 import org.openide.actions.*;
25 import org.openide.util.*;
26 import org.openide.util.actions.*;
27 import org.openide.nodes.*;
28 import org.openide.windows.CloneableOpenSupport;
29
30 import org.netbeans.modules.xml.core.text.TextEditorSupport;
31 import org.netbeans.modules.xml.core.sync.*;
32 import org.netbeans.modules.xml.core.cookies.*;
33
34 import org.xml.sax.*;
35
36 import org.netbeans.spi.xml.cookies.*;
37 import org.xml.sax.InputSource JavaDoc;
38
39 /**
40  * Implementation that provides main functionality for DTD data object.
41  *
42  * @author Libor Kramolis
43  * @author Petr Kuzel
44  */

45 public final class DTDDataObject extends MultiDataObject implements XMLDataObjectLook {
46
47     /** generated Serialized Version UID */
48     private static final long serialVersionUID = 2890472952957502631L;
49         
50     /** Default DTD MIME type. */
51     public static final String JavaDoc MIME_TYPE = "application/xml-dtd"; // http://www.ietf.org/rfc/rfc3023.txt // NOI18N
52

53     /** Delegate sync support */
54     private final DTDSyncSupport sync;
55     
56     /** Cookie Manager */
57     private final DataObjectCookieManager cookieManager;
58
59     
60     //
61
// init
62
//
63

64     public DTDDataObject (final FileObject obj, final UniFileLoader loader) throws DataObjectExistsException {
65         super (obj, loader);
66                 
67 //??? controller getPrimaryFile().addFileChangeListener (new FileListener ());
68

69         CookieSet set = getCookieSet();
70         set.add (cookieManager = new DataObjectCookieManager (this, set));
71         
72         sync = new DTDSyncSupport(this);
73         
74         TextEditorSupport.TextEditorSupportFactory editorFactory =
75             TextEditorSupport.findEditorSupportFactory (this, MIME_TYPE);
76         editorFactory.registerCookies (set);
77
78         InputSource JavaDoc in = DataObjectAdapters.inputSource(this);
79         set.add(new CheckXMLSupport(in, CheckXMLSupport.CHECK_PARAMETER_ENTITY_MODE));
80
81         //??? This strange line registers updater of mu cookie set
82
new CookieManager (this, set, DTDCookieFactoryCreator.class);
83     }
84
85 // // from XMLDataObjectLook
86
// public void updateTextDocument () {
87
// EditorCookie es = (EditorCookie)getCookie (EditorCookie.class);
88
// if (es != null) {
89
// es.close();
90
// }
91
// }
92

93
94     /**
95      */

96     protected Node createNodeDelegate () {
97         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("--> DTDDataObject.createNodeDelegate: this = " + this);
98
99         DataNodeCreator dataNodeCreator = (DataNodeCreator) Lookup.getDefault().lookup (DataNodeCreator.class);
100         DataNode dataNode = null;
101
102         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("-*- DTDD O .createNodeDelegate: dataNodeCreator = " + dataNodeCreator);
103
104         if ( dataNodeCreator != null ) {
105             dataNode = dataNodeCreator.createDataNode (this);
106         } else {
107             dataNode = new DTDDataNode (this);
108         }
109
110         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("<-- DTDDataObject.createNodeDelegate: dataNode = " + dataNode);
111
112         return dataNode;
113     }
114
115     /** @return provider of sync interface. */
116     public Synchronizator getSyncInterface() {
117         return sync;
118     }
119
120     // ~~~~~~~~~~~~~~~~~ COOKIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
121

122
123     /** Synchronize and delegate to super. */
124     public Node.Cookie getCookie(Class JavaDoc klass) {
125
126         Node.Cookie cake = null;
127         boolean change = false;
128
129         // take lock to prevent deadlock on cookie set that can be called
130
// from other thred during cookie removal
131
synchronized (this) {
132             cake = super.getCookie (klass);
133
134             if ( ( cake == null ) &&
135                  ( CloneableOpenSupport.class == klass ) ) { //!!! HACK -- backward compatibility
136
cake = super.getCookie (OpenCookie.class);
137             }
138         }
139                 
140         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("DTD cookie query " + klass + " => " + cake); // NOI18N
141

142         return cake;
143     }
144     
145     
146     public DataObjectCookieManager getCookieManager () {
147         return cookieManager;
148     }
149     
150
151     public HelpCtx getHelpCtx() {
152         //return new HelpCtx(DTDDataObject.class);
153
return HelpCtx.DEFAULT_HELP;
154     }
155         
156
157     //
158
// class DTDDataNode
159
//
160

161     /**
162      *
163      */

164     private static class DTDDataNode extends DataNode {
165
166         /** Create new DTDDataNode. */
167         public DTDDataNode (DTDDataObject obj) {
168             super (obj, Children.LEAF);
169
170             setDefaultAction (SystemAction.get (EditAction.class));
171             setIconBase ("org/netbeans/modules/xml/core/resources/dtdObject"); // NOI18N
172
setShortDescription (Util.THIS.getString ("PROP_DTDDataNode_description"));
173         }
174
175         public HelpCtx getHelpCtx() {
176             //return new HelpCtx(DTDDataObject.class);
177
return HelpCtx.DEFAULT_HELP;
178         }
179         
180     } // end of class DTDDataNode
181

182
183
184     //
185
// interface DataNodeCreator
186
//
187

188     /**
189      *
190      */

191     public static interface DataNodeCreator {
192
193         /**
194          */

195         public DataNode createDataNode (DTDDataObject dtdDO);
196
197     } // end of interface DataNodeCreator
198

199
200
201     //
202
// interface DTDCookieFactoryCreator
203
//
204

205     /**
206      *
207      */

208     public static interface DTDCookieFactoryCreator extends CookieFactoryCreator {
209         
210     } // end: interface DTDCookieFactoryCreator
211

212 }
213
Popular Tags