KickJava   Java API By Example, From Geeks To Geeks.

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


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/DottedNameAliasedQuery.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.Collections JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35
36 import javax.management.ObjectName JavaDoc;
37
38 /*
39     Implements DottedNameQuery over config dotted names by presenting a view
40     of user-visible dotted names even though the underlying dotted names are
41     in fact not user-visible. For PE, this means that dotted names start with
42     the server name "server", but in actuality they are registered starting
43     with the config name. This class hides that detail.
44     
45     Additionally, domain.* is also aliased into server
46  */

47 public class DottedNameAliasedQuery implements DottedNameQuery
48 {
49     protected final DottedNameQuery mSrcQuery;
50     protected final DottedNameServerInfo mServerInfo;
51     final DottedNameResolverForAliases mAliasResolver;
52     
53         public
54     DottedNameAliasedQuery( final DottedNameQuery srcQuery, final DottedNameServerInfo serverInfo )
55     {
56         mSrcQuery = srcQuery;
57         mServerInfo = serverInfo;
58         mAliasResolver = new DottedNameResolverForAliases( srcQuery, serverInfo );
59     }
60     
61         public ObjectName JavaDoc
62     dottedNameToObjectName( final String JavaDoc dottedName )
63     {
64         return( mAliasResolver.resolveDottedName( dottedName ) );
65     }
66     
67         public Set JavaDoc
68     allDottedNameStrings( )
69     {
70         Set JavaDoc result = Collections.EMPTY_SET;
71         
72         try
73         {
74             result = allDottedNameStringsThrow();
75         }
76         catch( DottedNameServerInfo.UnavailableException e )
77         {
78             DottedNameLogger.logException( e );
79         }
80         return( result );
81     }
82     
83     /*
84         Return a set of all dotted names *as visible to the user*.
85         
86         This means that we convert any dotted names beginning with a config name
87         to dotted names beginning with its corresponding server name.
88         
89         Certain domain names are also aliased into the server name.
90      */

91         protected java.util.Set JavaDoc
92     allDottedNameStringsThrow( )
93         throws DottedNameServerInfo.UnavailableException
94     {
95         final Set JavaDoc srcSet = mSrcQuery.allDottedNameStrings();
96         final Iterator JavaDoc iter = srcSet.iterator();
97         final HashSet JavaDoc destSet = new HashSet JavaDoc();
98         
99         final Set JavaDoc configNames = mServerInfo.getConfigNames();
100         
101         while ( iter.hasNext() )
102         {
103             final String JavaDoc dottedName = (String JavaDoc)iter.next();
104             final DottedName dn = DottedNameFactory.getInstance().get( dottedName );
105             
106             final String JavaDoc scope = dn.getScope();
107             
108             if ( DottedNameAliasSupport.scopeIsDomain( scope ) )
109             {
110                 if ( DottedNameAliasSupport.isAliasedDomain( dn ) )
111                 {
112                     destSet.add (dottedName);
113                     addAllNamesForDomain( dn, destSet );
114                 }
115             }
116             else
117             {
118                 if ( configNames.contains( scope ) )
119                 {
120                     addAllNamesForConfig( dn, destSet );
121                 }
122                 else
123                 {
124                     // not a config name.
125
destSet.add( dottedName );
126                 }
127             }
128             
129         }
130         
131         return( destSet );
132     }
133     
134     /*
135         Given a config dotted name, generate and add all corresponding dotted
136         names that start with the server name (just one in PE). (In SE/EE there
137         could be more than one server using the same config).
138      */

139     protected void
140     addAllNamesForDomain( final DottedName domainDN, final Set JavaDoc outSet )
141         throws DottedNameServerInfo.UnavailableException
142     {
143         final Iterator JavaDoc iter = mServerInfo.getServerNames().iterator();
144         
145         // there may be none if no servers refer to the config--that's OK
146
while ( iter.hasNext() )
147         {
148             final String JavaDoc serverName = (String JavaDoc)iter.next();
149             
150             final String JavaDoc dottedNameString =
151                     DottedName.toString( domainDN.getDomain(), serverName, domainDN.getParts() );
152                     
153             final DottedName newName = DottedNameFactory.getInstance().get( dottedNameString );
154             outSet.add( newName.toString() );
155         }
156     }
157     
158     /*
159         Given a config dotted name, generate and add all corresponding dotted
160         names that start with the server name (just one in PE). (In SE/EE there
161         could be more than one server using the same config).
162      */

163     protected void
164     addAllNamesForConfig( final DottedName configDN, final Set JavaDoc outSet )
165         throws DottedNameServerInfo.UnavailableException
166     {
167         final String JavaDoc [] serverNames = mServerInfo.getServerNamesForConfig( configDN.getScope() );
168         
169         // there may be none if no servers refer to the config--that's OK
170
for( int i = 0; i < serverNames.length; ++i )
171         {
172             final String JavaDoc newName =
173                     DottedName.toString( configDN.getDomain(), serverNames[ i ], configDN.getParts() );
174
175             outSet.add( newName );
176         }
177     }
178 }
179
180
181
Popular Tags