KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > deploy > DSFields


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.common.deploy;
25
26 import java.beans.*;
27 import java.net.InetAddress JavaDoc;
28 import java.io.File JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30 import java.util.List JavaDoc;
31 import javax.swing.JOptionPane JavaDoc;
32 //import com.sun.enterprise.tools.buzz.iascom.IDeployListener;
33
//import com.sun.enterprise.tools.buzz.iascom.DeployException;
34
//import com.netscape.server.deployment.DatasourceDescriptor;
35
//import com.sun.enterprise.tools.common.deployment.DSDescriptor;
36
//import com.iplanet.ias.tools.forte.datasource.DSBean;
37
import com.sun.enterprise.tools.common.datasource.IDSBean;
38 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
39 //import com.sun.enterprise.tools.common.deploy.IASDeployer;
40
//import com.iplanet.ias.tools.forte.util.TempDirManager;
41
//import org.openide.filesystems.FileSystem;
42
//import org.openide.filesystems.FileObject;
43
//import org.openide.filesystems.LocalFileSystem;
44
//import com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings;
45

46 public class DSFields extends Object JavaDoc implements java.io.Serializable JavaDoc {
47
48     static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("com.sun.enterprise.tools.common.deploy.Bundle"); //NOI18N
49
private static String JavaDoc filename;
50
51     transient private PropertyChangeSupport propertySupport;
52
53     private String JavaDoc name;
54     private String JavaDoc JndiName;
55     private String JavaDoc PoolName;
56  // private String SupportXA;
57
private String JavaDoc Enabled;
58     private String JavaDoc Description;
59     private NameValuePair[] extParams;
60     
61     private String JavaDoc RegPoolName;
62     
63 /* private String JdbcFactoryClassName;
64     private String DatabaseURL;
65     private String UserName;
66     private String Password;
67     private String ResType;
68     private ResPool resPoolProperties;
69 */

70     /** Creates new ServerInstance */
71     public DSFields(List JavaDoc ds) {
72         propertySupport = new PropertyChangeSupport ( this );
73         
74 // JdbcFactoryClassName = "JdbcFactoryClassName";//NOI18N
75
PoolName = bundle.getString("Unconfigured"); //NOI18N
76
RegPoolName = PoolName;
77 // SupportXA = "false"; //NOI18N
78
Enabled = "true"; //NOI18N
79
Description = ""; //NOI18N
80
extParams = new NameValuePair[0];
81 /* DatabaseURL = "DatabaseURL";//NOI18N
82         UserName = "UserName";//NOI18N
83         Password = "Password";//NOI18N
84         ResType = "ResourceType";//NOI18N
85         resPoolProperties = new ResPool();
86 */

87         //List ds = com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings.DEFAULT.getDataSources();
88
String JavaDoc t_name = null;
89         if(ds.size() != 0){
90            int num = ds.size()+1;
91            t_name = "DataSource_" + num;//NOI18N
92
boolean exists = DataSourceName(t_name,ds);
93            while(exists){
94              num++;
95              t_name = "DataSource_" + num;//NOI18N
96
exists = DataSourceName(t_name,ds);
97            }
98         }else{
99           t_name = "DataSource_1";//NOI18N
100
}
101         name = t_name;
102         JndiName = "jdbc/";//NOI18N
103
}
104
105     public String JavaDoc getJndiName() {
106       return JndiName;
107     }
108     public void setJndiName(java.lang.String JavaDoc jndiName) {
109        String JavaDoc prev = JndiName;
110        this.JndiName = jndiName;
111        initPropertyChangeSupport();
112        propertySupport.firePropertyChange ("JndiName", prev, JndiName);//NOI18N
113
/*
114        if (JndiName.startsWith("jdbc")) // NOI18N
115            setName(JndiName.substring(5));
116        else
117  */

118            setName(JndiName);
119     }
120       
121     public void simpleSetJndiName(String JavaDoc value) {
122         this.JndiName = value;
123         setName(JndiName);
124     }
125     
126     public String JavaDoc getPoolName() {
127         Reporter.info(PoolName + " " + RegPoolName); //NOI18N
128
return PoolName;
129     }
130     
131     public void setPoolName(java.lang.String JavaDoc val) {
132         String JavaDoc prev = PoolName;
133         this.PoolName = val;
134         setRegPoolName(PoolName);
135         Reporter.info(PoolName + " " + RegPoolName); //NOI18N
136
initPropertyChangeSupport();
137         propertySupport.firePropertyChange ("PoolName", prev, PoolName);//NOI18N
138
}
139     
140     public String JavaDoc getRegPoolName(){
141         Reporter.info(PoolName + " " + RegPoolName); //NOI18N
142
return RegPoolName;
143     }
144     public void setRegPoolName(java.lang.String JavaDoc val){
145         String JavaDoc prev = RegPoolName;
146         int offset = val.indexOf("("); //NOI18N
147
if (offset == -1)
148             this.RegPoolName = val;
149         else
150             this.RegPoolName = val.substring(0, offset);
151         Reporter.info(PoolName + " " + RegPoolName); //NOI18N
152
}
153     
154 /*
155     public String getSupportXA() {
156        return SupportXA;
157     }
158     
159     public void setSupportXA(java.lang.String val) {
160         String prev = SupportXA;
161         this.SupportXA = val;
162         initPropertyChangeSupport();
163         propertySupport.firePropertyChange ("SupportXA", prev, SupportXA);//NOI18N
164     }
165 */

166     public String JavaDoc getEnabled() {
167        return Enabled;
168     }
169     
170     public void setEnabled(java.lang.String JavaDoc val) {
171         String JavaDoc prev = Enabled;
172         this.Enabled = val;
173         initPropertyChangeSupport();
174         propertySupport.firePropertyChange ("Enabled", prev, Enabled);//NOI18N
175
}
176         
177     public String JavaDoc getDescription() {
178        return Description;
179     }
180     
181     public void setDescription(java.lang.String JavaDoc val) {
182         String JavaDoc prev = Description;
183         this.Description = val;
184         initPropertyChangeSupport();
185         propertySupport.firePropertyChange ("Description", prev, Description);//NOI18N
186
}
187         
188     public NameValuePair[] getExtParams() {
189         return extParams;
190     }
191
192     public void setExtParams(Object JavaDoc[] value) {
193         Reporter.info(new Integer JavaDoc(value.length)); //NOI18N
194
NameValuePair[] pairs = new NameValuePair[value.length];
195         for (int i = 0; i < value.length; i++) {
196             NameValuePair val = (NameValuePair)value[i];
197             NameValuePair pair = new NameValuePair();
198             pair.setParamName(val.getParamName());
199             pair.setParamValue(val.getParamValue());
200             pair.setParamDescription(val.getParamDescription());
201             Reporter.info(pair.getParamName() + " " + pair.getParamValue()); //NOI18N
202
pairs[i] = pair;
203         }
204         NameValuePair[] oldValue = extParams;
205         this.extParams = pairs;
206         initPropertyChangeSupport();
207         propertySupport.firePropertyChange ("extParams", oldValue, extParams);//NOI18N
208
}
209     
210     private void initPropertyChangeSupport(){
211      if(propertySupport==null)
212          propertySupport = new PropertyChangeSupport ( this );
213
214     }
215     public void addPropertyChangeListener (PropertyChangeListener listener) {
216         initPropertyChangeSupport();
217         propertySupport.addPropertyChangeListener (listener);
218     }
219
220     public void removePropertyChangeListener (PropertyChangeListener listener) {
221         initPropertyChangeSupport();
222         propertySupport.removePropertyChangeListener (listener);
223     }
224     
225    public String JavaDoc getName() {
226         return name;
227     }
228     public void setName(String JavaDoc value) {
229         String JavaDoc oldValue = " "; // NOI18N
230
name = value;
231         initPropertyChangeSupport();
232         propertySupport.firePropertyChange ("name", oldValue, name);//NOI18N
233
}
234  /*
235     public String PWD(){
236         String pw = getPassword();
237         String passw = "*";//NOI18N
238         for(int i=1; i<pw.length(); i++)
239             passw = passw + "*";//NOI18N
240         return passw;
241     }
242     public String getPassword() {
243         return Password;
244     }
245     public void setPassword(java.lang.String passwd) {
246         String prev = Password;
247         this.Password = passwd;
248         initPropertyChangeSupport();
249         propertySupport.firePropertyChange ("Password", prev, Password);//NOI18N
250     }
251
252     public String getJdbcFactoryClassName() {
253         return JdbcFactoryClassName;
254     }
255     public void setJdbcFactoryClassName(java.lang.String facname) {
256         String prev = JdbcFactoryClassName;
257         this.JdbcFactoryClassName = facname;
258         initPropertyChangeSupport();
259         propertySupport.firePropertyChange ("JdbcFactoryClassName", prev, JdbcFactoryClassName);//NOI18N
260     }
261
262     public String getDatabaseURL() {
263         return DatabaseURL;
264     }
265     public void setDatabaseURL(java.lang.String dburl) {
266         String prev = DatabaseURL;
267         this.DatabaseURL = dburl;
268         initPropertyChangeSupport();
269         propertySupport.firePropertyChange ("DatabaseURL", prev, DatabaseURL);//NOI18N
270     }
271
272     public String getUserName() {
273         return UserName;
274     }
275     public void setUserName(java.lang.String name) {
276         String prev = UserName;
277         this.UserName = name;
278         initPropertyChangeSupport();
279         propertySupport.firePropertyChange ("UserName", prev, UserName);//NOI18N
280     }
281
282     public String getResType() {
283         return ResType;
284     }
285     public void setResType(java.lang.String type) {
286         String prev = ResType;
287         this.ResType = type;
288         initPropertyChangeSupport();
289         propertySupport.firePropertyChange ("ResType", prev, ResType);//NOI18N
290     }
291     
292     public ResPool getResPoolProperties() {
293         return resPoolProperties;
294     }
295     public void setResPoolProperties(ResPool resPool) {
296 // String prev = ResType;
297         this.resPoolProperties = resPool;
298 // initPropertyChangeSupport();
299 // propertySupport.firePropertyChange ("ResType", prev, ResType);//NOI18N
300     }
301 */

302     /*
303     public static DSDescriptor getDSDesc(DSBean bn){
304        
305         DSDescriptor newdesc = new DSDescriptor();
306         newdesc.setDatabase(bn.getDatabase());
307         newdesc.setDatabase_url(bn.getDatabaseURL());
308         //newdesc.setResource_mgr(bn.getDatabaseURL());
309         newdesc.setDatasource(bn.getDataSource());
310         newdesc.setUsername(bn.getUserName());
311         newdesc.setPassword(bn.getPassword());
312         newdesc.setJndi_name("jdbc/"+newdesc.getDatasource());//NOI18N
313         try {
314             newdesc.setDriver_type(bn.getDriver());
315         }
316         catch (Exception ex) {
317             // this should not happen. If it does, we still need to send something back up
318             // the stack.
319             throw new RuntimeException("Driver_type is incorrect. Should not happen.");//NOI18N
320         }
321         return newdesc;
322     }
323     
324     public static void filename(DSBean bn){
325         TempDirManager tmp = new TempDirManager();
326         String pathname = tmp.getDirName();
327         //System.out.println("pathname" + pathname); //NOI18N
328         //File test = new File("c:\\temp\\");
329         //String pathname = test.getAbsolutePath();
330         String ds_name = bn.getDataSource() + ".xml";//NOI18N
331         filename = pathname + java.io.File.separator + ds_name;
332     }
333     */

334     private boolean DataSourceName(String JavaDoc value, List JavaDoc pm1){
335       boolean exists = false;
336       //IasGlobalOptionsSettings val1 = new IasGlobalOptionsSettings();
337
//List pm1 = com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings.DEFAULT.getDataSources();
338
//List pm1 = val1.getDataSources();
339
for(int i=0; i<pm1.size(); i++){
340         //IDSBean instance = val1.getDSInstance(i);
341
//IDSBean instance = com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings.DEFAULT.getDSInstance(i);
342
IDSBean instance = (IDSBean) pm1.get(i);
343         String JavaDoc inst = instance.getName();
344         if(inst.equals(value))
345            exists = true;
346       }//for
347
return exists;
348     }
349     
350 }
351
352
Popular Tags