KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > controllers > EJBModuleController


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 package org.netbeans.modules.j2ee.sun.ide.controllers;
20
21 import java.util.Map JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.management.Attribute JavaDoc;
25
26 import com.sun.appserv.management.base.AMX;
27 import com.sun.appserv.management.client.AppserverConnectionSource;
28 import com.sun.appserv.management.config.DeployedItemRefConfig;
29 import com.sun.appserv.management.config.EJBModuleConfig;
30 import com.sun.appserv.management.config.Enabled;
31 import com.sun.appserv.management.j2ee.EJBModule;
32 import com.sun.appserv.management.j2ee.J2EEDeployedObject;
33
34 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
35 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase;
36
37 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
38
39
40 /**
41  * Used as a conduit between the Netbeans API's and the AMX MBean API
42  * data model. This API contains convenient methods for retrieving
43  * components allowing the netbeans module heirarchy remain agnostic to the
44  * underlying data model.
45  *
46  * This controller is used to navigate through deployed EJB modules.
47  */

48 public class EJBModuleController extends AppserverMgmtControllerBase
49         implements DeployedItemsController, EnablerController {
50     
51     private EJBModule ejbModule;
52     private EJBModuleConfig ejbConfig;
53     
54     /**
55      * Create an instance of J2EEServerMgmtController used in the interaction
56      * with AMX API for Sun Java System Application Server.
57      *
58      * @param server The AMX J2EEServer object representing a particular server.
59      */

60     public EJBModuleController(EJBModule ejbModule,
61             AppserverConnectionSource connection) {
62         super(ejbModule, connection);
63         this.ejbModule = ejbModule;
64     }
65     
66     
67     /**
68      * Create an instance of J2EEServerMgmtController used in the interaction
69      * with AMX API for Sun Java System Application Server.
70      *
71      * @param server The AMX J2EEServer object representing a particular server.
72      */

73     public EJBModuleController(final EJBModule ejbModule,
74             final DeploymentManager JavaDoc dplmtMgr,
75             final AppserverConnectionSource connection) {
76         super(ejbModule, dplmtMgr, connection);
77         this.ejbModule = ejbModule;
78     }
79
80     public EJBModuleController(final EJBModule ejbModule,
81             final EJBModuleConfig ejbConfig,
82             final DeploymentManager JavaDoc dplmtMgr,
83             final AppserverConnectionSource connection) {
84         super(ejbConfig, dplmtMgr, connection);
85         this.ejbModule = ejbModule;
86         this.ejbConfig = ejbConfig;
87     }
88     
89     /**
90      * Returns the properties of the application given the name.
91      *
92      * @param propsToIgnore The String Properties to ignore.
93      * @return All the application properties.
94      */

95     public Map JavaDoc getProperties(List JavaDoc propsToIgnore) {
96         return getJ2EEAndConfigProperties(NodeTypes.EJB_MODULE, this.ejbModule,
97                 this.ejbConfig, propsToIgnore);
98     }
99     
100     
101     /**
102      * Returns the properties of the application given the name.
103      *
104      * @param appName The name of the attribute.
105      * @param value The value of the attribute to set.
106      *
107      * @return updated Attribute
108      */

109     public Attribute JavaDoc setProperty(final String JavaDoc attrName, final Object JavaDoc value) {
110         
111         testIfServerInDebug();
112         
113         return ControllerUtil.setAttributeValue(ejbModule, ejbConfig, attrName, value,
114             getMBeanServerConnection());
115     }
116     
117     /**
118      *
119      *
120      */

121     public String JavaDoc[] getStatelessSessionBeans() {
122         return getEjbsByType(NodeTypes.STATELESS_SESSION_BEAN);
123     }
124     
125     
126     /**
127      *
128      */

129     public String JavaDoc[] getStatefulSessionBeans() {
130         return getEjbsByType(NodeTypes.STATEFUL_SESSION_BEAN);
131     }
132     
133     
134     /**
135      *
136      */

137     public String JavaDoc[] getMessageDrivenBeans() {
138         return getEjbsByType(NodeTypes.MESSAGE_DRIVEN_BEAN);
139     }
140     
141     
142     /**
143      *
144      *
145      */

146     public String JavaDoc[] getEntityBeans() {
147         return getEjbsByType(NodeTypes.ENTITY_BEAN);
148     }
149
150     
151     /**
152      *
153      */

154     public Map JavaDoc getStatelessEJBProperties(final String JavaDoc ejbName,
155             final List JavaDoc propsToIgnore) {
156         return getPropertiesFromBackend(NodeTypes.STATELESS_SESSION_BEAN,
157             getEjb(NodeTypes.STATELESS_SESSION_BEAN, ejbName), propsToIgnore);
158     }
159     
160     /**
161      *
162      */

163     public Attribute JavaDoc setStatelessEJBProperties(final String JavaDoc ejbName,
164             final String JavaDoc attrName, final Object JavaDoc value) {
165         
166         testIfServerInDebug();
167         
168         return ControllerUtil.setAttributeValue(
169             getEjb(NodeTypes.STATELESS_SESSION_BEAN, ejbName), attrName, value,
170                 getMBeanServerConnection());
171     }
172     
173     
174     /**
175      *
176      */

177     public Map JavaDoc getStatefulEJBProperties(final String JavaDoc ejbName,
178             final List JavaDoc propsToIgnore) {
179         return getPropertiesFromBackend(NodeTypes.STATEFUL_SESSION_BEAN,
180             getEjb(NodeTypes.STATEFUL_SESSION_BEAN, ejbName), propsToIgnore);
181     }
182     
183     /**
184      *
185      */

186     public Attribute JavaDoc setStatefulEJBProperties(final String JavaDoc ejbName,
187             final String JavaDoc attrName, final Object JavaDoc value) {
188         
189         testIfServerInDebug();
190         
191         return ControllerUtil.setAttributeValue(
192             getEjb(NodeTypes.STATEFUL_SESSION_BEAN, ejbName), attrName, value,
193                 getMBeanServerConnection());
194     }
195     
196     /**
197      *
198      */

199     public Map JavaDoc getEntityEJBProperties(final String JavaDoc ejbName,
200             final List JavaDoc propsToIgnore) {
201         return getPropertiesFromBackend(NodeTypes.ENTITY_BEAN,
202             getEjb(NodeTypes.ENTITY_BEAN, ejbName), propsToIgnore);
203     }
204     
205     /**
206      *
207      */

208     public Attribute JavaDoc setEntityEJBProperties(final String JavaDoc ejbName,
209             final String JavaDoc attrName, final Object JavaDoc value) {
210         
211         testIfServerInDebugAndLogException();
212         
213         return ControllerUtil.setAttributeValue(
214             getEjb(NodeTypes.ENTITY_BEAN, ejbName), attrName, value,
215                 getMBeanServerConnection());
216     }
217     
218     /**
219      *
220      */

221     public Map JavaDoc getMessageDrivenEJBProperties(final String JavaDoc ejbName,
222             final List JavaDoc propsToIgnore) {
223         return getPropertiesFromBackend(NodeTypes.MESSAGE_DRIVEN_BEAN,
224             getEjb(NodeTypes.MESSAGE_DRIVEN_BEAN, ejbName), propsToIgnore);
225     }
226     
227     /**
228      *
229      */

230     public Attribute JavaDoc setMessageDrivenEJBProperties(final String JavaDoc ejbName,
231             final String JavaDoc attrName, final Object JavaDoc value) {
232         
233         testIfServerInDebug();
234         
235         return ControllerUtil.setAttributeValue(
236             getEjb(NodeTypes.ENTITY_BEAN, ejbName), attrName, value,
237                 getMBeanServerConnection());
238     }
239     
240     /**
241      *
242      */

243     public AMX getEjb(final String JavaDoc nodeType, final String JavaDoc ejbName) {
244         testIfServerInDebug();
245         return ejbModule.getContainee(
246             NodeTypes.getAMXJ2EETypeByNodeType(nodeType), ejbName);
247     }
248     
249
250     /**
251      *
252      */

253     public String JavaDoc[] getEjbsByType(String JavaDoc nodeType) {
254         testIfServerInDebug();
255         return ControllerUtil.getComponentNamesFromMap(
256             ejbModule.getContaineeMap(
257                 NodeTypes.getAMXJ2EETypeByNodeType(nodeType)));
258     }
259
260     
261     /**
262      *
263      *
264      *
265      */

266     public boolean isEnabled() {
267         testIfServerInDebug();
268         boolean configEnabled = ((Enabled)ejbConfig).getEnabled();
269         return ControllerUtil.calculateIsEnabled(ejbConfig, configEnabled);
270     }
271     
272     
273     /**
274      *
275      *
276      *
277      */

278     public void setEnabled(boolean enabled) {
279         testIfServerInDebug();
280         DeployedItemRefConfig config = ControllerUtil.getDeployedItemRefConfig(ejbConfig);
281         if(config != null)
282             config.setEnabled(enabled);
283     }
284     
285     public J2EEDeployedObject getJ2EEObject() {
286         return ejbModule;
287     }
288 }
289
Popular Tags