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: /*
042: * ResourceConfigData.java
043: *
044: * Created on October 5, 2002, 6:20 PM
045: */
046: package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
047:
048: import java.util.Set;
049: import java.util.Vector;
050: import java.util.Hashtable;
051: import org.openide.util.NbBundle;
052: import org.openide.filesystems.FileObject;
053: import org.openide.loaders.DataFolder;
054:
055: import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
056:
057: import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
058: import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
059:
060: /**
061: *
062: * @author shirleyc
063: */
064: public class ResourceConfigData implements WizardConstants {
065:
066: private DataFolder targetFolder;
067: private String targetFolderPath;
068: private String targetFile;
069: private FileObject targetFileObject;
070: private ResourceConfigHelperHolder holder;
071: private Hashtable prop_value_map = new Hashtable();
072: private String resName;
073:
074: public static Wizard cpWizard = null;
075: public static Wizard dsWizard = null;
076: public static Wizard jmsWizard = null;
077: public static Wizard mailWizard = null;
078: public static Wizard pmWizard = null;
079:
080: private FileObject projectDirectory;
081:
082: public ResourceConfigData() {
083: }
084:
085: public void removeAll() {
086: prop_value_map = new Hashtable();
087: }
088:
089: public String getResourceName() {
090: return resName;
091: }
092:
093: public void setResourceName(String name) {
094: resName = name;
095: }
096:
097: public String getString(String name) {
098: Object value = prop_value_map.get(name);
099: if (value == null)
100: return new String();
101: else
102: return (String) value;
103: }
104:
105: public void setString(String name, String value) {
106: set(name, value);
107: }
108:
109: public Object get(String name) {
110: return prop_value_map.get(name);
111: }
112:
113: public void set(String name, Object value) {
114: prop_value_map.put(name, value);
115: }
116:
117: public String[] getFieldNames() {
118: Set keySet = prop_value_map.keySet();
119: String[] fieldNames = new String[keySet.size()];
120: return (String[]) keySet.toArray(fieldNames);
121: }
122:
123: public Vector getProperties() {
124: Vector props = (Vector) prop_value_map.get(__Properties); //NOI18N
125: if (props == null) {
126: props = new Vector();
127: prop_value_map.put(__Properties, props); //NOI18N
128: }
129: return props;
130: }
131:
132: public Vector getPropertyNames() {
133: Vector props = getProperties();
134: Vector vec = new Vector();
135: for (int i = 0; i < props.size(); i++) {
136: vec
137: .add(((NameValuePair) props.elementAt(i))
138: .getParamName());
139: }
140: return vec;
141: }
142:
143: public String getPropertyValue(String propName) {
144: Vector vec = getProperties();
145: for (int i = 0; i < vec.size(); i++) {
146: NameValuePair pair = (NameValuePair) vec.elementAt(i);
147: if (pair.getParamName().equals(propName))
148: return pair.getParamValue();
149: }
150: return null;
151: }
152:
153: public Vector addProperty(NameValuePair pair) {
154: Vector names = getPropertyNames();
155: if (names.contains(pair.getParamName()))
156: return null;
157: Vector props = getProperties();
158: props.add(pair);
159: return props;
160: }
161:
162: public Vector addProperty(String name, String value) {
163: NameValuePair pair = new NameValuePair();
164: pair.setParamName(name);
165: pair.setParamValue(value);
166: return addProperty(pair);
167: }
168:
169: public void removeProperty(int index) {
170: Vector props = getProperties();
171: props.removeElementAt(index);
172: }
173:
174: public void setProperties(Vector props) {
175: set(__Properties, props);
176: }
177:
178: public String toString() {
179: StringBuffer retValue = new StringBuffer();
180: retValue.append(getResourceName() + "::\n"); //NOI18N
181: String[] fieldNames = getFieldNames();
182: for (int i = 0; i < fieldNames.length; i++) {
183: if (fieldNames[i].equals(__Properties)) {
184: retValue.append("properties: \n"); //NOI18N
185: Vector props = (Vector) getProperties();
186: for (int j = 0; j < props.size(); j++) {
187: NameValuePair pair = (NameValuePair) props
188: .elementAt(j);
189: retValue.append(" " + pair.getParamName() + ": "
190: + pair.getParamValue()); //NOI18N
191: }
192: } else
193: retValue.append(fieldNames[i] + ": "
194: + getString(fieldNames[i]) + "\n"); //NOI18N
195: }
196: return retValue.toString();
197: }
198:
199: public void setTargetFolder(DataFolder targetFolder) {
200: this .targetFolder = targetFolder;
201: }
202:
203: public DataFolder getTargetFolder() {
204: return this .targetFolder;
205: }
206:
207: public void setTargetFolderPath(String path) {
208: this .targetFolderPath = path;
209: }
210:
211: public String getTargetFolderPath() {
212: return this .targetFolderPath;
213: }
214:
215: public void setTargetFile(String targetFile) {
216: this .targetFile = targetFile;
217: }
218:
219: public String getTargetFile() {
220: return this .targetFile;
221: }
222:
223: public FileObject getTargetFileObject() {
224: return this .targetFileObject;
225: }
226:
227: public void setTargetFileObject(FileObject targetObject) {
228: this .targetFileObject = targetObject;
229: }
230:
231: public FileObject getProjectDirectory() {
232: return this .projectDirectory;
233: }
234:
235: public void setProjectDirectory(FileObject projectDirectory) {
236: this .projectDirectory = projectDirectory;
237: }
238:
239: public ResourceConfigHelperHolder getHolder() {
240: return this .holder;
241: }
242:
243: public void setHolder(ResourceConfigHelperHolder holder) {
244: this.holder = holder;
245: }
246: }
|