KickJava   Java API By Example, From Geeks To Geeks.

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


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  * JMSBean.java
21  *
22  * Created on November 13, 2003, 3:05 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.JavaMsgServiceResource;
30 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
31 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
32 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.PropertyElement;
33 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.ConnectorResource;
34 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.AdminObjectResource;
35 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.ConnectorConnectionPool;
36
37 /**
38  *
39  * @author nityad
40  */

41 public class JMSBean extends JavaMsgServiceResource implements java.io.Serializable JavaDoc{
42
43     /** Creates a new instance of JMSBean */
44     public JMSBean() {
45     }
46     
47     public String JavaDoc getName() {
48         return super.getName();
49     }
50     
51     public static JMSBean createBean(Resources resources) {
52         JMSBean bean = new JMSBean();
53         //name attribute in bean is for studio display purpose.
54
//It is not part of the resource dtd.
55
ConnectorResource connresource = resources.getConnectorResource(0);
56         bean.setName(connresource.getJndiName());
57         bean.setDescription(connresource.getDescription());
58         bean.setIsEnabled(connresource.getEnabled());
59         bean.setJndiName(connresource.getJndiName());
60         bean.setPoolName(connresource.getPoolName());
61         
62         ConnectorConnectionPool connpoolresource = resources.getConnectorConnectionPool(0);
63         bean.setResAdapter(connpoolresource.getResourceAdapterName());
64         bean.setResType(connpoolresource.getConnectionDefinitionName());
65          
66         PropertyElement[] extraProperties = connpoolresource.getPropertyElement();
67         Vector JavaDoc vec = new Vector JavaDoc();
68         for (int i = 0; i < extraProperties.length; i++) {
69             NameValuePair pair = new NameValuePair();
70             pair.setParamName(extraProperties[i].getName());
71             pair.setParamValue(extraProperties[i].getValue());
72             vec.add(pair);
73         }
74         
75         if (vec != null && vec.size() > 0) {
76             NameValuePair[] props = new NameValuePair[vec.size()];
77             bean.setExtraParams((NameValuePair[])vec.toArray(props));
78         }
79         
80         return bean;
81     }
82      
83     public static JMSBean createBean(AdminObjectResource aoresource) {
84         JMSBean bean = new JMSBean();
85         
86         //name attribute in bean is for studio display purpose.
87
//It is not part of the resource dtd.
88
bean.setName(aoresource.getJndiName());
89         bean.setDescription(aoresource.getDescription());
90         bean.setIsEnabled(aoresource.getEnabled());
91         bean.setJndiName(aoresource.getJndiName());
92         bean.setResAdapter(aoresource.getResAdapter());
93         bean.setResType(aoresource.getResType());
94         
95         PropertyElement[] extraProperties = aoresource.getPropertyElement();
96         Vector JavaDoc vec = new Vector JavaDoc();
97         for (int i = 0; i < extraProperties.length; i++) {
98             NameValuePair pair = new NameValuePair();
99             pair.setParamName(extraProperties[i].getName());
100             pair.setParamValue(extraProperties[i].getValue());
101             vec.add(pair);
102         }
103         
104         if (vec != null && vec.size() > 0) {
105             NameValuePair[] props = new NameValuePair[vec.size()];
106             bean.setExtraParams((NameValuePair[])vec.toArray(props));
107         }
108         
109         return bean;
110     }
111     
112     public Resources getConnectorGraph(){
113          Resources res = getResourceGraph();
114          ConnectorResource connresource = res.newConnectorResource();
115          connresource.setDescription(getDescription());
116          connresource.setEnabled(getIsEnabled());
117          connresource.setJndiName(getJndiName());
118          connresource.setPoolName(getJndiName());
119                   
120          ConnectorConnectionPool connpoolresource = res.newConnectorConnectionPool();
121          connpoolresource.setName(getJndiName());
122          connpoolresource.setResourceAdapterName(getResAdapter());
123          connpoolresource.setConnectionDefinitionName(getResType());
124          // set properties
125
NameValuePair[] params = getExtraParams();
126          if (params != null && params.length > 0) {
127              for (int i = 0; i < params.length; i++) {
128                  NameValuePair pair = params[i];
129                  PropertyElement prop = connpoolresource.newPropertyElement();
130                  prop = populatePropertyElement(prop, pair);
131                  connpoolresource.addPropertyElement(prop);
132              }
133          }
134                         
135          res.addConnectorResource(connresource);
136          res.addConnectorConnectionPool(connpoolresource);
137          
138          return res;
139      }
140     
141      public Resources getAdminObjectGraph(){
142          Resources res = getResourceGraph();
143          AdminObjectResource aoresource = res.newAdminObjectResource();
144          aoresource.setDescription(getDescription());
145          aoresource.setEnabled(getIsEnabled());
146          aoresource.setJndiName(getJndiName());
147          aoresource.setResAdapter(getResAdapter());
148          aoresource.setResType(getResType());
149          
150          // set properties
151
NameValuePair[] params = getExtraParams();
152          if (params != null && params.length > 0) {
153              for (int i = 0; i < params.length; i++) {
154                  NameValuePair pair = params[i];
155                  PropertyElement prop = aoresource.newPropertyElement();
156                  prop = populatePropertyElement(prop, pair);
157                  aoresource.addPropertyElement(prop);
158              }
159          }
160          
161          res.addAdminObjectResource(aoresource);
162          return res;
163      }
164 }
165
Popular Tags