KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > generator > XMLGenerateAction


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.tools.generator;
20
21 import java.util.*;
22 import java.beans.*;
23
24 import org.openide.nodes.Node;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.actions.CookieAction;
27 import org.openide.util.RequestProcessor;
28
29 import org.netbeans.modules.xml.core.actions.CollectXMLAction;
30 import org.netbeans.modules.xml.core.actions.CollectDTDAction;
31
32 import org.netbeans.modules.xml.core.lib.GuiUtil;
33
34 public abstract class XMLGenerateAction extends CookieAction {
35
36     /** Stream serialVersionUID as of Build1099j. */
37     protected static final long serialVersionUID = -6614874187800576344L;
38     
39     /* @return the mode of action. */
40     protected int mode() {
41         return MODE_ALL;
42     }
43
44     /* Human presentable name of the action. This should be
45      * presented as an item in a menu.
46      * @return the name of the action
47      */

48     public abstract String JavaDoc getName();
49
50     protected Class JavaDoc[] cookieClasses () {
51         return new Class JavaDoc[] { getOwnCookieClass() };
52     }
53
54     protected Class JavaDoc getOwnCookieClass () {
55         return XMLGenerateCookie.class;
56     }
57     
58     protected boolean asynchronous() {
59         return false;
60     }
61
62     /*
63      * This code is called from a "Module-actions" thread.
64      */

65     protected void performAction (final Node[] activatedNodes) {
66         try {
67             for (int i = 0; i < activatedNodes.length; i++) {
68                 Class JavaDoc cake = getOwnCookieClass();
69                 XMLGenerateCookie gc = (XMLGenerateCookie)activatedNodes[i].getCookie (cake);
70                 if (gc != null) {
71                     gc.generate ();
72                 } else {
73                     throw new IllegalStateException JavaDoc("Missing cookie " + cake);
74                 }
75             }
76         } catch (RuntimeException JavaDoc ex) {
77             String JavaDoc msg = Util.THIS.getString("MSG_action_failed"); //NOI18N
78
GuiUtil.notifyException(msg, ex);
79         }
80     }
81
82
83     //////////////////////////
84
// class GenerateDTDAction
85
public static class GenerateDTDAction extends XMLGenerateAction implements CollectXMLAction.XMLAction {
86         /** generated Serialized Version UID */
87         private static final long serialVersionUID = 8532990650127561962L;
88
89         /* Human presentable name of the action. This should be
90          * presented as an item in a menu.
91          * @return the name of the action
92          */

93         public String JavaDoc getName () {
94             return Util.THIS.getString ("PROP_GenerateDTD");
95         }
96
97         /* Help context where to find more about the action.
98          * @return the help context for this action
99          */

100         public HelpCtx getHelpCtx () {
101             return new HelpCtx (GenerateDTDAction.class);
102         }
103
104         protected Class JavaDoc getOwnCookieClass () {
105             return GenerateDTDSupport.class;
106         }
107     } // end of inner class GenerateDTDAction
108

109     //////////////////////////////////////
110
// class GenerateDocumentHandlerAction
111
public static class GenerateDocumentHandlerAction extends XMLGenerateAction implements CollectDTDAction.DTDAction {
112         /** generated Serialized Version UID */
113         private static final long serialVersionUID = 1342753912956042368L;
114
115         /* Human presentable name of the action. This should be
116          * presented as an item in a menu.
117          * @return the name of the action
118          */

119         public String JavaDoc getName () {
120             return Util.THIS.getString ("PROP_GenerateSAXHandler");
121         }
122
123         /* Help context where to find more about the action.
124          * @return the help context for this action
125          */

126         public HelpCtx getHelpCtx () {
127             return new HelpCtx (GenerateDocumentHandlerAction.class);
128         }
129
130         protected Class JavaDoc getOwnCookieClass () {
131             return SAXGeneratorSupport.class;
132         }
133     } // end of inner class GenerateDocumentHandlerAction
134

135     /////////////////////////////////
136
// class GenerateDOMScannerAction
137
public static class GenerateDOMScannerAction extends XMLGenerateAction implements CollectDTDAction.DTDAction {
138         /** generated Serialized Version UID */
139         private static final long serialVersionUID = 2567846356902367312L;
140
141         /* Human presentable name of the action. This should be
142          * presented as an item in a menu.
143          * @return the name of the action
144          */

145         public String JavaDoc getName () {
146             return Util.THIS.getString ("PROP_GenerateDOMScanner");
147         }
148
149         /* Help context where to find more about the action.
150          * @return the help context for this action
151          */

152         public HelpCtx getHelpCtx () {
153             return new HelpCtx (GenerateDOMScannerAction.class);
154         }
155
156         protected Class JavaDoc getOwnCookieClass () {
157             return GenerateDOMScannerSupport.class;
158         }
159     } // end of inner class GenerateDOMScannerAction
160
}
161
Popular Tags