KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > beans > JavaMailSessionBean


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  * JavaMailSessionBean.java
21  *
22  * Created on September 17, 2003, 2:50 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.beans;
26
27 import java.util.Vector JavaDoc;
28 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
29 import org.netbeans.modules.j2ee.sun.share.serverresources.MailSessionResource;
30 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
31 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.*;
32
33 /**
34  *
35  * @author nityad
36  */

37 public class JavaMailSessionBean extends MailSessionResource implements java.io.Serializable JavaDoc {
38     
39     /** Creates a new instance of JavaMailSessionBean */
40     public JavaMailSessionBean() {
41     }
42     
43     public String JavaDoc getName() {
44         return super.getName();
45     }
46     
47     public String JavaDoc getJndiName(){
48         return super.getJndiName();
49     }
50     
51     public static JavaMailSessionBean createBean(MailResource mailresource) {
52         JavaMailSessionBean bean = new JavaMailSessionBean();
53         //name attribute in bean is for studio display purpose.
54
//It is not part of the mail-resource dtd.
55
bean.setName(mailresource.getJndiName());
56         bean.setDescription(mailresource.getDescription());
57         bean.setJndiName(mailresource.getJndiName());
58         bean.setStoreProt(mailresource.getStoreProtocol());
59         bean.setStoreProtClass(mailresource.getStoreProtocolClass());
60         bean.setTransProt(mailresource.getTransportProtocol());
61         bean.setTransProtClass(mailresource.getTransportProtocolClass());
62         bean.setHostName(mailresource.getHost());
63         bean.setUserName(mailresource.getUser());
64         bean.setFromAddr(mailresource.getFrom());
65         bean.setIsDebug(mailresource.getDebug());
66         bean.setIsEnabled(mailresource.getEnabled());
67            
68         PropertyElement[] extraProperties = mailresource.getPropertyElement();
69         Vector JavaDoc vec = new Vector JavaDoc();
70         for (int i = 0; i < extraProperties.length; i++) {
71             NameValuePair pair = new NameValuePair();
72             pair.setParamName(extraProperties[i].getName());
73             pair.setParamValue(extraProperties[i].getValue());
74             vec.add(pair);
75         }
76         
77         if (vec != null && vec.size() > 0) {
78             NameValuePair[] props = new NameValuePair[vec.size()];
79             bean.setExtraParams((NameValuePair[])vec.toArray(props));
80         }
81         
82         return bean;
83     }
84     
85     public Resources getGraph(){
86         Resources res = getResourceGraph();
87         MailResource mlresource = res.newMailResource();
88         mlresource.setDescription(getDescription());
89         mlresource.setJndiName(getJndiName());
90         mlresource.setStoreProtocol(getStoreProt());
91         mlresource.setStoreProtocolClass(getStoreProtClass());
92         mlresource.setTransportProtocol(getTransProt());
93         mlresource.setTransportProtocolClass(getTransProtClass());
94         mlresource.setHost(getHostName());
95         mlresource.setUser(getUserName());
96         mlresource.setFrom(getFromAddr());
97         mlresource.setDebug(getIsDebug());
98         mlresource.setEnabled(getIsEnabled());
99         
100         // set properties
101
NameValuePair[] params = getExtraParams();
102         if (params != null && params.length > 0) {
103             for (int i = 0; i < params.length; i++) {
104                 NameValuePair pair = params[i];
105                 PropertyElement prop = mlresource.newPropertyElement();
106                 prop = populatePropertyElement(prop, pair);
107                 mlresource.addPropertyElement(prop);
108             }
109         }
110         
111         res.addMailResource(mlresource);
112         return res;
113     }
114         
115 }
116
Popular Tags