001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.tools.generator;
042:
043: import java.util.*;
044: import java.beans.*;
045:
046: import org.openide.nodes.Node;
047: import org.openide.util.HelpCtx;
048: import org.openide.util.actions.CookieAction;
049:
050: import org.netbeans.modules.xml.actions.CollectXMLAction;
051: import org.netbeans.modules.xml.actions.CollectDTDAction;
052:
053: import org.netbeans.modules.xml.lib.GuiUtil;
054: import org.openide.util.NbBundle;
055:
056: public abstract class XMLGenerateAction extends CookieAction {
057:
058: /** Stream serialVersionUID as of Build1099j. */
059: protected static final long serialVersionUID = -6614874187800576344L;
060:
061: /* @return the mode of action. */
062: protected int mode() {
063: return MODE_ALL;
064: }
065:
066: /* Human presentable name of the action. This should be
067: * presented as an item in a menu.
068: * @return the name of the action
069: */
070: public abstract String getName();
071:
072: protected Class[] cookieClasses() {
073: return new Class[] { getOwnCookieClass() };
074: }
075:
076: protected Class getOwnCookieClass() {
077: return XMLGenerateCookie.class;
078: }
079:
080: protected boolean asynchronous() {
081: return false;
082: }
083:
084: /*
085: * This code is called from a "Module-actions" thread.
086: */
087: protected void performAction(final Node[] activatedNodes) {
088: try {
089: for (int i = 0; i < activatedNodes.length; i++) {
090: Class cake = getOwnCookieClass();
091: XMLGenerateCookie gc = (XMLGenerateCookie) activatedNodes[i]
092: .getCookie(cake);
093: if (gc != null) {
094: gc.generate();
095: } else {
096: throw new IllegalStateException("Missing cookie "
097: + cake);
098: }
099: }
100: } catch (RuntimeException ex) {
101: String msg = NbBundle.getMessage(XMLGenerateAction.class,
102: "MSG_action_failed"); //NOI18N
103: GuiUtil.notifyException(msg, ex);
104: }
105: }
106:
107: //////////////////////////
108: // class GenerateDTDAction
109: public static class GenerateDTDAction extends XMLGenerateAction
110: implements CollectXMLAction.XMLAction {
111: /** generated Serialized Version UID */
112: private static final long serialVersionUID = 8532990650127561962L;
113:
114: /* Human presentable name of the action. This should be
115: * presented as an item in a menu.
116: * @return the name of the action
117: */
118: public String getName() {
119: return NbBundle.getMessage(XMLGenerateAction.class,
120: "PROP_GenerateDTD");
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(GenerateDTDAction.class);
128: }
129:
130: protected Class getOwnCookieClass() {
131: return GenerateDTDSupport.class;
132: }
133: } // end of inner class GenerateDTDAction
134:
135: //////////////////////////////////////
136: // class GenerateDocumentHandlerAction
137: // public static class GenerateDocumentHandlerAction extends XMLGenerateAction implements CollectDTDAction.DTDAction {
138: /** generated Serialized Version UID */
139: // private static final long serialVersionUID = 1342753912956042368L;
140: /* Human presentable name of the action. This should be
141: * presented as an item in a menu.
142: * @return the name of the action
143: */
144: // public String getName () {
145: // return NbBundle.getMessage(XMLGenerateAction.class, "PROP_GenerateSAXHandler");
146: // }
147: /* Help context where to find more about the action.
148: * @return the help context for this action
149: */
150: // public HelpCtx getHelpCtx () {
151: // return new HelpCtx (GenerateDocumentHandlerAction.class);
152: // }
153: // protected Class getOwnCookieClass () {
154: // return SAXGeneratorSupport.class;
155: // }
156: // } // end of inner class GenerateDocumentHandlerAction
157: /////////////////////////////////
158: // class GenerateDOMScannerAction
159: // public static class GenerateDOMScannerAction extends XMLGenerateAction implements CollectDTDAction.DTDAction {
160: /** generated Serialized Version UID */
161: // private static final long serialVersionUID = 2567846356902367312L;
162: /* Human presentable name of the action. This should be
163: * presented as an item in a menu.
164: * @return the name of the action
165: */
166: // public String getName () {
167: // return NbBundle.getMessage(XMLGenerateAction.class, "PROP_GenerateDOMScanner");
168: // }
169: /* Help context where to find more about the action.
170: * @return the help context for this action
171: */
172: // public HelpCtx getHelpCtx () {
173: // return new HelpCtx (GenerateDOMScannerAction.class);
174: // }
175: // protected Class getOwnCookieClass () {
176: // return GenerateDOMScannerSupport.class;
177: // }
178: // } // end of inner class GenerateDOMScannerAction
179: }
|