1 23 24 31 32 package com.sun.enterprise.admin.server.core.mbean.config.naming; 33 34 import com.sun.enterprise.admin.AdminContext; 35 import com.sun.enterprise.admin.common.MalformedNameException; 36 37 import com.sun.enterprise.admin.server.core.mbean.config.ConfigMBeanBase; 38 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 39 40 import javax.management.ObjectName ; 42 import javax.management.MalformedObjectNameException ; 43 44 import com.sun.enterprise.util.i18n.StringManager; 46 47 48 51 public class ConfigMBeanNamingInfo 52 { 53 private AdminContext m_AdminContext; 54 String [] m_ids = null; 55 MBeanNamingDescriptor m_descr = null; 56 57 private static StringManager localStrings = 59 StringManager.getManager( ConfigMBeanNamingInfo.class ); 60 61 public ConfigMBeanNamingInfo(String type, String [] params) throws MBeanConfigException 62 { 63 this(type, params, true); 64 } 65 public ConfigMBeanNamingInfo(String type, String [] params, boolean bTestParamSize) throws MBeanConfigException 66 { 67 m_descr = ConfigMBeansNaming.findNamingDescriptorByType(type); 68 if(m_descr==null) { 69 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_type", type ); 70 throw new MBeanConfigException( msg ); 71 } 72 73 if(bTestParamSize) 74 { 75 int parmSize = (params==null)?0:params.length; 76 if(m_descr.getParmListSize()!=parmSize) { 77 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.wrong_parameters_array_size", type ); 78 throw new MBeanConfigException( msg ); 79 } 80 } 81 m_ids = params; 82 } 83 84 public ConfigMBeanNamingInfo(String dottedName) throws MBeanConfigException, MalformedNameException 85 { 86 m_descr = ConfigMBeansNaming.findNamingDescriptor(dottedName); 87 if(m_descr==null) { 88 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_dotted_name", dottedName ); 89 throw new MBeanConfigException( msg ); 90 } 91 m_ids = m_descr.extractParmList(dottedName); 92 } 93 94 public ConfigMBeanNamingInfo(ObjectName objectName) throws MBeanConfigException 95 { 96 m_descr = ConfigMBeansNaming.findNamingDescriptor(objectName); 97 if(m_descr==null) { 98 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_object_name", objectName ); 99 throw new MBeanConfigException( msg ); 100 } 101 m_ids = m_descr.extractParmList(objectName); 102 } 103 104 public void setAdminContext(AdminContext adminContext) { 105 m_AdminContext = adminContext; 106 } 107 108 public ObjectName getObjectName() throws MalformedObjectNameException 110 { 111 return m_descr.createObjectName(m_ids); 112 } 113 114 public String [] getLocationParams() 115 { 116 return m_ids; 117 } 118 119 public String getXPath() 120 { 121 return m_descr.createXPath(m_ids); 122 } 123 124 public int getMode() 125 { 126 return m_descr.getMode(); 127 } 128 129 public boolean isModeConfig() 130 { 131 int mode = m_descr.getMode(); 132 return ((mode&MBeansDescriptions.MODE_CONFIG)!=0); 133 } 134 135 public boolean isModeMonitorable() 136 { 137 int mode = m_descr.getMode(); 138 return ((mode&MBeansDescriptions.MODE_MONITOR)!=0); 139 } 140 141 public ConfigMBeanBase constructConfigMBean() throws MBeanConfigException 142 { 143 String className = MBeansDescriptions.CONFIG_MBEANS_BASE_CLASS_PREFIX + m_descr.getMBeanClassName(); 144 Class cl; 145 ConfigMBeanBase configMBean; 146 try 147 { 148 cl = Class.forName(className); 149 configMBean = (ConfigMBeanBase)cl.newInstance(); 151 } 152 catch (Exception e) 153 { 154 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_couldnot_create_mbean_class", className ); 155 throw new MBeanConfigException( msg ); 156 } 157 configMBean.setAdminContext(m_AdminContext); 158 configMBean.initialize(this); 159 return configMBean; 160 } 161 162 public String getServerInstanceName() throws MBeanConfigException 163 { 164 if(m_ids==null || m_ids.length==0) 165 { 166 String msg = localStrings.getString( "admin.server.core.mbean.config.naming.wrong_parameters_array_size", m_descr.getType() ); 167 throw new MBeanConfigException( msg ); 168 } 169 return m_ids[0]; 170 } 171 172 } 173 | Popular Tags |