KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > DottedNameForValue


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/DottedNameForValue.java,v 1.3 2005/12/25 03:42:02 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:42:02 $
28  */

29  
30 package com.sun.enterprise.admin.dottedname;
31
32 import java.util.List JavaDoc;
33 import com.sun.enterprise.admin.dottedname.valueaccessor.PrefixedValueSupport;
34
35
36 /*
37     A class which interprets a DottedName as containing a value name.
38  */

39 public final class DottedNameForValue
40 {
41     protected final DottedName mDottedName;
42     protected DottedName mPrefix;
43     protected String JavaDoc mValueName;
44     
45         public
46     DottedNameForValue( final DottedName dottedName )
47     {
48         mDottedName = dottedName;
49         mValueName = null;
50         mPrefix = init();
51     }
52     
53     /**
54         Examine the name and extract the name of the value, which could be either
55         a plain name or a prefixed name.
56      */

57         private DottedName
58     init()
59     {
60         final List JavaDoc parts = mDottedName.getParts();
61         final int numParts = parts.size();
62         
63         // the scope is first, then
64
// there must be at least 1 part for there to be a value
65
// example: "domain.locale"
66
if ( numParts == 0 )
67         {
68             final String JavaDoc msg = DottedNameStrings.getString(
69                     DottedNameStrings.NO_VALUE_NAME_SPECIFIED_KEY );
70             throw new IllegalArgumentException JavaDoc( msg + " = " + mDottedName );
71         }
72         
73         // the last part is the value name
74
final String JavaDoc lastPart = (String JavaDoc)parts.get( numParts - 1 );
75         int numPrefixParts = 0;
76         
77         // If the part preceeding the value name is prefix
78
// then
79
PrefixedValueSupport prop_support = new PrefixedValueSupport(null);
80         final String JavaDoc dottedName = DottedName.toString(mDottedName.getDomain(),
81                                                 mDottedName.getScope(),
82                                                 mDottedName.getParts(), false);
83         final boolean isPrefixed = prop_support.isPrefixedValueDottedName(dottedName);
84         if ( isPrefixed )
85         {
86             mValueName = prop_support.getPrefixedValueName(dottedName, true);
87             numPrefixParts = numParts - 2;
88         }
89         else
90         {
91             // it's a regular value name; does not include prefix
92
mValueName = lastPart;
93             numPrefixParts = numParts - 1;
94         }
95         
96         return( DottedNameFactory.getInstance().get( DottedName.toString( mDottedName, numPrefixParts ) ) );
97     }
98         
99         public DottedName
100     getPrefix()
101     {
102         return( mPrefix );
103     }
104     
105                 public String JavaDoc
106     getValueName()
107     {
108         assert( mValueName != null );
109         return( mValueName );
110     }
111                 
112     public String JavaDoc toString() {
113         return mDottedName.toString();
114     }
115 }
116
117
118
Popular Tags