1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 28 29 import com.sun.appserv.management.helper.RefHelper; 30 import com.sun.appserv.management.base.Util; 31 32 import com.sun.appserv.management.config.*; 33 34 35 import com.sun.enterprise.management.AMXTestBase; 36 import com.sun.enterprise.management.Capabilities; 37 38 39 40 51 public final class DanglingRefsTest extends AMXTestBase 52 { 53 public 54 DanglingRefsTest( ) 55 { 56 } 57 public void 58 testAllDangling() 59 throws ClassNotFoundException 60 { 61 _testDanglingResourceRefConfigs(); 62 } 64 65 private void 66 _testDanglingResourceRefConfigs() 67 throws ClassNotFoundException 68 { 69 final DomainConfig domainConfig = getDomainConfig(); 70 final Set <ResourceConfig> resourcesSet = 71 getQueryMgr().queryInterfaceSet( ResourceConfig.class.getName(), null ); 72 73 final Set <ResourceRefConfig> 74 refs = RefHelper.findAllResourceRefConfigs( getQueryMgr() ); 75 76 final Map <String ,ResourceConfig> resourcesMap = Util.createNameMap( resourcesSet ); 77 78 for( final ResourceRefConfig ref : refs ) 79 { 80 final String name = ref.getName(); 81 82 final ResourceConfig resourceConfig = resourcesMap.get( name ); 83 if ( resourceConfig == null ) 84 { 85 String msg = 86 "Resource reference '" + 87 Util.getObjectName( ref ) + "' refers to a non-existent resource"; 88 89 boolean removedOK = false; 90 try 91 { 92 final ResourceRefConfigCR container = 93 (ResourceRefConfigCR)ref.getContainer(); 94 95 container.removeResourceRefConfig( name ); 96 removedOK = true; 97 } 98 catch( Exception e ) 99 { 100 msg = msg + ", and trying to remove it throws an Exception " + 101 "(remove it manually from domain.xml)" + 102 ", see bug #6298512"; 103 } 104 105 if ( ! removedOK ) 106 { 107 warning( msg ); 108 } 109 } 110 else 111 { 112 } 114 } 115 } 116 117 143 } 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | Popular Tags |