package org.ehcache.jsr107;
import java.net.URI;
import javax.cache.CacheException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
abstract class Eh107MXBean {
private final ObjectName objectName;
Eh107MXBean(String cacheName, URI cacheManagerURI, final String beanName) {
this.objectName = createObjectName(cacheName, cacheManagerURI, beanName);
}
private String sanitize(String string) {
return string == null ? "" : string.replaceAll(",|:|=|\n", ".");
}
private ObjectName createObjectName(String cacheName, URI cacheManagerURI, String beanName) {
String cacheManagerName = sanitize(cacheManagerURI.toString());
cacheName = sanitize(cacheName);
try {
return new ObjectName("javax.cache:type=" + beanName + ",CacheManager=" + cacheManagerName + ",Cache="
+ cacheName);
} catch (MalformedObjectNameException e) {
throw new CacheException(e);
}
}
ObjectName getObjectName() {
return this.objectName;
}
}