org.weakref.jmx.guice.StringMapExportBinder Maven / Gradle / Ivy
package org.weakref.jmx.guice;
import org.weakref.jmx.internal.guava.base.Throwables;
import com.google.inject.multibindings.Multibinder;
import org.weakref.jmx.ObjectNames;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.util.Map;
import java.util.Map.Entry;
public class StringMapExportBinder
extends MapExportBinder
{
private final Class valueClass;
StringMapExportBinder(Multibinder> binder, Class valueClass)
{
super(binder, String.class, valueClass);
this.valueClass = valueClass;
}
public void withGeneratedName()
{
ObjectNameFunction> namingFunction = new ObjectNameFunction>()
{
public ObjectName name(Map.Entry entry)
{
try {
return new ObjectName(ObjectNames.generatedNameOf(valueClass, entry.getKey()));
}
catch (MalformedObjectNameException e) {
throw Throwables.propagate(e);
}
}
};
binder.addBinding().toInstance(new MapMapping(String.class, valueClass, namingFunction));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy