1 23 24 package com.sun.enterprise.admin.server.core.jmx.storage; 25 26 import javax.management.ObjectName ; 28 import javax.management.InstanceNotFoundException ; 29 import com.sun.enterprise.admin.AdminContext; 31 import com.sun.enterprise.admin.common.ObjectNames; 32 import com.sun.enterprise.admin.common.ObjectNameHelper; 33 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 34 import com.sun.enterprise.admin.common.constant.AdminConstants; 35 import com.sun.enterprise.admin.server.core.mbean.config.GenericConfigurator; 36 import com.sun.enterprise.admin.server.core.mbean.config.ServerController; 37 import com.sun.enterprise.admin.server.core.mbean.config.naming.ConfigMBeanNamingInfo; 38 import com.sun.enterprise.instance.ServerManager; 40 import com.sun.enterprise.instance.InstanceEnvironment; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.config.ConfigContext; 43 import com.sun.enterprise.config.ConfigFactory; 44 import com.sun.enterprise.config.ConfigBeansFactory; 45 import com.sun.enterprise.config.serverbeans.*; 46 47 import java.util.logging.Level ; 48 import java.util.logging.Logger ; 49 50 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 51 import com.sun.enterprise.admin.meta.MBeanRegistry; 52 53 58 59 public class PersistenceChecker 60 { 61 private static final Logger _logger = Logger.getLogger( 62 AdminConstants.kLoggerName); 63 64 private AdminContext mAdminContext; 65 66 67 public PersistenceChecker () 68 { 69 } 71 72 public void setAdminContext(AdminContext ctx) { 73 mAdminContext = ctx; 74 } 75 76 private Object findElement_8_0(ObjectName objectName) throws InstanceNotFoundException 77 { 78 try 79 { 80 MBeanRegistry registry = MBeanRegistryFactory.getAdminMBeanRegistry(); 81 return (Object )registry.findMBeanRegistryEntry(objectName); 82 } 83 catch(Exception e) 84 { 85 return null; 86 } 87 } 88 public Object findElement(ObjectName objectName) throws InstanceNotFoundException 89 { 90 Object match = null; 91 92 match= findElement_8_0(objectName); 93 if(match!=null) 94 return match; 95 96 String type = ObjectNameHelper.getType(objectName); 99 String instanceName = ObjectNameHelper.getServerInstanceName(objectName); 100 101 if (type != null) 102 { 103 if (type.equals(ObjectNames.kController)) 104 { 105 match = new ServerController(); 106 } 107 else if (type.equals(ObjectNames.kGenericConfigurator)) 108 { 109 match = new GenericConfigurator(); 110 } 111 else if (type.equals(ObjectNames.kServerInstance)) 112 { 113 match = findServerInstance(instanceName); 114 if(match==null) 115 throw new InstanceNotFoundException (objectName.toString()); 116 } 117 else if (type.equals(ObjectNames.kDeployment)) 118 { 119 match = findServerInstance(instanceName); 120 if(match==null) 121 throw new InstanceNotFoundException (objectName.toString()); 122 } 123 else 124 { 125 126 match = findGenericConfigBean(objectName, instanceName); 127 } 128 } 129 else 130 { 131 132 _logger.log(Level.FINE, "mbean.config.admin.unknown_mbean_type", objectName.toString() ); 133 } 134 return ( match ); 135 } 136 137 private Object findServerInstance(String instanceName) 138 { 139 ServerManager sm = ServerManager.instance(); 140 Server serverInstance = null; 141 143 if (! sm.instanceExists(instanceName) ) 144 { 145 return null; 146 } 147 148 try 149 { 150 ConfigContext cc = getConfigContext(instanceName); 151 serverInstance = ServerBeansFactory.getServerBean(cc); 152 } 153 catch(Exception e) 154 { 155 e.printStackTrace(); } 157 return ( serverInstance ); 158 } 159 160 private Object findGenericConfigBean(ObjectName objectName, String instanceName) 161 { 162 163 Object bean = null; 164 ConfigMBeanNamingInfo mbeanInfo = null; 165 try 166 { 167 mbeanInfo = new ConfigMBeanNamingInfo(objectName); 168 } 169 catch (MBeanConfigException mce) 170 { 171 _logger.log(Level.FINE, "mbean.config.admin.naming_not_found", 172 new Object []{objectName.toString(), mce.getLocalizedMessage()} ); 173 } 174 if(mbeanInfo!=null) 175 { 176 String xPath = mbeanInfo.getXPath(); 177 try 178 { 179 ConfigContext ctx = getConfigContext(instanceName); 180 bean = ConfigBeansFactory.getConfigBeanByXPath(ctx, xPath); 181 } 182 catch(Exception e) 183 { 184 _logger.log(Level.FINE, "mbean.config.admin.config_bean_not_found", 185 new Object []{xPath, e.getLocalizedMessage()} ); 186 } 187 } 188 return bean; 189 } 190 private ConfigContext getConfigContext(String instanceName) throws ConfigException 191 { 192 if (mAdminContext != null) { 193 return mAdminContext.getAdminConfigContext(); 194 } else { 195 String backupServerXmlPath = new InstanceEnvironment(instanceName).getBackupConfigFilePath(); 196 return (ConfigFactory.createConfigContext(backupServerXmlPath) ); 197 } 198 } 199 200 } 201 | Popular Tags |