KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > management > ServerMEJB


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ServerMEJB.java
22  *
23  * Created on August 13, 2003, 12:14 PM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share.management;
27
28 import java.io.IOException JavaDoc;
29 import javax.management.MBeanException JavaDoc;
30 import javax.management.ReflectionException JavaDoc;
31 import javax.management.IntrospectionException JavaDoc;
32 import javax.management.InstanceNotFoundException JavaDoc;
33 import javax.management.AttributeNotFoundException JavaDoc;
34 import javax.management.InvalidAttributeValueException JavaDoc;
35 import javax.management.MBeanServerConnection JavaDoc;
36 import javax.management.ObjectName JavaDoc;
37 import javax.management.AttributeList JavaDoc;
38 import java.rmi.RemoteException JavaDoc;
39 import java.rmi.ServerException JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41
42 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
43 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
44
45 import org.netbeans.modules.j2ee.sun.api.ServerInterface;
46 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtController;
47 import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil;
48
49
50
51 /**
52  *
53  * @author nityad
54  */

55 public class ServerMEJB implements ServerInterface {
56     
57     /** Creates a new instance of ServerMEJB */
58     private UtilMEJB ut = null;
59
60     private DeploymentManager JavaDoc currentDM = null;
61     static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.share.management.Bundle");// NOI18N
62

63     public ServerMEJB( ) {
64
65     }
66     public ServerMEJB(DeploymentManager JavaDoc dm) {
67         setDeploymentManager (dm);
68     }
69     public void setDeploymentManager(DeploymentManager JavaDoc dm){
70         this.currentDM = dm;
71         
72     }
73     public Object JavaDoc getAttribute(ObjectName JavaDoc name, String JavaDoc attribute) throws MBeanException JavaDoc,
74       AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, ReflectionException JavaDoc, RemoteException JavaDoc{
75          return this.getUT().updateGetAttribute(name, attribute);
76     }
77     
78     public AttributeList JavaDoc getAttributes(ObjectName JavaDoc name, String JavaDoc[] attributes) throws
79       ReflectionException JavaDoc, InstanceNotFoundException JavaDoc, RemoteException JavaDoc{
80         return this.getUT().updateGetAttributes(name, attributes);
81     }
82    
83     public javax.management.MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc name) throws IntrospectionException JavaDoc, InstanceNotFoundException JavaDoc,
84       ReflectionException JavaDoc, RemoteException JavaDoc{
85         return this.getUT().updateMBeanInfo(name);
86     }
87     
88     public Object JavaDoc invoke(ObjectName JavaDoc name, String JavaDoc operationName, Object JavaDoc[] params, String JavaDoc[] signature) throws InstanceNotFoundException JavaDoc,
89      MBeanException JavaDoc, ReflectionException JavaDoc, RemoteException JavaDoc{
90         return this.getUT().updateInvoke(name, operationName, params, signature);
91     }
92     
93     public void setAttribute(ObjectName JavaDoc name, javax.management.Attribute JavaDoc attribute) throws InstanceNotFoundException JavaDoc,
94       AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, RemoteException JavaDoc{
95         this.getUT().updateSetAttribute(name, attribute);
96    }
97     
98     public DeploymentManager JavaDoc getDeploymentManager(){
99         return this.currentDM;
100     }
101     
102     public MBeanServerConnection JavaDoc getMBeanServerConnection() throws RemoteException JavaDoc, ServerException JavaDoc {
103         return this.getUT().getConnection();
104     }
105     
106     public /*ServerMEJB*/Object JavaDoc getManagement(){
107         return this;
108     }
109     
110     private UtilMEJB getUT() throws RemoteException JavaDoc, ServerException JavaDoc{
111         SunDeploymentManagerInterface sdmi = (SunDeploymentManagerInterface)currentDM;
112             if (sdmi.isSuspended()){
113                 //System.out.println("CANNOT DO A getUT WHILE STOP IN A BREAK POINT IN DEBUG MODE...");
114
throw new RemoteException JavaDoc(bundle.getString("MSG_ServerInDebug")) ;
115             }
116             if (this.ut!=null){
117
118                 return this.ut;
119             }
120         SunDeploymentManagerInterface dm=(SunDeploymentManagerInterface)currentDM;
121         try{
122             
123                 ut = new UtilMEJB(dm);
124                 ut.getConnection().getDefaultDomain();//test the connection. Might throw IOE for Uname/password
125

126
127         }
128         catch (IOException JavaDoc e){
129             if(e.getMessage().contains ("500")){//internal error
130
this.ut =null;
131             }
132         }
133         catch (java.lang.NoClassDefFoundError JavaDoc ncf){//wrong dynamic classpath
134
throw new RemoteException JavaDoc(bundle.getString("MSG_WrongInstallDir")) ;
135         }
136         return this.ut;
137     }
138
139     public String JavaDoc getWebModuleName(String JavaDoc contextRoot) {
140         String JavaDoc name = null;
141         SunDeploymentManagerInterface sunDm = (SunDeploymentManagerInterface)currentDM;
142         if (sunDm.isSuspended()) {
143             return null;
144         }
145         if (sunDm.isRunning(false)) {
146             if (sunDm.grabInnerDM(true)) {
147                 try {
148                     AppserverMgmtController controller = getController();
149                     if(controller != null) {
150                         name = controller.getWebModuleName(contextRoot);
151                     }
152                 } finally {
153                     sunDm.releaseInnerDM();
154                 }
155             }
156         }
157         return name;
158     }
159
160     private AppserverMgmtController getController(){
161         AppserverMgmtController controller = null;
162         SunDeploymentManagerInterface sunDm = (SunDeploymentManagerInterface)currentDM;
163         controller = ControllerUtil.getAppserverMgmtControllerFromDeployMgr(currentDM);
164         return controller;
165     }
166     
167     /* check if the dm is ok in term of user name and password,
168      * throws an IOexception if this is incorrect
169      * oterwise, returns normally
170      **/

171     public void checkCredentials() throws IOException JavaDoc{
172         SunDeploymentManagerInterface sdmi = (SunDeploymentManagerInterface)currentDM;
173         if (sdmi.isSuspended()){
174             throw new RemoteException JavaDoc(bundle.getString("MSG_ServerInDebug")) ;
175         }
176         SunDeploymentManagerInterface dm=(SunDeploymentManagerInterface)currentDM;
177         getUT().getConnection().getDefaultDomain();//test the connection. Might throw IOE for Uname/password
178

179         return;
180     }
181     
182 }
183
Popular Tags