KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > jndi > JndiMBeanImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JndiMBeanImpl.java
26  *
27  * Created on March 8, 2004, 1:48 PM
28  */

29
30 package com.sun.enterprise.admin.monitor.jndi;
31
32 import com.sun.enterprise.admin.common.constant.AdminConstants;
33 import com.sun.enterprise.util.i18n.StringManager;
34 import java.lang.reflect.InvocationTargetException JavaDoc;
35 import java.lang.reflect.Method JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39 import javax.management.AttributeNotFoundException JavaDoc;
40 import javax.management.InvalidAttributeValueException JavaDoc;
41 import javax.management.MBeanException JavaDoc;
42 import javax.management.MBeanInfo JavaDoc;
43 import javax.management.MBeanOperationInfo JavaDoc;
44 import javax.management.MBeanParameterInfo JavaDoc;
45 import javax.management.ReflectionException JavaDoc;
46 import javax.naming.NameClassPair JavaDoc;
47 import javax.naming.NamingException JavaDoc;
48
49 /**
50  * The JndiMBean implementation from which a client can access jndi
51  * entries given a particular context.
52  
53  * @author Rob Ruyak
54  */

55 public class JndiMBeanImpl implements JndiMBean {
56     
57     private JndiMBeanHelper helper;
58     MBeanInfo JavaDoc mbeanInfo;
59     private static final Logger JavaDoc logger =
60         Logger.getLogger(AdminConstants.kLoggerName);
61     private static final StringManager sm =
62         StringManager.getManager(JndiMBeanImpl.class);
63     
64     /** Creates a new instance of JndiMBeanImpl */
65     public JndiMBeanImpl() {
66         initialize();
67     }
68     
69     /**
70      * Initializes the JndiMBeanImpl mbean object for servicing queries
71      * related to the jndi entries of the application server's naming
72      * service. This initialization involves the creation of the object's
73      * JndiMBeanHelper for delegating requests.
74      */

75     void initialize() {
76         helper = new JndiMBeanHelper();
77     }
78     
79     /**
80      *
81      */

82     public Object JavaDoc getAttribute(String JavaDoc str)
83             throws AttributeNotFoundException JavaDoc,
84                 MBeanException JavaDoc, ReflectionException JavaDoc {
85         throw new UnsupportedOperationException JavaDoc(
86                 sm.getString("monitor.jndi.unsupported_method"));
87     }
88     
89     /**
90      *
91      */

92     public AttributeList JavaDoc getAttributes(String JavaDoc[] str) {
93         throw new UnsupportedOperationException JavaDoc(
94                 sm.getString("monitor.jndi.unsupported_method"));
95     }
96     
97     /**
98      *
99      */

100     public MBeanInfo JavaDoc getMBeanInfo() {
101         if(mbeanInfo == null) {
102             mbeanInfo = new MBeanInfo JavaDoc(this.getClass().getName(),
103                 "Managed Object for " + this.getClass().getName(),
104                 null, null, getOperationInfo(), null);
105         }
106         return mbeanInfo;
107     }
108     
109     /**
110      *
111      */

112     MBeanOperationInfo JavaDoc[] getOperationInfo() {
113         Method JavaDoc[] methods = this.getClass().getMethods();
114         MBeanOperationInfo JavaDoc[] mInfo = new MBeanOperationInfo JavaDoc[methods.length];
115         for(int i= 0; i < methods.length; i++){
116            mInfo[i]= createOperationInfo(methods[i]);
117         }
118         return mInfo;
119     }
120     
121     /**
122      *
123      */

124     MBeanOperationInfo JavaDoc createOperationInfo(Method JavaDoc method){
125         return new MBeanOperationInfo JavaDoc(method.getName(),
126             "Method " + method.getName(),
127             getParameterInfo(method.getParameterTypes()),
128             method.getReturnType().getName(),
129             MBeanOperationInfo.INFO);
130     }
131     
132     /**
133      *
134      */

135     MBeanParameterInfo JavaDoc[] getParameterInfo(Class JavaDoc[] paramTypes){
136         MBeanParameterInfo JavaDoc[] params=null;
137         if(paramTypes != null){
138             params = new MBeanParameterInfo JavaDoc[paramTypes.length];
139             for(int i = 0; i < paramTypes.length; i++){
140                 try {
141                     params[i] = new MBeanParameterInfo JavaDoc("param" + i,
142                                 paramTypes[i].getName(),
143                                 paramTypes[i].getName());
144                 } catch(java.lang.IllegalArgumentException JavaDoc e){
145                     logger.log(Level.INFO, e.toString());
146                 }
147             }
148         }
149         return params;
150     }
151     
152     /**
153      *
154      */

155     boolean isAttrGetterOrSetter(Method JavaDoc operation){
156         if(operation.getName().startsWith("get")
157             || operation.getName().startsWith("set")){
158             return true;
159         }
160         return false;
161     }
162     
163     /**
164      *
165      */

166     public Object JavaDoc invoke(String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str2)
167             throws MBeanException JavaDoc, ReflectionException JavaDoc {
168         Object JavaDoc a = null;
169         Class JavaDoc[] c = new Class JavaDoc[str2.length];
170         for(int i=0; i < str2.length; i++){
171             c[i] = str2[i].getClass();
172         }
173         try {
174            a = (Object JavaDoc)this.getClass().getMethod(str, c).invoke(this, obj);
175         } catch(InvocationTargetException JavaDoc e){
176             logger.log(Level.INFO,e.getMessage(), e);
177             MBeanException JavaDoc me =
178                 new MBeanException JavaDoc((Exception JavaDoc)e.getTargetException());
179             throw me;
180         } catch (Exception JavaDoc e) {
181             throw new MBeanException JavaDoc(e);
182         }
183         return a;
184     }
185     
186     /**
187      *
188      */

189     public void setAttribute(javax.management.Attribute JavaDoc attribute)
190             throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc,
191                 MBeanException JavaDoc, ReflectionException JavaDoc {
192         throw new UnsupportedOperationException JavaDoc(
193                 sm.getString("monitor.jndi.unsupported_method"));
194     }
195     
196     /**
197      *
198      */

199     public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributeList) {
200         throw new UnsupportedOperationException JavaDoc(
201                 sm.getString("monitor.jndi.unsupported_method"));
202     }
203    
204     /**
205      * Gets all the jndi entry names given a specific context name. This
206      * method uses the JndiMBeanHelper object to execute all logic involved
207      * in querying entries via jndi to the application server's naming
208      * service.
209      *
210      * @param context The context name under which the names reside.
211      * @return An array of {@link NameClassPair} objects representing the jndi entries.
212      * @throws {@link MBeanException} if there is an error getting the entries.
213      * @see JndiMBeanHelper#getJndiEntriesByContextPath(String)
214      */

215     public java.util.ArrayList JavaDoc getNames(String JavaDoc context)
216             throws NamingException JavaDoc {
217         java.util.ArrayList JavaDoc names = null;
218         names = helper.getJndiEntriesByContextPath(context);
219         return names;
220     }
221 }
222
Popular Tags