001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.sun.ide.controllers;
042:
043: import java.util.Map;
044: import java.util.List;
045:
046: import javax.management.Attribute;
047:
048: import com.sun.appserv.management.base.AMX;
049: import com.sun.appserv.management.client.AppserverConnectionSource;
050: import com.sun.appserv.management.config.DeployedItemRefConfig;
051: import com.sun.appserv.management.config.EJBModuleConfig;
052: import com.sun.appserv.management.config.Enabled;
053: import com.sun.appserv.management.j2ee.EJBModule;
054: import com.sun.appserv.management.j2ee.J2EEDeployedObject;
055: import com.sun.appserv.management.j2ee.J2EETypes;
056: import java.util.Set;
057:
058: import javax.enterprise.deploy.spi.DeploymentManager;
059: import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase;
060:
061: import org.netbeans.modules.j2ee.sun.util.NodeTypes;
062:
063: /**
064: * Used as a conduit between the Netbeans API's and the AMX MBean API
065: * data model. This API contains convenient methods for retrieving
066: * components allowing the netbeans module heirarchy remain agnostic to the
067: * underlying data model.
068: *
069: * This controller is used to navigate through deployed EJB modules.
070: */
071: public class EJBModuleController extends AppserverMgmtControllerBase
072: implements DeployedItemsController, EnablerController {
073:
074: private EJBModule ejbModule;
075: private EJBModuleConfig ejbConfig;
076:
077: /**
078: * Create an instance of J2EEServerMgmtController used in the interaction
079: * with AMX API for Sun Java System Application Server.
080: *
081: * @param server The AMX J2EEServer object representing a particular server.
082: */
083: public EJBModuleController(EJBModule ejbModule,
084: AppserverConnectionSource connection) {
085: super (ejbModule, connection);
086: this .ejbModule = ejbModule;
087: }
088:
089: /**
090: * Create an instance of J2EEServerMgmtController used in the interaction
091: * with AMX API for Sun Java System Application Server.
092: *
093: * @param server The AMX J2EEServer object representing a particular server.
094: */
095: public EJBModuleController(final EJBModule ejbModule,
096: final DeploymentManager dplmtMgr,
097: final AppserverConnectionSource connection) {
098: super (ejbModule, dplmtMgr, connection);
099: this .ejbModule = ejbModule;
100: }
101:
102: public EJBModuleController(final EJBModule ejbModule,
103: final EJBModuleConfig ejbConfig,
104: final DeploymentManager dplmtMgr,
105: final AppserverConnectionSource connection) {
106: super (ejbConfig, dplmtMgr, connection);
107: this .ejbModule = ejbModule;
108: this .ejbConfig = ejbConfig;
109: }
110:
111: /**
112: * Returns the properties of the application given the name.
113: *
114: * @param propsToIgnore The String Properties to ignore.
115: * @return All the application properties.
116: */
117: public Map getProperties(List propsToIgnore) {
118: return getJ2EEAndConfigProperties(NodeTypes.EJB_MODULE,
119: this .ejbModule, this .ejbConfig, propsToIgnore);
120: }
121:
122: /**
123: * Returns the properties of the application given the name.
124: *
125: * @param appName The name of the attribute.
126: * @param value The value of the attribute to set.
127: *
128: * @return updated Attribute
129: */
130: public Attribute setProperty(final String attrName,
131: final Object value) {
132:
133: testIfServerInDebug();
134:
135: return ControllerUtil.setAttributeValue(ejbModule, ejbConfig,
136: attrName, value, getMBeanServerConnection());
137: }
138:
139: /**
140: *
141: *
142: */
143: public String[] getStatelessSessionBeans() {
144: return getEjbsByType(NodeTypes.STATELESS_SESSION_BEAN);
145: }
146:
147: /**
148: *
149: */
150: public String[] getStatefulSessionBeans() {
151: return getEjbsByType(NodeTypes.STATEFUL_SESSION_BEAN);
152: }
153:
154: /**
155: *
156: */
157: public String[] getMessageDrivenBeans() {
158: return getEjbsByType(NodeTypes.MESSAGE_DRIVEN_BEAN);
159: }
160:
161: /**
162: *
163: *
164: */
165: public String[] getEntityBeans() {
166: return getEjbsByType(NodeTypes.ENTITY_BEAN);
167: }
168:
169: /**
170: *
171: */
172: public Map getStatelessEJBProperties(final String ejbName,
173: final List propsToIgnore) {
174: return getPropertiesFromBackend(
175: NodeTypes.STATELESS_SESSION_BEAN, getEjb(
176: NodeTypes.STATELESS_SESSION_BEAN, ejbName),
177: propsToIgnore);
178: }
179:
180: /**
181: *
182: */
183: public Attribute setStatelessEJBProperties(final String ejbName,
184: final String attrName, final Object value) {
185:
186: testIfServerInDebug();
187:
188: return ControllerUtil.setAttributeValue(getEjb(
189: NodeTypes.STATELESS_SESSION_BEAN, ejbName), attrName,
190: value, getMBeanServerConnection());
191: }
192:
193: /**
194: *
195: */
196: public Map getStatefulEJBProperties(final String ejbName,
197: final List propsToIgnore) {
198: return getPropertiesFromBackend(
199: NodeTypes.STATEFUL_SESSION_BEAN, getEjb(
200: NodeTypes.STATEFUL_SESSION_BEAN, ejbName),
201: propsToIgnore);
202: }
203:
204: /**
205: *
206: */
207: public Attribute setStatefulEJBProperties(final String ejbName,
208: final String attrName, final Object value) {
209:
210: testIfServerInDebug();
211:
212: return ControllerUtil.setAttributeValue(getEjb(
213: NodeTypes.STATEFUL_SESSION_BEAN, ejbName), attrName,
214: value, getMBeanServerConnection());
215: }
216:
217: /**
218: *
219: */
220: public Map getEntityEJBProperties(final String ejbName,
221: final List propsToIgnore) {
222: return getPropertiesFromBackend(NodeTypes.ENTITY_BEAN, getEjb(
223: NodeTypes.ENTITY_BEAN, ejbName), propsToIgnore);
224: }
225:
226: /**
227: *
228: */
229: public Attribute setEntityEJBProperties(final String ejbName,
230: final String attrName, final Object value) {
231:
232: testIfServerInDebugAndLogException();
233:
234: return ControllerUtil.setAttributeValue(getEjb(
235: NodeTypes.ENTITY_BEAN, ejbName), attrName, value,
236: getMBeanServerConnection());
237: }
238:
239: /**
240: *
241: */
242: public Map getMessageDrivenEJBProperties(final String ejbName,
243: final List propsToIgnore) {
244: return getPropertiesFromBackend(NodeTypes.MESSAGE_DRIVEN_BEAN,
245: getEjb(NodeTypes.MESSAGE_DRIVEN_BEAN, ejbName),
246: propsToIgnore);
247: }
248:
249: /**
250: *
251: */
252: public Attribute setMessageDrivenEJBProperties(
253: final String ejbName, final String attrName,
254: final Object value) {
255:
256: testIfServerInDebug();
257:
258: return ControllerUtil.setAttributeValue(getEjb(
259: NodeTypes.ENTITY_BEAN, ejbName), attrName, value,
260: getMBeanServerConnection());
261: }
262:
263: /**
264: *
265: */
266: public AMX getEjb(final String nodeType, final String ejbName) {
267: testIfServerInDebug();
268: return ejbModule.getContainee(NodeTypes
269: .getAMXJ2EETypeByNodeType(nodeType), ejbName);
270: }
271:
272: /**
273: *
274: */
275: public String[] getEjbsByType(String nodeType) {
276: testIfServerInDebug();
277: Set ejbs = ejbModule.getContaineeSet(NodeTypes
278: .getAMXJ2EETypeByNodeType(nodeType));
279: String[] components = ControllerUtil
280: .getComponentNamesFromSet(ejbs);
281: return components;
282: }
283:
284: /**
285: *
286: *
287: *
288: */
289: public boolean isEnabled() {
290: testIfServerInDebug();
291: boolean configEnabled = ((Enabled) ejbConfig).getEnabled();
292: return ControllerUtil.calculateIsEnabled(ejbConfig,
293: configEnabled);
294: }
295:
296: /**
297: *
298: *
299: *
300: */
301: public void setEnabled(boolean enabled) {
302: testIfServerInDebug();
303: DeployedItemRefConfig config = ControllerUtil
304: .getDeployedItemRefConfig(ejbConfig);
305: if (config != null)
306: config.setEnabled(enabled);
307: }
308:
309: public J2EEDeployedObject getJ2EEObject() {
310: return ejbModule;
311: }
312: }
|