KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > 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 /*
21  * ResourceConfigData.java
22
23  */

24 package org.netbeans.modules.j2ee.sun.ws7.serverresources.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  * Code reused from Appserver common API module
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     
53     public ResourceConfigData() {
54     }
55     
56     /*public ResourceConfigData(org.netbeans.modules.j2ee.sun.share.dd.resources.JdbcConnectionPool pool) throws NullPointerException{
57         Wizard wiz = getCPWizard();
58         String[] attrNames = FieldHelper.getFieldNames(wiz);
59             
60         for (int i = 0; i < attrNames.length; i++) {
61             try {
62                 String value = pool.getAttributeValue(attrNames[i]);
63                 if (value != null) {
64                     setString(attrNames[i], value);
65                 }
66             } catch (Exception ex) {
67                 System.out.println("error in Resource Config data ");
68             }
69         }
70         ExtraProperty[] props = pool.getExtraProperty();
71         Vector vec = new Vector();
72         for (int i = 0; i < props.length; i++) {
73             NameValuePair pair = new NameValuePair();
74             pair.setParamName(props[i].getAttributeValue("name")); //NOI18N
75             pair.setParamValue(props[i].getAttributeValue("value")); //NOI18N
76             pair.setParamDescription(props[i].getDescription()); //NOI18N
77             vec.add(pair);
78         }
79         set(__Properties, vec);
80         
81         //set name
82         String name = pool.getAttributeValue(__Name);
83         String dataSourceClassName = pool.getAttributeValue(__DatasourceClassname);
84         setString(__Name, name);
85     }*/

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