KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > DelegateToMBeanDelegate


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  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28  
29 /*
30  */

31
32 package com.sun.enterprise.management.support;
33
34 import java.io.IOException JavaDoc;
35
36 import javax.management.ObjectName JavaDoc;
37 import javax.management.MBeanServer JavaDoc;
38 import javax.management.MBeanServerConnection JavaDoc;
39 import javax.management.MBeanInfo JavaDoc;
40 import javax.management.AttributeList JavaDoc;
41 import javax.management.Attribute JavaDoc;
42 import javax.management.AttributeNotFoundException JavaDoc;
43 import javax.management.InvalidAttributeValueException JavaDoc;
44 import javax.management.InstanceNotFoundException JavaDoc;
45 import javax.management.IntrospectionException JavaDoc;
46 import javax.management.ReflectionException JavaDoc;
47
48 import com.sun.appserv.management.util.jmx.stringifier.MBeanInfoStringifier;
49
50 /**
51     Delegate which delegates to another MBean.
52  */

53 public class DelegateToMBeanDelegate extends DelegateBase
54 {
55     private final ObjectName JavaDoc mTarget;
56     private final MBeanServerConnection JavaDoc mConn;
57     private final MBeanInfo JavaDoc mTargetMBeanInfo;
58     
59         public
60     DelegateToMBeanDelegate(
61         final MBeanServerConnection JavaDoc conn,
62         final ObjectName JavaDoc target)
63         throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc, ReflectionException JavaDoc,
64         IOException JavaDoc
65     {
66         super( "DelegateToMBeanDelegate." + target.toString(), null );
67         
68         mConn = conn;
69         mTarget = target;
70         
71         mTargetMBeanInfo = mConn.getMBeanInfo( target );
72     }
73     
74         public
75     DelegateToMBeanDelegate(
76         final MBeanServer JavaDoc server,
77         final ObjectName JavaDoc target)
78         throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc, ReflectionException JavaDoc
79     {
80         super( "DelegateToMBeanDelegate." + target.toString(), null);
81         
82         mConn = server;
83         mTarget = target;
84         
85         mTargetMBeanInfo = server.getMBeanInfo( target );
86         
87         //trace( "\nMBeanInfo for: " + target + ":\n" +
88
//MBeanInfoStringifier.DEFAULT.stringify( mTargetMBeanInfo ) );
89
}
90     
91         public ObjectName JavaDoc
92     getTarget()
93     {
94         return( mTarget );
95     }
96     
97         public MBeanServerConnection JavaDoc
98     getMBeanServerConnection()
99     {
100         return( mConn );
101     }
102     
103         public Object JavaDoc
104     getAttribute( final String JavaDoc attrName )
105         throws AttributeNotFoundException JavaDoc
106     {
107         try
108         {
109             final Object JavaDoc value =
110                 getMBeanServerConnection().getAttribute( mTarget, attrName );
111             return( value );
112         }
113         catch( Exception JavaDoc e )
114         {
115             e.printStackTrace();
116             throw new RuntimeException JavaDoc( e );
117         }
118     }
119     
120         public void
121     setAttribute( final Attribute JavaDoc attr )
122         throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc
123     {
124         try
125         {
126             getMBeanServerConnection().setAttribute( mTarget, attr );
127         }
128         catch( Exception JavaDoc e )
129         {
130             throw new RuntimeException JavaDoc( e );
131         }
132     }
133     
134         public MBeanInfo JavaDoc
135     getMBeanInfo()
136     {
137         return( mTargetMBeanInfo );
138     }
139     
140     
141     
142         private void
143     delegateFailed( final Throwable JavaDoc t )
144     {
145         if ( getOwner() != null )
146         {
147             getOwner().delegateFailed( t );
148         }
149     }
150
151     /**
152      */

153         public final Object JavaDoc
154     invoke(
155         String JavaDoc operationName,
156         Object JavaDoc[] args,
157         String JavaDoc[] types )
158     {
159         try
160         {
161             final Object JavaDoc result = getMBeanServerConnection().invoke( getTarget(),
162                                         operationName, args, types );
163             
164             return( result );
165         }
166         catch ( InstanceNotFoundException JavaDoc e )
167         {
168             delegateFailed( e );
169             throw new RuntimeException JavaDoc( e );
170         }
171         catch ( IOException JavaDoc e )
172         {
173             try
174             {
175                 getMBeanServerConnection().isRegistered( getTarget() );
176             }
177             catch( IOException JavaDoc ee )
178             {
179                 delegateFailed( e );
180             }
181             throw new RuntimeException JavaDoc( e );
182         }
183         catch( Exception JavaDoc e )
184         {
185             throw new RuntimeException JavaDoc( e );
186         }
187     }
188 }
189
190
191
192
193
194
195
196
197
Popular Tags