KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * PersistenceManager.java
26  *
27  * Created on January 15, 2002, 12:15 PM
28  *
29  * Author: Shirley Chiang
30  */

31
32 package com.sun.enterprise.tools.common.deploy;
33
34 import java.beans.*;
35 import java.util.List JavaDoc;
36 import java.net.InetAddress JavaDoc;
37 import java.io.File JavaDoc;
38 import java.util.Vector JavaDoc;
39 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
40
41 //import com.netscape.server.deployment.PMFDescriptor;
42
import com.sun.enterprise.tools.common.deploy.IPMFactory;
43
44 public class PersistenceManager extends Object JavaDoc implements java.io.Serializable JavaDoc {
45   
46     private String JavaDoc name;
47     private String JavaDoc Description;
48     private String JavaDoc JndiName;
49 // private String ResType;
50
private String JavaDoc FactoryClassName;
51 // private String LogLevel;
52
private String JavaDoc Enabled;
53     private NameValuePair[] extParams = new NameValuePair[0];
54     
55     private String JavaDoc DataSourceName;
56 /*
57     private String IgnoreCache;
58     private String NonTXRead;
59     private String NonTXWrite;
60     private String Optimistic;
61     private String RetainValue;
62 */

63     transient protected PropertyChangeSupport propertySupport;
64
65     public PersistenceManager(List JavaDoc resources) {
66         propertySupport = new PropertyChangeSupport ( this );
67         //JndiName = "pmf/";//NOI18N
68
JndiName = "jdo/";//NOI18N
69
Description = ""; // NOI18N
70
// ResType = "javax.sql.DataSource";//NOI18N
71
FactoryClassName = "com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl";//NOI18N
72
// LogLevel = "ERROR";
73
Enabled = "true"; // NOI18N
74
// extParams = new Vector();
75

76         DataSourceName = "jdbc/";//NOI18N
77
/*
78         IgnoreCache = "false";//NOI18N
79         NonTXRead = "false";//NOI18N
80         NonTXWrite = "false";//NOI18N
81         Optimistic = "false";//NOI18N
82         RetainValue = "false";//NOI18N
83 */

84         String JavaDoc resName = "PersistenceManager"; // NOI18N
85
String JavaDoc t_name = null;
86         if(resources.size() != 0){
87            int num = resources.size()+1;
88            t_name = resName + "_" + num;//NOI18N
89
boolean resource_exists = FactoryName(t_name, resources);
90            while(resource_exists){
91              num++;
92              t_name = resName + "_" + num;//NOI18N
93
resource_exists = FactoryName(t_name, resources);
94            }
95         }else{
96           t_name = resName + "_1";//NOI18N
97
}
98         name = t_name;
99     }
100     
101    public boolean FactoryName(String JavaDoc value, List JavaDoc resources){
102       boolean exists = false;
103       for(int i=0; i<resources.size(); i++){
104         IPMFactory instance = (IPMFactory) resources.get(i);
105         String JavaDoc inst = instance.getName();
106         if(inst.equals(value))
107            exists = true;
108       }//for
109
return exists;
110     }
111    
112     public String JavaDoc getJndiName() {
113         return JndiName;
114     }
115
116     public void setJndiName(String JavaDoc value) {
117         String JavaDoc oldValue = JndiName;
118         this.JndiName = value;
119         initPropertyChangeSupport();
120         propertySupport.firePropertyChange ("JndiName", oldValue, JndiName);//NOI18N
121
setName(JndiName);
122     }
123     
124     public void simpleSetJndiName(String JavaDoc value) {
125         this.JndiName = value;
126         setName(JndiName);
127     }
128     
129     public String JavaDoc getDescription() {
130         return Description;
131     }
132
133     public void setDescription(String JavaDoc value) {
134         String JavaDoc oldValue = Description;
135         this.Description = value;
136         initPropertyChangeSupport();
137         propertySupport.firePropertyChange ("Description", oldValue, Description);//NOI18N
138
}
139 /*
140     public String getResType() {
141         return ResType;
142     }
143
144     public void setResType(String value) {
145         String oldValue = ResType;
146         this.ResType = value;
147         initPropertyChangeSupport();
148         propertySupport.firePropertyChange ("ResType", oldValue, ResType);//NOI18N
149     }
150 */

151     public String JavaDoc getFactoryClassName() {
152         return FactoryClassName;
153     }
154
155     public void setFactoryClassName(String JavaDoc value) {
156         String JavaDoc oldValue = FactoryClassName;
157         this.FactoryClassName = value;
158         initPropertyChangeSupport();
159         propertySupport.firePropertyChange ("FactoryClassName", oldValue, FactoryClassName);//NOI18N
160
}
161  
162 /*
163     public String getLogLevel() {
164         return LogLevel;
165     }
166
167     public void setLogLevel(String value) {
168         String oldValue = LogLevel;
169         this.LogLevel = value;
170         initPropertyChangeSupport();
171         propertySupport.firePropertyChange ("LogLevel", oldValue, LogLevel);//NOI18N
172     }
173 */

174     
175     public String JavaDoc getEnabled() {
176         return Enabled;
177     }
178
179     public void setEnabled(String JavaDoc value) {
180         String JavaDoc oldValue = Enabled;
181         this.Enabled = value;
182         initPropertyChangeSupport();
183         propertySupport.firePropertyChange ("Enabled", oldValue, Enabled);//NOI18N
184
}
185  
186  /*
187     public Vector getExtParams() {
188         return extParams;
189     }
190
191     public void setExtParams(Vector value) {
192         Vector oldValue = extParams;
193         this.extParams = value;
194         initPropertyChangeSupport();
195         propertySupport.firePropertyChange ("extParams", oldValue, extParams);//NOI18N
196     }
197  */

198     
199     public String JavaDoc getDataSourceName() {
200         return DataSourceName;
201     }
202
203     public void setDataSourceName(String JavaDoc value) {
204         String JavaDoc oldValue = DataSourceName;
205         this.DataSourceName = value;
206         initPropertyChangeSupport();
207         propertySupport.firePropertyChange ("DataSourceName", oldValue, DataSourceName);//NOI18N
208
}
209 /*
210     public String getIgnoreCache() {
211         return IgnoreCache;
212     }
213
214     public void setIgnoreCache(String value) {
215         String oldValue = IgnoreCache;
216         this.IgnoreCache = value;
217         initPropertyChangeSupport();
218         propertySupport.firePropertyChange ("IgnoreCache", oldValue, IgnoreCache);//NOI18N
219     }
220     
221     public String getNonTXRead() {
222         return NonTXRead;
223     }
224
225     public void setNonTXRead(String value) {
226         String oldValue = NonTXRead;
227         this.NonTXRead = value;
228         initPropertyChangeSupport();
229         propertySupport.firePropertyChange ("NonTXRead", oldValue, NonTXRead);//NOI18N
230     }
231     
232     public String getNonTXWrite() {
233         return NonTXWrite;
234     }
235
236     public void setNonTXWrite(String value) {
237         String oldValue = NonTXWrite;
238         this.NonTXWrite = value;
239         initPropertyChangeSupport();
240         propertySupport.firePropertyChange ("NonTXWrite", oldValue, NonTXWrite);//NOI18N
241     }
242     
243     public String getOptimistic() {
244         return Optimistic;
245     }
246
247     public void setOptimistic(String value) {
248         String oldValue = Optimistic;
249         this.Optimistic = value;
250         initPropertyChangeSupport();
251         propertySupport.firePropertyChange ("Optimistic", oldValue, Optimistic);//NOI18N
252     }
253     
254     public String getRetainValue() {
255         return RetainValue;
256     }
257
258     public void setRetainValue(String value) {
259         String oldValue = RetainValue;
260         this.RetainValue = value;
261         initPropertyChangeSupport();
262         propertySupport.firePropertyChange ("RetainValue", oldValue, RetainValue);//NOI18N
263     }
264 */

265     private void initPropertyChangeSupport(){
266          if(propertySupport==null)
267          propertySupport = new PropertyChangeSupport ( this );
268
269     }
270     
271     public void addPropertyChangeListener (PropertyChangeListener listener) {
272         initPropertyChangeSupport();
273         propertySupport.addPropertyChangeListener (listener);
274     }
275
276     public void removePropertyChangeListener (PropertyChangeListener listener) {
277         initPropertyChangeSupport();
278         propertySupport.removePropertyChangeListener (listener);
279     }
280
281     public String JavaDoc getName() {
282         return name;
283     }
284     
285     public void setName(String JavaDoc value) {
286         String JavaDoc oldValue = name;
287         this.name = value;
288         initPropertyChangeSupport();
289         propertySupport.firePropertyChange ("name", oldValue, name);//NOI18N
290
}
291     
292     public NameValuePair[] getExtParams() {
293         return extParams;
294     }
295
296     public void setExtParams(Object JavaDoc[] value) {
297         Reporter.info(new Integer JavaDoc(value.length)); //NOI18N
298
NameValuePair[] pairs = new NameValuePair[value.length];
299         for (int i = 0; i < value.length; i++) {
300             NameValuePair val = (NameValuePair)value[i];
301             NameValuePair pair = new NameValuePair();
302             pair.setParamName(val.getParamName());
303             pair.setParamValue(val.getParamValue());
304             pair.setParamDescription(val.getParamDescription());
305             Reporter.info(pair.getParamName() + " " + pair.getParamValue() + " " + pair.getParamDescription()); //NOI18N
306
pairs[i] = pair;
307         }
308         NameValuePair[] oldValue = extParams;
309         this.extParams = pairs;
310         initPropertyChangeSupport();
311         propertySupport.firePropertyChange ("extParams", oldValue, extParams);//NOI18N
312
}
313     public String JavaDoc toString() {
314         return "name: " + getName() + ", Description: " + getDescription() + ", JndiName: " + // NOI18N
315
getJndiName() + ", FactoryClassName: " + // NOI18N
316
getFactoryClassName() + ", Enabled: " + getEnabled(); // NOI18N
317
}
318 }
319
Popular Tags