KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > ResourceConfigData


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 /*
20  * ResourceConfigData.java
21  *
22  * Created on October 5, 2002, 6:20 PM
23  */

24 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
25
26 import java.util.Set JavaDoc;
27 import java.util.Vector JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import org.openide.util.NbBundle;
30 import org.openide.filesystems.FileObject;
31 import org.openide.loaders.DataFolder;
32
33 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
34
35 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
36 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
37
38 /**
39  *
40  * @author shirleyc
41  */

42 public class ResourceConfigData implements WizardConstants {
43  
44     private DataFolder targetFolder;
45     private String JavaDoc targetFolderPath;
46     private String JavaDoc targetFile;
47     private FileObject targetFileObject;
48     private ResourceConfigHelperHolder holder;
49     private Hashtable JavaDoc prop_value_map = new Hashtable JavaDoc();
50     private String JavaDoc resName;
51     
52     public static Wizard cpWizard = null;
53     public static Wizard dsWizard = null;
54     public static Wizard jmsWizard = null;
55     public static Wizard mailWizard = null;
56     public static Wizard pmWizard = null;
57     
58     public ResourceConfigData() {
59     }
60     
61     /*public ResourceConfigData(org.netbeans.modules.j2ee.sun.share.dd.resources.JdbcConnectionPool pool) throws NullPointerException{
62         Wizard wiz = getCPWizard();
63         String[] attrNames = FieldHelper.getFieldNames(wiz);
64             
65         for (int i = 0; i < attrNames.length; i++) {
66             try {
67                 String value = pool.getAttributeValue(attrNames[i]);
68                 if (value != null) {
69                     setString(attrNames[i], value);
70                 }
71             } catch (Exception ex) {
72                 System.out.println("error in Resource Config data ");
73             }
74         }
75         ExtraProperty[] props = pool.getExtraProperty();
76         Vector vec = new Vector();
77         for (int i = 0; i < props.length; i++) {
78             NameValuePair pair = new NameValuePair();
79             pair.setParamName(props[i].getAttributeValue("name")); //NOI18N
80             pair.setParamValue(props[i].getAttributeValue("value")); //NOI18N
81             pair.setParamDescription(props[i].getDescription()); //NOI18N
82             vec.add(pair);
83         }
84         set(__Properties, vec);
85         
86         //set name
87         String name = pool.getAttributeValue(__Name);
88         String dataSourceClassName = pool.getAttributeValue(__DatasourceClassname);
89         setString(__Name, name);
90     }*/

91     
92     public void removeAll() {
93         prop_value_map = new Hashtable JavaDoc();
94     }
95     
96     public String JavaDoc getResourceName() {
97         return resName;
98     }
99     
100     public void setResourceName(String JavaDoc name) {
101         resName = name;
102     }
103     
104     public String JavaDoc getString(String JavaDoc name) {
105         Object JavaDoc value = prop_value_map.get(name);
106         if (value == null)
107             return new String JavaDoc();
108         else
109             return (String JavaDoc)value;
110     }
111     
112     public void setString(String JavaDoc name, String JavaDoc value) {
113         set(name, value);
114     }
115     
116     public Object JavaDoc get(String JavaDoc name) {
117         return prop_value_map.get(name);
118     }
119     
120     public void set(String JavaDoc name, Object JavaDoc value) {
121         prop_value_map.put(name, value);
122     }
123     
124     public String JavaDoc[] getFieldNames() {
125         Set JavaDoc keySet = prop_value_map.keySet();
126         String JavaDoc[] fieldNames = new String JavaDoc[keySet.size()];
127         return (String JavaDoc[])keySet.toArray(fieldNames);
128     }
129     
130     public Vector JavaDoc getProperties() {
131         Vector JavaDoc props = (Vector JavaDoc)prop_value_map.get(__Properties); //NOI18N
132
if (props == null) {
133             props = new Vector JavaDoc();
134             prop_value_map.put(__Properties, props); //NOI18N
135
}
136         return props;
137     }
138     
139     public Vector JavaDoc getPropertyNames() {
140         Vector JavaDoc props = getProperties();
141         Vector JavaDoc vec = new Vector JavaDoc();
142         for (int i = 0; i < props.size(); i++) {
143             vec.add(((NameValuePair)props.elementAt(i)).getParamName());
144         }
145         return vec;
146     }
147     
148     public String JavaDoc getPropertyValue(String JavaDoc propName) {
149         Vector JavaDoc vec = getProperties();
150         for (int i = 0; i < vec.size(); i++) {
151             NameValuePair pair = (NameValuePair)vec.elementAt(i);
152             if (pair.getParamName().equals(propName))
153                 return pair.getParamValue();
154         }
155         return null;
156     }
157     
158     public Vector JavaDoc addProperty(NameValuePair pair) {
159         Vector JavaDoc names = getPropertyNames();
160         if (names.contains(pair.getParamName()))
161             return null;
162         Vector JavaDoc props = getProperties();
163         props.add(pair);
164         return props;
165     }
166     
167     public Vector JavaDoc addProperty(String JavaDoc name, String JavaDoc value) {
168         NameValuePair pair = new NameValuePair();
169         pair.setParamName(name);
170         pair.setParamValue(value);
171         return addProperty(pair);
172     }
173     
174     public void removeProperty(int index) {
175         Vector JavaDoc props = getProperties();
176         props.removeElementAt(index);
177     }
178     
179     public void setProperties(Vector JavaDoc props) {
180            set(__Properties, props);
181     }
182     
183     public String JavaDoc toString() {
184         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc();
185         retValue.append(getResourceName() + "::\n"); //NOI18N
186
String JavaDoc[] fieldNames = getFieldNames();
187         for (int i = 0; i < fieldNames.length; i++) {
188             if (fieldNames[i].equals(__Properties)) {
189                 retValue.append("properties: \n"); //NOI18N
190
Vector JavaDoc props = (Vector JavaDoc)getProperties();
191                 for (int j = 0; j < props.size(); j++) {
192                     NameValuePair pair = (NameValuePair)props.elementAt(j);
193                     retValue.append(" " + pair.getParamName() + ": " + pair.getParamValue()); //NOI18N
194
}
195             }
196             else
197                 retValue.append(fieldNames[i] + ": " + getString(fieldNames[i]) + "\n"); //NOI18N
198
}
199         return retValue.toString();
200     }
201     
202     public void setTargetFolder(DataFolder targetFolder){
203         this.targetFolder = targetFolder;
204     }
205     
206     public DataFolder getTargetFolder(){
207         return this.targetFolder;
208     }
209     
210     public void setTargetFolderPath(String JavaDoc path){
211         this.targetFolderPath = path;
212     }
213     
214     public String JavaDoc getTargetFolderPath(){
215         return this.targetFolderPath;
216     }
217
218     public void setTargetFile(String JavaDoc targetFile){
219         this.targetFile = targetFile;
220     }
221     
222     public String JavaDoc getTargetFile(){
223         return this.targetFile;
224     }
225     
226     public FileObject getTargetFileObject(){
227         return this.targetFileObject;
228     }
229     
230     public void setTargetFileObject(FileObject targetObject){
231         this.targetFileObject = targetObject;
232     }
233  
234     public ResourceConfigHelperHolder getHolder(){
235         return this.holder;
236     }
237     
238     public void setHolder(ResourceConfigHelperHolder holder){
239         this.holder = holder;
240     }
241 }
242
Popular Tags