001package jmri.managers;
002
003import javax.annotation.CheckForNull;
004import javax.annotation.Nonnull;
005
006import jmri.*;
007import jmri.jmrix.internal.InternalSystemConnectionMemo;
008
009import java.util.Objects;
010
011/**
012 * Abstract partial implementation of a SignalHeadManager.
013 * <p>
014 * Not truly an abstract class, this might have been better named
015 * DefaultSignalHeadManager. But we've got it here for the eventual need to
016 * provide system-specific implementations.
017 * <p>
018 * Note that this does not enforce any particular system naming convention at
019 * the present time. They're just names...
020 *
021 * @author Bob Jacobsen Copyright (C) 2003
022 */
023public class AbstractSignalHeadManager extends AbstractManager<SignalHead>
024        implements SignalHeadManager {
025
026    public AbstractSignalHeadManager(InternalSystemConnectionMemo memo) {
027        super(memo);
028        init();
029    }
030    
031    final void init(){
032        InstanceManager.getDefault(TurnoutManager.class).addVetoableChangeListener(this);
033    }
034
035    /** {@inheritDoc} */
036    @Override
037    public int getXMLOrder() {
038        return Manager.SIGNALHEADS;
039    }
040
041    /** {@inheritDoc} */
042    @Override
043    public char typeLetter() {
044        return 'H';
045    }
046
047    /** {@inheritDoc} */
048    @Override
049    @CheckForNull
050    public SignalHead getSignalHead(@Nonnull String name) {
051        Objects.requireNonNull(name, "SignalHead name cannot be null.");  // NOI18N
052        if (name.trim().length() == 0) {
053            return null;
054        }
055        SignalHead t = getByUserName(name);
056        if (t != null) {
057            return t;
058        }
059        return getBySystemName(name);
060    }
061
062    /** {@inheritDoc} */
063    @Override
064    @Nonnull
065    public String getBeanTypeHandled(boolean plural) {
066        return Bundle.getMessage(plural ? "BeanNameSignalHeads" : "BeanNameSignalHead");
067    }
068
069    /**
070     * {@inheritDoc}
071     */
072    @Override
073    public Class<SignalHead> getNamedBeanClass() {
074        return SignalHead.class;
075    }
076    
077    @Override
078    public void dispose(){
079        InstanceManager.getDefault(TurnoutManager.class).removeVetoableChangeListener(this);
080        super.dispose();
081    }
082
083}