KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > 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  * This generated bean class MailResource matches the DTD element mail-resource
26  *
27  */

28
29 package com.sun.enterprise.config.serverbeans;
30
31 import org.w3c.dom.*;
32 import org.netbeans.modules.schema2beans.*;
33 import java.beans.*;
34 import java.util.*;
35 import java.io.Serializable JavaDoc;
36 import com.sun.enterprise.config.ConfigBean;
37 import com.sun.enterprise.config.ConfigException;
38 import com.sun.enterprise.config.StaleWriteConfigException;
39 import com.sun.enterprise.util.i18n.StringManager;
40
41 // BEGIN_NOI18N
42

43 public class MailResource extends ConfigBean implements Serializable JavaDoc
44 {
45
46     static Vector comparators = new Vector();
47     private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0);
48
49     static public final String JavaDoc DESCRIPTION = "Description";
50     static public final String JavaDoc ELEMENT_PROPERTY = "ElementProperty";
51
52     public MailResource() {
53         this(Common.USE_DEFAULT_VALUES);
54     }
55
56     public MailResource(int options)
57     {
58         super(comparators, runtimeVersion);
59         // Properties (see root bean comments for the bean graph)
60
initPropertyTables(2);
61         this.createProperty("description", DESCRIPTION,
62             Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY,
63             String JavaDoc.class);
64         this.createProperty("property", ELEMENT_PROPERTY,
65             Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
66             ElementProperty.class);
67         this.createAttribute(ELEMENT_PROPERTY, "name", "Name",
68                         AttrProp.CDATA | AttrProp.REQUIRED,
69                         null, null);
70         this.createAttribute(ELEMENT_PROPERTY, "value", "Value",
71                         AttrProp.CDATA | AttrProp.REQUIRED,
72                         null, null);
73         this.initialize(options);
74     }
75
76     // Setting the default values of the properties
77
void initialize(int options) {
78
79     }
80
81     /**
82     * Return the Description of the Element mail-resource
83     */

84     public String JavaDoc getDescription() {
85         return (String JavaDoc) getValue(ServerTags.DESCRIPTION);
86     }
87     /**
88     * Modify the Description of the Element mail-resource
89     * @param v the new value
90     */

91     public void setDescription(String JavaDoc v){
92         setValue(ServerTags.DESCRIPTION, (null != v ? v.trim() : null));
93         }
94     // This attribute is an array, possibly empty
95
public void setElementProperty(int index, ElementProperty value) {
96         this.setValue(ELEMENT_PROPERTY, index, value);
97     }
98
99     // Get Method
100
public ElementProperty getElementProperty(int index) {
101         return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index);
102     }
103
104     // This attribute is an array, possibly empty
105
public void setElementProperty(ElementProperty[] value) {
106         this.setValue(ELEMENT_PROPERTY, value);
107     }
108
109     // Getter Method
110
public ElementProperty[] getElementProperty() {
111         return (ElementProperty[])this.getValues(ELEMENT_PROPERTY);
112     }
113
114     // Return the number of properties
115
public int sizeElementProperty() {
116         return this.size(ELEMENT_PROPERTY);
117     }
118
119     // Add a new element returning its index in the list
120
public int addElementProperty(ElementProperty value)
121             throws ConfigException{
122         return addElementProperty(value, true);
123     }
124
125     // Add a new element returning its index in the list with a boolean flag
126
public int addElementProperty(ElementProperty value, boolean overwrite)
127             throws ConfigException{
128         ElementProperty old = getElementPropertyByName(value.getName());
129         if(old != null) {
130             throw new ConfigException(StringManager.getManager(MailResource.class).getString("cannotAddDuplicate", "ElementProperty"));
131         }
132         return this.addValue(ELEMENT_PROPERTY, value, overwrite);
133     }
134
135     //
136
// Remove an element using its reference
137
// Returns the index the element had in the list
138
//
139
public int removeElementProperty(ElementProperty value){
140         return this.removeValue(ELEMENT_PROPERTY, value);
141     }
142
143     //
144
// Remove an element using its reference
145
// Returns the index the element had in the list
146
// with boolean overwrite
147
//
148
public int removeElementProperty(ElementProperty value, boolean overwrite)
149             throws StaleWriteConfigException{
150         return this.removeValue(ELEMENT_PROPERTY, value, overwrite);
151     }
152
153     public ElementProperty getElementPropertyByName(String JavaDoc id) {
154      if (null != id) { id = id.trim(); }
155     ElementProperty[] o = getElementProperty();
156      if (o == null) return null;
157
158      for (int i=0; i < o.length; i++) {
159          if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) {
160              return o[i];
161          }
162      }
163
164         return null;
165         
166     }
167     /**
168     * Getter for JndiName of the Element mail-resource
169     * @return the JndiName of the Element mail-resource
170     */

171     public String JavaDoc getJndiName() {
172         return getAttributeValue(ServerTags.JNDI_NAME);
173     }
174     /**
175     * Modify the JndiName of the Element mail-resource
176     * @param v the new value
177     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
178     */

179     public void setJndiName(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
180         setAttributeValue(ServerTags.JNDI_NAME, v, overwrite);
181     }
182     /**
183     * Modify the JndiName of the Element mail-resource
184     * @param v the new value
185     */

186     public void setJndiName(String JavaDoc v) {
187         setAttributeValue(ServerTags.JNDI_NAME, v);
188     }
189     /**
190     * Getter for StoreProtocol of the Element mail-resource
191     * @return the StoreProtocol of the Element mail-resource
192     */

193     public String JavaDoc getStoreProtocol() {
194         return getAttributeValue(ServerTags.STORE_PROTOCOL);
195     }
196     /**
197     * Modify the StoreProtocol of the Element mail-resource
198     * @param v the new value
199     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
200     */

201     public void setStoreProtocol(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
202         setAttributeValue(ServerTags.STORE_PROTOCOL, v, overwrite);
203     }
204     /**
205     * Modify the StoreProtocol of the Element mail-resource
206     * @param v the new value
207     */

208     public void setStoreProtocol(String JavaDoc v) {
209         setAttributeValue(ServerTags.STORE_PROTOCOL, v);
210     }
211     /**
212     * Get the default value of StoreProtocol from dtd
213     */

214     public static String JavaDoc getDefaultStoreProtocol() {
215         return "imap".trim();
216     }
217     /**
218     * Getter for StoreProtocolClass of the Element mail-resource
219     * @return the StoreProtocolClass of the Element mail-resource
220     */

221     public String JavaDoc getStoreProtocolClass() {
222         return getAttributeValue(ServerTags.STORE_PROTOCOL_CLASS);
223     }
224     /**
225     * Modify the StoreProtocolClass of the Element mail-resource
226     * @param v the new value
227     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
228     */

229     public void setStoreProtocolClass(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
230         setAttributeValue(ServerTags.STORE_PROTOCOL_CLASS, v, overwrite);
231     }
232     /**
233     * Modify the StoreProtocolClass of the Element mail-resource
234     * @param v the new value
235     */

236     public void setStoreProtocolClass(String JavaDoc v) {
237         setAttributeValue(ServerTags.STORE_PROTOCOL_CLASS, v);
238     }
239     /**
240     * Get the default value of StoreProtocolClass from dtd
241     */

242     public static String JavaDoc getDefaultStoreProtocolClass() {
243         return "com.sun.mail.imap.IMAPStore".trim();
244     }
245     /**
246     * Getter for TransportProtocol of the Element mail-resource
247     * @return the TransportProtocol of the Element mail-resource
248     */

249     public String JavaDoc getTransportProtocol() {
250         return getAttributeValue(ServerTags.TRANSPORT_PROTOCOL);
251     }
252     /**
253     * Modify the TransportProtocol of the Element mail-resource
254     * @param v the new value
255     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
256     */

257     public void setTransportProtocol(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
258         setAttributeValue(ServerTags.TRANSPORT_PROTOCOL, v, overwrite);
259     }
260     /**
261     * Modify the TransportProtocol of the Element mail-resource
262     * @param v the new value
263     */

264     public void setTransportProtocol(String JavaDoc v) {
265         setAttributeValue(ServerTags.TRANSPORT_PROTOCOL, v);
266     }
267     /**
268     * Get the default value of TransportProtocol from dtd
269     */

270     public static String JavaDoc getDefaultTransportProtocol() {
271         return "smtp".trim();
272     }
273     /**
274     * Getter for TransportProtocolClass of the Element mail-resource
275     * @return the TransportProtocolClass of the Element mail-resource
276     */

277     public String JavaDoc getTransportProtocolClass() {
278         return getAttributeValue(ServerTags.TRANSPORT_PROTOCOL_CLASS);
279     }
280     /**
281     * Modify the TransportProtocolClass of the Element mail-resource
282     * @param v the new value
283     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
284     */

285     public void setTransportProtocolClass(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
286         setAttributeValue(ServerTags.TRANSPORT_PROTOCOL_CLASS, v, overwrite);
287     }
288     /**
289     * Modify the TransportProtocolClass of the Element mail-resource
290     * @param v the new value
291     */

292     public void setTransportProtocolClass(String JavaDoc v) {
293         setAttributeValue(ServerTags.TRANSPORT_PROTOCOL_CLASS, v);
294     }
295     /**
296     * Get the default value of TransportProtocolClass from dtd
297     */

298     public static String JavaDoc getDefaultTransportProtocolClass() {
299         return "com.sun.mail.smtp.SMTPTransport".trim();
300     }
301     /**
302     * Getter for Host of the Element mail-resource
303     * @return the Host of the Element mail-resource
304     */

305     public String JavaDoc getHost() {
306         return getAttributeValue(ServerTags.HOST);
307     }
308     /**
309     * Modify the Host of the Element mail-resource
310     * @param v the new value
311     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
312     */

313     public void setHost(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
314         setAttributeValue(ServerTags.HOST, v, overwrite);
315     }
316     /**
317     * Modify the Host of the Element mail-resource
318     * @param v the new value
319     */

320     public void setHost(String JavaDoc v) {
321         setAttributeValue(ServerTags.HOST, v);
322     }
323     /**
324     * Getter for User of the Element mail-resource
325     * @return the User of the Element mail-resource
326     */

327     public String JavaDoc getUser() {
328         return getAttributeValue(ServerTags.USER);
329     }
330     /**
331     * Modify the User of the Element mail-resource
332     * @param v the new value
333     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
334     */

335     public void setUser(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
336         setAttributeValue(ServerTags.USER, v, overwrite);
337     }
338     /**
339     * Modify the User of the Element mail-resource
340     * @param v the new value
341     */

342     public void setUser(String JavaDoc v) {
343         setAttributeValue(ServerTags.USER, v);
344     }
345     /**
346     * Getter for From of the Element mail-resource
347     * @return the From of the Element mail-resource
348     */

349     public String JavaDoc getFrom() {
350         return getAttributeValue(ServerTags.FROM);
351     }
352     /**
353     * Modify the From of the Element mail-resource
354     * @param v the new value
355     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
356     */

357     public void setFrom(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
358         setAttributeValue(ServerTags.FROM, v, overwrite);
359     }
360     /**
361     * Modify the From of the Element mail-resource
362     * @param v the new value
363     */

364     public void setFrom(String JavaDoc v) {
365         setAttributeValue(ServerTags.FROM, v);
366     }
367     /**
368     * Getter for Debug of the Element mail-resource
369     * @return the Debug of the Element mail-resource
370     */

371     public boolean isDebug() {
372         return toBoolean(getAttributeValue(ServerTags.DEBUG));
373     }
374     /**
375     * Modify the Debug of the Element mail-resource
376     * @param v the new value
377     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
378     */

379     public void setDebug(boolean v, boolean overwrite) throws StaleWriteConfigException {
380         setAttributeValue(ServerTags.DEBUG, ""+(v==true), overwrite);
381     }
382     /**
383     * Modify the Debug of the Element mail-resource
384     * @param v the new value
385     */

386     public void setDebug(boolean v) {
387         setAttributeValue(ServerTags.DEBUG, ""+(v==true));
388     }
389     /**
390     * Get the default value of Debug from dtd
391     */

392     public static String JavaDoc getDefaultDebug() {
393         return "false".trim();
394     }
395     /**
396     * Getter for ObjectType of the Element mail-resource
397     * @return the ObjectType of the Element mail-resource
398     */

399     public String JavaDoc getObjectType() {
400         return getAttributeValue(ServerTags.OBJECT_TYPE);
401     }
402     /**
403     * Modify the ObjectType of the Element mail-resource
404     * @param v the new value
405     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
406     */

407     public void setObjectType(String JavaDoc v, boolean overwrite) throws StaleWriteConfigException {
408         setAttributeValue(ServerTags.OBJECT_TYPE, v, overwrite);
409     }
410     /**
411     * Modify the ObjectType of the Element mail-resource
412     * @param v the new value
413     */

414     public void setObjectType(String JavaDoc v) {
415         setAttributeValue(ServerTags.OBJECT_TYPE, v);
416     }
417     /**
418     * Get the default value of ObjectType from dtd
419     */

420     public static String JavaDoc getDefaultObjectType() {
421         return "user".trim();
422     }
423     /**
424     * Getter for Enabled of the Element mail-resource
425     * @return the Enabled of the Element mail-resource
426     */

427     public boolean isEnabled() {
428         return toBoolean(getAttributeValue(ServerTags.ENABLED));
429     }
430     /**
431     * Modify the Enabled of the Element mail-resource
432     * @param v the new value
433     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
434     */

435     public void setEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException {
436         setAttributeValue(ServerTags.ENABLED, ""+(v==true), overwrite);
437     }
438     /**
439     * Modify the Enabled of the Element mail-resource
440     * @param v the new value
441     */

442     public void setEnabled(boolean v) {
443         setAttributeValue(ServerTags.ENABLED, ""+(v==true));
444     }
445     /**
446     * Get the default value of Enabled from dtd
447     */

448     public static String JavaDoc getDefaultEnabled() {
449         return "true".trim();
450     }
451     /**
452      * Create a new bean using it's default constructor.
453      * This does not add it to any bean graph.
454      */

455     public ElementProperty newElementProperty() {
456         return new ElementProperty();
457     }
458
459     /**
460     * get the xpath representation for this element
461     * returns something like abc[@name='value'] or abc
462     * depending on the type of the bean
463     */

464     protected String JavaDoc getRelativeXPath() {
465         String JavaDoc ret = null;
466         ret = "mail-resource" + (canHaveSiblings() ? "[@jndi-name='" + getAttributeValue("jndi-name") +"']" : "") ;
467         return (null != ret ? ret.trim() : null);
468     }
469
470     /*
471     * generic method to get default value from dtd
472     */

473     public static String JavaDoc getDefaultAttributeValue(String JavaDoc attr) {
474         if(attr == null) return null;
475         attr = attr.trim();
476         if(attr.equals(ServerTags.STORE_PROTOCOL)) return "imap".trim();
477         if(attr.equals(ServerTags.STORE_PROTOCOL_CLASS)) return "com.sun.mail.imap.IMAPStore".trim();
478         if(attr.equals(ServerTags.TRANSPORT_PROTOCOL)) return "smtp".trim();
479         if(attr.equals(ServerTags.TRANSPORT_PROTOCOL_CLASS)) return "com.sun.mail.smtp.SMTPTransport".trim();
480         if(attr.equals(ServerTags.DEBUG)) return "false".trim();
481         if(attr.equals(ServerTags.OBJECT_TYPE)) return "user".trim();
482         if(attr.equals(ServerTags.ENABLED)) return "true".trim();
483     return null;
484     }
485     //
486
public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
487         comparators.add(c);
488     }
489
490     //
491
public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
492         comparators.remove(c);
493     }
494     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
495     }
496
497     // Dump the content of this bean returning it as a String
498
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
499         String JavaDoc s;
500         Object JavaDoc o;
501         org.netbeans.modules.schema2beans.BaseBean n;
502         str.append(indent);
503         str.append("Description"); // NOI18N
504
str.append(indent+"\t"); // NOI18N
505
str.append("<"); // NOI18N
506
o = this.getDescription();
507         str.append((o==null?"null":o.toString().trim())); // NOI18N
508
str.append(">\n"); // NOI18N
509
this.dumpAttributes(DESCRIPTION, 0, str, indent);
510
511         str.append(indent);
512         str.append("ElementProperty["+this.sizeElementProperty()+"]"); // NOI18N
513
for(int i=0; i<this.sizeElementProperty(); i++)
514         {
515             str.append(indent+"\t");
516             str.append("#"+i+":");
517             n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i);
518             if (n != null)
519                 n.dump(str, indent + "\t"); // NOI18N
520
else
521                 str.append(indent+"\tnull"); // NOI18N
522
this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent);
523         }
524
525     }
526     public String JavaDoc dumpBeanNode(){
527         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
528         str.append("MailResource\n"); // NOI18N
529
this.dump(str, "\n "); // NOI18N
530
return str.toString();
531     }}
532
533 // END_NOI18N
534

535
Popular Tags