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.n
040: */
041:
042: package org.netbeans.modules.web.wizards;
043:
044: import java.io.IOException;
045:
046: import org.openide.filesystems.FileObject;
047:
048: import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
049: import org.netbeans.modules.j2ee.dd.api.web.WebApp;
050:
051: //import org.netbeans.api.java.classpath.ClassPath;
052: //import org.netbeans.api.project.Project;
053: //import org.netbeans.api.project.FileOwnerQuery;
054: import org.netbeans.modules.web.api.webmodule.WebModule;
055:
056: /**
057: * Generic methods for evaluating the input into the wizards.
058: *
059: * @author Ana von Klopp
060: */
061:
062: abstract class DeployData {
063:
064: WebApp webApp = null;
065: String className = null;
066: boolean makeEntry = true;
067: FileObject ddObject = null;
068:
069: final static boolean debug = false;
070:
071: // This is the web app file object
072: void setWebApp(FileObject fo) {
073: if (debug)
074: log("::setWebApp()");
075: if (fo == null) {
076: ddObject = null;
077: webApp = null;
078: return;
079: }
080:
081: ddObject = fo;
082:
083: try {
084: webApp = DDProvider.getDefault().getDDRoot(fo);
085: if (debug)
086: log(webApp.toString());
087: } catch (IOException ioex) {
088: if (debug) {
089: log("Couldn't get the web app!");
090: ioex.printStackTrace(); // XXX this is not an exception handling
091: }
092: } catch (Exception ex) {
093: if (debug) {
094: log("Couldn't get the web app!");
095: ex.printStackTrace(); // XXX this is not an exception handling
096: }
097: }
098: }
099:
100: String getClassName() {
101: if (className == null)
102: return "";
103: return className;
104: }
105:
106: void setClassName(String name) {
107: this .className = name;
108: }
109:
110: boolean makeEntry() {
111: return makeEntry;
112: }
113:
114: void setMakeEntry(boolean makeEntry) {
115: this .makeEntry = makeEntry;
116: }
117:
118: void writeChanges() throws IOException {
119:
120: if (debug)
121: log("::writeChanges()"); //NOI18N
122: if (webApp == null)
123: return;
124: if (debug)
125: log("now writing..."); //NOI18N
126: webApp.write(ddObject);
127: }
128:
129: abstract boolean isValid();
130:
131: // This must invoke write changes at the end
132: abstract void createDDEntries();
133:
134: abstract String getErrorMessage();
135:
136: abstract void log(String s);
137:
138: abstract void setAddToDD(boolean addToDD);
139:
140: abstract boolean isAddToDD();
141:
142: public static FileObject getWebAppFor(FileObject folder) {
143: if (folder == null)
144: return null;
145: WebModule webModule = WebModule.getWebModule(folder);
146: if (webModule == null)
147: return null;
148: return webModule.getDeploymentDescriptor();
149: }
150:
151: public boolean hasDD() {
152: return webApp != null;
153: }
154: }
|