KickJava   Java API By Example, From Geeks To Geeks.

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


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/DottedNameAliasSupport.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 package com.sun.enterprise.admin.dottedname;
30
31 import java.util.Set JavaDoc;
32 import java.util.HashSet JavaDoc;
33
34 import com.sun.enterprise.admin.util.ArrayConversion;
35
36
37 public class DottedNameAliasSupport
38 {
39     public DottedNameAliasSupport( )
40     {
41
42     }
43
44
45     public final static String JavaDoc DOMAIN_SCOPE = "domain";
46     public final static String JavaDoc DOMAIN_SCOPE_DOT = DOMAIN_SCOPE + ".";
47     
48     
49         static public boolean
50     scopeIsDomain( String JavaDoc scope )
51     {
52         return( scope.equals( DOMAIN_SCOPE ) || scope.startsWith( DOMAIN_SCOPE_DOT ) );
53     }
54      
55     
56     
57     /*
58         Names which are domain.xxx names which are aliased into server
59      */

60     static public final Set JavaDoc DOMAIN_PARTS = ArrayConversion.toSet( new String JavaDoc []
61         {
62             // these are prefixes
63
"applications",
64             "resources"
65         } );
66         
67         public static boolean
68     isAliasedDomain( final DottedName dn )
69     {
70         boolean isAliased = false;
71         
72         final java.util.List JavaDoc parts = dn.getParts();
73         
74         if ( parts.size() >= 1 )
75         {
76             isAliased = DOMAIN_PARTS.contains( parts.get( 0 ) );
77         }
78         
79         return( isAliased );
80     }
81     
82     
83     
84     /*
85         Names following the server name which indicate that the server name is *not* to
86         be aliased into config.
87      */

88     static private final Set JavaDoc NON_ALIASED_PARTS_SET = ArrayConversion.toSet( new String JavaDoc []
89         {
90             // these are prefixes
91
"application-ref",
92             "resource-ref",
93             "config-ref",
94             "node-agent-ref",
95             "server-ref",
96             
97             // these are attributes
98
"property",
99             "name"
100         } );
101     
102         protected static boolean
103     isNonAliasedServer( final DottedName dn )
104     {
105         boolean isNonAliased = false;
106         
107         final java.util.List JavaDoc parts = dn.getParts();
108         
109         if ( parts.size() >= 1 )
110         {
111             isNonAliased = NON_ALIASED_PARTS_SET.contains( parts.get( 0 ) );
112         }
113         
114         return( isNonAliased );
115     }
116     
117     /*
118         Map any aliased scope names into their true dotted names.
119         
120         Here 'server' is the name of a server.
121         
122         Rules:
123             server.* => config.* (except for NON_ALIASED_PARTS_SET)
124             * => same as input
125      */

126         public static String JavaDoc
127     resolveScope( final DottedNameServerInfo serverInfo, final DottedName dn )
128         throws DottedNameServerInfo.UnavailableException
129     {
130         final String JavaDoc scopeNameIn = dn.getScope();
131         String JavaDoc actualScopeName = scopeNameIn;
132         
133         if ( scopeIsDomain( scopeNameIn ) )
134         {
135             // no change required
136
}
137         else
138         {
139             final boolean scopeIsServerName = serverInfo.getServerNames().contains( actualScopeName );
140
141             if ( scopeIsServerName )
142             {
143                 if ( isAliasedDomain( dn ) )
144                 {
145                     actualScopeName = DottedNameAliasSupport.DOMAIN_SCOPE;
146                 }
147                 else if ( isNonAliasedServer( dn ) )
148                 {
149                     // no change
150
}
151                 else
152                 {
153                     // it's a server name, and it *is* aliased, but wasn't alised into domain
154
// so it must be aliased into a config
155
actualScopeName = serverInfo.getConfigNameForServer( scopeNameIn );
156                 }
157             }
158         }
159         
160         return( actualScopeName );
161     }
162     
163     
164
165     
166     static java.util.logging.Logger JavaDoc sLogger = null;
167         static void
168     dm( Object JavaDoc o )
169     {
170         if (sLogger == null )
171         {
172             sLogger = java.util.logging.Logger.getLogger( "DottedNameGetSetMBeanImplLogger" );
173             sLogger.setLevel( java.util.logging.Level.INFO );
174         }
175         
176         sLogger.info( o.toString() );
177     }
178 }
179
180
181
182
183
Popular Tags