KickJava   Java API By Example, From Geeks To Geeks.

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


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/PrefixedValueAccessorBase.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 package com.sun.enterprise.admin.dottedname.valueaccessor;
30
31
32 import javax.management.Attribute JavaDoc;
33 import javax.management.AttributeList JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35 import javax.management.MBeanServerConnection JavaDoc;
36 import javax.management.ReflectionException JavaDoc;
37 import javax.management.MBeanException JavaDoc;
38 import javax.management.InstanceNotFoundException JavaDoc;
39 import javax.management.AttributeNotFoundException JavaDoc;
40 import javax.management.RuntimeOperationsException JavaDoc;
41 import javax.management.JMException JavaDoc;
42
43 import javax.management.MBeanServerConnection JavaDoc;
44
45 public abstract class PrefixedValueAccessorBase extends ValueAccessorBase
46 {
47     String JavaDoc _prefix = null; //should be overriden by children
48

49     public PrefixedValueAccessorBase(MBeanServerConnection JavaDoc conn, String JavaDoc prefix)
50     {
51         super( conn );
52         _prefix = prefix;
53     }
54     String JavaDoc getDottedNamePrefix()
55     {
56         
57         if(_prefix==null)
58             throw new RuntimeException JavaDoc("Prefix is not set by children class");
59         return _prefix;
60     }
61
62     String JavaDoc extractPrefixedValueName(String JavaDoc dottedName)
63     {
64         return extractPrefixedValueName(dottedName, false);
65     }
66     
67     String JavaDoc extractPrefixedValueName(String JavaDoc dottedName, boolean bIncludingPrefix)
68     {
69         int lastIdx = dottedName.lastIndexOf("."+getDottedNamePrefix());
70         lastIdx++;
71         if(lastIdx<1)
72         {
73             if(dottedName.startsWith(getDottedNamePrefix()))
74                 lastIdx = 0;
75             else
76                 return null;
77         }
78         if(bIncludingPrefix)
79             return dottedName.substring(lastIdx);
80         else
81             return dottedName.substring(lastIdx+getDottedNamePrefix().length());
82     }
83     
84     boolean isDottedNameForAccessor(String JavaDoc dottedName)
85     {
86         return (extractPrefixedValueName(dottedName)!=null);
87     }
88 }
89
90
91
Popular Tags