KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > valueaccessor > AnyValueAccessor


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  * $Header: /cvs/glassfish/admin/mbeans/src/java/com/sun/enterprise/admin/dottedname/valueaccessor/AnyValueAccessor.java,v 1.3 2005/12/25 03:42:06 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:42:06 $
28  */

29  
30
31 package com.sun.enterprise.admin.dottedname.valueaccessor;
32
33
34 import javax.management.MBeanServerConnection JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36 import javax.management.Attribute JavaDoc;
37
38
39 import com.sun.enterprise.admin.dottedname.valueaccessor.PrefixedValueSupport;
40 import com.sun.enterprise.admin.dottedname.valueaccessor.PropertyValueAccessorBase;
41
42 /*
43     Encapsulates all accessors so that caller need not distinguish between them.
44  */

45 public class AnyValueAccessor extends ValueAccessorBase
46 {
47     final ValueAccessor mAttributeAccessor;
48     
49     
50         public
51     AnyValueAccessor( MBeanServerConnection JavaDoc conn )
52     {
53         super( conn );
54         
55         mAttributeAccessor = new AttributeValueAccessor( conn );
56     }
57     
58         public Attribute JavaDoc
59     getValue( ObjectName JavaDoc objectName, String JavaDoc valueName ) throws Exception JavaDoc
60     {
61         Attribute JavaDoc attr = null;
62         PropertyValueAccessorBase propertyAccessor=
63                  (new PrefixedValueSupport(getMBS()).getPrefixedValueAccessor(valueName));
64         if ( propertyAccessor!=null )
65         {
66             attr = propertyAccessor.getValue( objectName,
67                       propertyAccessor.extractPrefixedValueName(valueName) );
68         }
69         else
70         {
71             attr = mAttributeAccessor.getValue( objectName, valueName );
72         }
73         
74         return( attr );
75     }
76     
77         public Attribute JavaDoc
78     setValue( ObjectName JavaDoc objectName, Attribute JavaDoc attr ) throws Exception JavaDoc
79     {
80         Attribute JavaDoc resultAttr = null;
81         
82         final String JavaDoc valueName = attr.getName();
83         PropertyValueAccessorBase propertyAccessor=
84                  (new PrefixedValueSupport(getMBS()).getPrefixedValueAccessor(valueName));
85         if ( propertyAccessor!=null )
86         {
87             final String JavaDoc propertyName = propertyAccessor.extractPrefixedValueName(valueName);
88             final Attribute JavaDoc newAttr = new Attribute JavaDoc( propertyName, attr.getValue() );
89             resultAttr = propertyAccessor.setValue( objectName, newAttr );
90         }
91         else
92         {
93             resultAttr = mAttributeAccessor.setValue( objectName, attr );
94         }
95         
96         return( resultAttr );
97     }
98 }
99
100
101
102
Popular Tags