All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.weakref.jmx.guice.StringMapExportBinder Maven / Gradle / Ivy

There is a newer version: 1.26
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy