KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MailResource.java
26  *
27  * Created on March 14, 2002, 12:23 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.io.File JavaDoc;
37 import java.util.Vector JavaDoc;
38 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
39
40 public class MailResource extends Object JavaDoc implements java.io.Serializable JavaDoc {
41   
42     private String JavaDoc name;
43     private String JavaDoc Description;
44     private String JavaDoc JndiName;
45     private String JavaDoc StoreProtocol;
46     private String JavaDoc StoreProtocolClass;
47     private String JavaDoc TransportProtocol;
48     private String JavaDoc TransportProtocolClass;
49     private String JavaDoc Host;
50 // private String LogLevel;
51
private String JavaDoc Enabled;
52     private NameValuePair[] extParams = new NameValuePair[0];
53     
54     private String JavaDoc User;
55     private String JavaDoc From;
56     private String JavaDoc Debug;
57     
58     transient protected PropertyChangeSupport propertySupport;
59
60     public MailResource(List JavaDoc resources) {
61         propertySupport = new PropertyChangeSupport ( this );
62         JndiName = "mail/jndiname"; // NOI18N
63
Description = ""; // NOI18N
64
StoreProtocol = "imap";//NOI18N
65
StoreProtocolClass = "com.sun.mail.imap.IMAPStore";//NOI18N
66
TransportProtocol = "smtp";//NOI18N
67
TransportProtocolClass = "com.sun.mail.smtp.SMTPTransport";//NOI18N
68
Host = "Mail Host"; // NOI18N
69
// LogLevel = "ERROR";
70
Enabled = "true"; // NOI18N
71
// extParams = new Vector();
72

73         User = "User Name"; // NOI18N
74
From = "User Email Address"; // NOI18N
75
Debug = "false"; // NOI18N
76

77         String JavaDoc resName = "MailResource"; // NOI18N
78
String JavaDoc t_name = null;
79         if(resources.size() != 0){
80            int num = resources.size()+1;
81            t_name = resName + "_" + num;//NOI18N
82
boolean resource_exists = FactoryName(t_name, resources);
83            while(resource_exists){
84              num++;
85              t_name = resName + "_" + num;//NOI18N
86
resource_exists = FactoryName(t_name, resources);
87            }
88         }else{
89           t_name = resName + "_1";//NOI18N
90
}
91         name = t_name;
92     }
93     
94    public boolean FactoryName(String JavaDoc value, List JavaDoc resources){
95       boolean exists = false;
96       for(int i=0; i<resources.size(); i++){
97         IMailResource instance = (IMailResource) resources.get(i);
98         String JavaDoc inst = instance.getName();
99         if(inst.equals(value))
100            exists = true;
101       }//for
102
return exists;
103     }
104    
105     public String JavaDoc getJndiName() {
106         return JndiName;
107     }
108
109     public void setJndiName(String JavaDoc value) {
110         String JavaDoc oldValue = JndiName;
111         this.JndiName = value;
112         initPropertyChangeSupport();
113         propertySupport.firePropertyChange ("JndiName", oldValue, JndiName);//NOI18N
114
setName(JndiName);
115     }
116     
117     public void simpleSetJndiName(String JavaDoc value) {
118         this.JndiName = value;
119         setName(JndiName);
120     }
121     
122     public String JavaDoc getDescription() {
123         return Description;
124     }
125
126     public void setDescription(String JavaDoc value) {
127         String JavaDoc oldValue = Description;
128         this.Description = value;
129         initPropertyChangeSupport();
130         propertySupport.firePropertyChange ("Description", oldValue, Description);//NOI18N
131
}
132     
133     public String JavaDoc getStoreProtocol() {
134         return StoreProtocol;
135     }
136
137     public void setStoreProtocol(String JavaDoc value) {
138         String JavaDoc oldValue = StoreProtocol;
139         this.StoreProtocol = value;
140         initPropertyChangeSupport();
141         propertySupport.firePropertyChange ("StoreProtocol", oldValue, StoreProtocol);//NOI18N
142
}
143     
144     public String JavaDoc getStoreProtocolClass() {
145         return StoreProtocolClass;
146     }
147
148     public void setStoreProtocolClass(String JavaDoc value) {
149         String JavaDoc oldValue = StoreProtocolClass;
150         this.StoreProtocolClass = value;
151         initPropertyChangeSupport();
152         propertySupport.firePropertyChange ("StoreProtocolClass", oldValue, StoreProtocolClass);//NOI18N
153
}
154         
155     public String JavaDoc getTransportProtocol() {
156         return TransportProtocol;
157     }
158
159     public void setTransportProtocol(String JavaDoc value) {
160         String JavaDoc oldValue = TransportProtocol;
161         this.TransportProtocol = value;
162         initPropertyChangeSupport();
163         propertySupport.firePropertyChange ("TransportProtocol", oldValue, TransportProtocol);//NOI18N
164
}
165     
166     public String JavaDoc getTransportProtocolClass() {
167         return TransportProtocolClass;
168     }
169
170     public void setTransportProtocolClass(String JavaDoc value) {
171         String JavaDoc oldValue = TransportProtocolClass;
172         this.TransportProtocolClass = value;
173         initPropertyChangeSupport();
174         propertySupport.firePropertyChange ("TransportProtocolClass", oldValue, TransportProtocolClass);//NOI18N
175
}
176             
177     public String JavaDoc getHost() {
178         return Host;
179     }
180
181     public void setHost(String JavaDoc value) {
182         String JavaDoc oldValue = Host;
183         this.Host = value;
184         initPropertyChangeSupport();
185         propertySupport.firePropertyChange ("Host", oldValue, Host);//NOI18N
186
}
187  
188     public String JavaDoc getEnabled() {
189         return Enabled;
190     }
191
192     public void setEnabled(String JavaDoc value) {
193         String JavaDoc oldValue = Enabled;
194         this.Enabled = value;
195         initPropertyChangeSupport();
196         propertySupport.firePropertyChange ("Enabled", oldValue, Enabled);//NOI18N
197
}
198  
199     public String JavaDoc getUser() {
200         return User;
201     }
202
203     public void setUser(String JavaDoc value) {
204         String JavaDoc oldValue = User;
205         this.User = value;
206         initPropertyChangeSupport();
207         propertySupport.firePropertyChange ("User", oldValue, User);//NOI18N
208
}
209     
210     public String JavaDoc getFrom() {
211         return From;
212     }
213
214     public void setFrom(String JavaDoc value) {
215         String JavaDoc oldValue = From;
216         this.From = value;
217         initPropertyChangeSupport();
218         propertySupport.firePropertyChange ("From", oldValue, From);//NOI18N
219
}
220     
221     public String JavaDoc getDebug() {
222         return Debug;
223     }
224
225     public void setDebug(String JavaDoc value) {
226         String JavaDoc oldValue = Debug;
227         this.Debug = value;
228         initPropertyChangeSupport();
229         propertySupport.firePropertyChange ("Debug", oldValue, Debug);//NOI18N
230
}
231     
232     private void initPropertyChangeSupport(){
233          if(propertySupport==null)
234          propertySupport = new PropertyChangeSupport ( this );
235
236     }
237     
238     public void addPropertyChangeListener (PropertyChangeListener listener) {
239         initPropertyChangeSupport();
240         propertySupport.addPropertyChangeListener (listener);
241     }
242
243     public void removePropertyChangeListener (PropertyChangeListener listener) {
244         initPropertyChangeSupport();
245         propertySupport.removePropertyChangeListener (listener);
246     }
247
248     public String JavaDoc getName() {
249         return name;
250     }
251     
252     public void setName(String JavaDoc value) {
253         String JavaDoc oldValue = name;
254         this.name = value;
255         initPropertyChangeSupport();
256         propertySupport.firePropertyChange ("name", oldValue, name);//NOI18N
257
}
258     
259     public NameValuePair[] getExtParams() {
260         return extParams;
261     }
262
263     public void setExtParams(Object JavaDoc[] value) {
264         Reporter.info(new Integer JavaDoc(value.length)); //NOI18N
265
NameValuePair[] pairs = new NameValuePair[value.length];
266         for (int i = 0; i < value.length; i++) {
267             NameValuePair val = (NameValuePair)value[i];
268             NameValuePair pair = new NameValuePair();
269             pair.setParamName(val.getParamName());
270             pair.setParamValue(val.getParamValue());
271             pair.setParamDescription(val.getParamDescription());
272             Reporter.info(pair.getParamName() + " " + pair.getParamValue()); //NOI18N
273
pairs[i] = pair;
274         }
275         NameValuePair[] oldValue = extParams;
276         this.extParams = pairs;
277         initPropertyChangeSupport();
278         propertySupport.firePropertyChange ("extParams", oldValue, extParams);//NOI18N
279
}
280     
281     public String JavaDoc toString() {
282         return "name: " + getName() + ", Description: " + getDescription() + ", JndiName: " + // NOI18N
283
getJndiName() + ", Store Protocol: " + getStoreProtocol() + // NOI18N
284
", Store Protocol Class: " + getStoreProtocolClass() + // NOI18N
285
", Transport Protocol: " + getTransportProtocol() + // NOI18N
286
", Transport Protocol Class: " + getTransportProtocolClass() + ", Host: " + // NOI18N
287
getHost() + ", User: " + getUser() + ", From: " + getFrom() + // NOI18N
288
", Debug: " + getDebug() + ", Enabled: " + getEnabled(); // NOI18N
289
}
290 }
291
Popular Tags