001package jmri.jmrit.logixng.actions;
002
003import jmri.*;
004
005/**
006 * Defines types of NamedBeans, for example Turnout and Light.
007 * 
008 * @author Daniel Bergqvist Copyright 2019
009 */
010public enum NamedBeanType {
011    Light(Bundle.getMessage("BeanNameLight"), Light.class, "KnownState", () -> {
012        return InstanceManager.getDefault(LightManager.class);
013    }),
014    Memory(Bundle.getMessage("BeanNameMemory"), Memory.class, "value", () -> {
015        return InstanceManager.getDefault(MemoryManager.class);
016    }),
017    Sensor(Bundle.getMessage("BeanNameSensor"), Sensor.class, "KnownState", () -> {
018        return InstanceManager.getDefault(SensorManager.class);
019    }),
020    Turnout(Bundle.getMessage("BeanNameTurnout"), Turnout.class, "KnownState", () -> {
021        return InstanceManager.getDefault(TurnoutManager.class);
022    });
023    
024    private final String _name;
025    private final Class<? extends NamedBean> _clazz;
026    private final String _propertyName;
027    private final GetManager _getManager;
028    private Manager<? extends NamedBean> _manager;
029
030    NamedBeanType(String name, Class<? extends NamedBean> clazz, String propertyName, GetManager getManager) {
031        _name = name;
032        _clazz = clazz;
033        _propertyName = propertyName;
034        _getManager = getManager;
035        _manager = _getManager.getManager();
036    }
037
038    @Override
039    public String toString() {
040        return _name;
041    }
042
043    public Class<? extends NamedBean> getClazz() {
044        return _clazz;
045    }
046
047    public String getPropertyName() {
048        return _propertyName;
049    }
050
051    public Manager<? extends NamedBean> getManager() {
052        return _manager;
053    }
054
055    // This method is used by test classes to reset this enum.
056    // Each test resets the InstanceManager so we need to reset the
057    // managers in this enum.
058    public static void reset() {
059        for (NamedBeanType type : NamedBeanType.values()) {
060            type._manager = type._getManager.getManager();
061        }
062    }
063
064    private interface GetManager {
065
066        Manager<? extends NamedBean> getManager();
067    }
068    
069}