1 23 24 92 93 package com.sun.enterprise.admin.meta.naming; 94 95 import javax.management.ObjectName ; 97 import javax.management.MalformedObjectNameException ; 98 99 102 103 106 public class MBeanNamingInfo 107 { 108 String [] m_ids = null; 109 MBeanNamingDescriptor m_descr = null; 110 111 115 public MBeanNamingInfo( MBeanNamingDescriptor descr, String type, String [] params) throws MBeanNamingException 116 { 117 this( descr, type, params, true); 118 } 119 120 public MBeanNamingInfo( MBeanNamingDescriptor descr, String type, String [] params, boolean bTestParamSize) throws MBeanNamingException 121 { 122 m_descr = descr; 123 if(m_descr==null) { 124 String msg = ( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_type" + type ); 125 throw new MBeanNamingException( msg ); 126 } 127 128 if(bTestParamSize) 129 { 130 int parmSize = (params==null)?0:params.length; 131 if(m_descr.getParmListSize()>parmSize) { 132 String msg = ( "admin.server.core.mbean.config.naming.wrong_parameters_array_size"+ type ); 133 throw new MBeanNamingException( msg ); 134 } 135 } 136 137 m_ids = new String [m_descr.getParmListSize()]; 138 for(int i=0; i<m_ids.length; i++) 139 m_ids[i] = params[i]; 140 } 141 142 public MBeanNamingInfo(MBeanNamingDescriptor descr, String dottedName) throws MBeanNamingException, MalformedObjectNameException 143 { 144 m_descr = descr; if(m_descr==null) { 146 String msg = ( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_dotted_name"+dottedName ); 147 throw new MBeanNamingException( msg ); 148 } 149 m_ids = m_descr.extractParmList(dottedName); 150 } 151 152 public MBeanNamingInfo(MBeanNamingDescriptor descr, ObjectName objectName) throws MBeanNamingException 153 { 154 m_descr = descr; if(m_descr==null) { 156 String msg = ( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_object_name"+ objectName ); 157 throw new MBeanNamingException( msg ); 158 } 159 m_ids = m_descr.extractParmList(objectName); 160 } 161 162 public ObjectName getObjectName() throws MalformedObjectNameException 164 { 165 return m_descr.createObjectName(m_ids); 166 } 167 168 private String escapeString(String str) 169 { 170 if(str == null) 171 return null; 172 return str.replace('.', '`').replaceAll("`","\\\\."); 173 } 174 175 private String [] escapeStrings(String [] arr) 176 { 177 if(arr == null) 178 return null; 179 String [] ret = new String [arr.length]; 180 for(int i=0; i<arr.length; i++) 181 { 182 ret[i] = escapeString(arr[i]); 183 } 184 return ret; 185 } 186 public String [] getDottedNames() throws MalformedObjectNameException 187 { 188 return m_descr.createDottedNames(escapeStrings(m_ids)); 189 } 190 191 public String [] getLocationParams() 192 { 193 return m_ids; 194 } 195 196 public String getXPath() 197 { 198 return m_descr.createXPath(m_ids); 199 } 200 201 public String getType() 202 { 203 return m_descr.getType(); 204 } 205 206 public int getMode() 207 { 208 return m_descr.getMode(); 209 } 210 211 public boolean isModeConfig() 212 { 213 int mode = m_descr.getMode(); 214 return ((mode&MBeansNaming.MODE_CONFIG)!=0); 215 } 216 217 public boolean isModeMonitorable() 218 { 219 int mode = m_descr.getMode(); 220 return ((mode&MBeansNaming.MODE_MONITOR)!=0); 221 } 222 223 243 public String getServerInstanceName() throws MBeanNamingException 244 { 245 if(m_ids==null || m_ids.length==0) 246 { 247 String msg = ( "admin.server.core.mbean.config.naming.wrong_parameters_array_size"+ m_descr.getType() ); 248 throw new MBeanNamingException( msg ); 249 } 250 return m_ids[0]; 251 } 252 253 } 254 | Popular Tags |