1 23 24 29 package com.sun.enterprise.admin.dottedname; 30 31 import java.util.Collections ; 32 import java.util.Set ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 36 import javax.management.ObjectName ; 37 38 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 62 dottedNameToObjectName( final String dottedName ) 63 { 64 return( mAliasResolver.resolveDottedName( dottedName ) ); 65 } 66 67 public Set 68 allDottedNameStrings( ) 69 { 70 Set 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 91 protected java.util.Set 92 allDottedNameStringsThrow( ) 93 throws DottedNameServerInfo.UnavailableException 94 { 95 final Set srcSet = mSrcQuery.allDottedNameStrings(); 96 final Iterator iter = srcSet.iterator(); 97 final HashSet destSet = new HashSet (); 98 99 final Set configNames = mServerInfo.getConfigNames(); 100 101 while ( iter.hasNext() ) 102 { 103 final String dottedName = (String )iter.next(); 104 final DottedName dn = DottedNameFactory.getInstance().get( dottedName ); 105 106 final String 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 destSet.add( dottedName ); 126 } 127 } 128 129 } 130 131 return( destSet ); 132 } 133 134 139 protected void 140 addAllNamesForDomain( final DottedName domainDN, final Set outSet ) 141 throws DottedNameServerInfo.UnavailableException 142 { 143 final Iterator iter = mServerInfo.getServerNames().iterator(); 144 145 while ( iter.hasNext() ) 147 { 148 final String serverName = (String )iter.next(); 149 150 final String 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 163 protected void 164 addAllNamesForConfig( final DottedName configDN, final Set outSet ) 165 throws DottedNameServerInfo.UnavailableException 166 { 167 final String [] serverNames = mServerInfo.getServerNamesForConfig( configDN.getScope() ); 168 169 for( int i = 0; i < serverNames.length; ++i ) 171 { 172 final String newName = 173 DottedName.toString( configDN.getDomain(), serverNames[ i ], configDN.getParts() ); 174 175 outSet.add( newName ); 176 } 177 } 178 } 179 180 181 | Popular Tags |