KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > offline > ConfigDelegate


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 package com.sun.enterprise.management.offline;
26
27 import java.io.IOException JavaDoc;
28
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.MBeanInfo JavaDoc;
31 import javax.management.MBeanAttributeInfo JavaDoc;
32 import javax.management.MBeanOperationInfo JavaDoc;
33 import javax.management.Attribute JavaDoc;
34 import javax.management.AttributeList JavaDoc;
35 import javax.management.AttributeNotFoundException JavaDoc;
36 import javax.management.InvalidAttributeValueException JavaDoc;
37
38 import com.sun.enterprise.management.support.Delegate;
39 import com.sun.enterprise.management.support.DelegateBase;
40
41 import com.sun.enterprise.config.ConfigContext;
42 import com.sun.enterprise.config.ConfigBean;
43 import com.sun.enterprise.config.ConfigException;
44
45 //import com.sun.enterprise.config.serverbeans.*;
46

47 /**
48  */

49 class ConfigDelegate extends DelegateBase
50 {
51     private final ConfigBeanHelper mHelper;
52
53     ConfigDelegate(
54         final ConfigContext configContext,
55         final String JavaDoc xPath )
56         throws ConfigException
57     {
58         super( "ConfigDelegate", null );
59         mHelper = ConfigBeanHelperFactory.getInstance( configContext ).getHelper( xPath );
60     }
61     
62      ConfigDelegate(
63         final ConfigContext configContext,
64         final ConfigBean configBean )
65         throws ConfigException
66     {
67         super( "ConfigDelegate", null );
68         mHelper = ConfigBeanHelperFactory.getInstance( configContext ).getHelper( configBean );
69     }
70     
71         public Object JavaDoc
72     getAttribute( final String JavaDoc attrName )
73         throws AttributeNotFoundException JavaDoc
74     {
75         final Object JavaDoc result = mHelper.getAttribute(attrName);
76         
77         return result;
78     }
79
80         public void
81     setAttribute( final Attribute JavaDoc attr )
82         throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc
83     {
84         mHelper.setAttribute( attr );
85         
86         flush();
87     }
88
89         public MBeanInfo JavaDoc
90     getMBeanInfo()
91     {
92         return mHelper.getMBeanInfo();
93     }
94     
95     
96     /**
97         @see com.sun.enterprise.management.config.OldPropertiesImpl
98      */

99         public AttributeList JavaDoc
100     getProperties()
101     {
102         return mHelper.getProperties();
103     }
104     
105      /**
106         @see com.sun.enterprise.management.config.OldPropertiesImpl
107      */

108         public String JavaDoc
109     getPropertyValue( final String JavaDoc name )
110     {
111         return mHelper.getPropertyValue( name );
112     }
113     
114      /**
115         @see com.sun.enterprise.management.config.OldPropertiesImpl
116      */

117         public void
118     setProperty( final Attribute JavaDoc attr )
119     {
120         mHelper.setProperty( attr );
121     }
122     
123      
124     /**
125         @see com.sun.enterprise.management.config.OldPropertiesImpl
126      */

127         public AttributeList JavaDoc
128     getSystemProperties()
129     {
130         return mHelper.getSystemProperties();
131     }
132     
133     
134      /**
135         @see com.sun.enterprise.management.config.OldPropertiesImpl
136      */

137         public String JavaDoc
138     getSystemPropertyValue( final String JavaDoc name )
139     {
140         return mHelper.getSystemPropertyValue( name );
141     }
142     
143      /**
144         @see com.sun.enterprise.management.config.OldPropertiesImpl
145      */

146         public void
147     setSystemProperty( final Attribute JavaDoc attr )
148     {
149         mHelper.setSystemProperty( attr );
150     }
151     
152     
153         public String JavaDoc
154     getDescription()
155     {
156         return mHelper.getDescription();
157     }
158     
159         public void
160     setDescription( final String JavaDoc description )
161     {
162         mHelper.setDescription( description );
163     }
164     
165         public final Object JavaDoc
166     invoke(
167         String JavaDoc operationName,
168         Object JavaDoc[] args,
169         String JavaDoc[] types )
170     {
171         Object JavaDoc result = null;
172         final int numArgs = args == null ? 0 : args.length;
173         
174         if ( "getProperties".equals( operationName ) &&
175             numArgs == 0 )
176         {
177             result = getProperties();
178         }
179         else if ( "getPropertyValue".equals( operationName ) &&
180             numArgs == 1 && types[0].equals( String JavaDoc.class.getName() ) )
181         {
182             result = getPropertyValue( (String JavaDoc)args[ 0 ] );
183         }
184         else if ( "setProperty".equals( operationName ) &&
185             numArgs == 1 && types[0].equals( Attribute JavaDoc.class.getName() ) )
186         {
187             setProperty( (Attribute JavaDoc)args[ 0 ] );
188         }
189         else if ( "getSystemProperties".equals( operationName ) &&
190             numArgs == 0 )
191         {
192             result = getSystemProperties();
193         }
194         else if ( "getSystemPropertyValue".equals( operationName ) &&
195             numArgs == 1 && types[0].equals( String JavaDoc.class.getName() ) )
196         {
197             result = getSystemPropertyValue( (String JavaDoc)args[ 0 ] );
198         }
199         else if ( "setSystemProperty".equals( operationName ) &&
200             numArgs == 1 && types[0].equals( Attribute JavaDoc.class.getName() ) )
201         {
202             setSystemProperty( (Attribute JavaDoc)args[ 0 ] );
203         }
204         else
205         {
206             result = mHelper.handleInvoke( operationName, args, types );
207         }
208         
209         flush();
210         
211         return result;
212     }
213                 
214         private void
215     flush()
216     {
217         try
218         {
219             mHelper.getConfigContext().flush();
220         }
221         catch (ConfigException e)
222         {
223             throw new RuntimeException JavaDoc( e );
224         }
225     }
226 }
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Popular Tags