Package jmri.managers

Class AbstractProvidingProxyManager<E extends NamedBean>

    • Method Detail

      • provideNamedBean

        @Nonnull
        protected E provideNamedBean​(java.lang.String name)
                              throws java.lang.IllegalArgumentException
        Locate via user name, then system name if needed. If that fails, create a new NamedBean: If the name is a valid system name, it will be used for the new NamedBean. Otherwise, the makeSystemName method will attempt to turn it into a valid system name. Subclasses use this to create provider methods such as getSensor or getTurnout via casts.
        Parameters:
        name - the user name or system name of the bean
        Returns:
        an existing or new NamedBean
        Throws:
        java.lang.IllegalArgumentException - if name is not usable in a bean
      • newNamedBean

        @Nonnull
        public E newNamedBean​(@Nonnull
                              java.lang.String systemName,
                              java.lang.String userName)
                       throws java.lang.IllegalArgumentException
        Return an instance with the specified user or system name.

        Lookup by UserName, then provide by System Name.

        Note that two calls with the same arguments will get the same instance; there is i.e. only one Sensor object representing a given physical sensor and therefore only one with a specific system or user name.

        This will always return a valid object reference for a valid request; a new object will be created if necessary. In that case:

        • If a null reference is given for user name, no user name will be associated with the NamedBean object created; a valid system name must be provided
        • If both names are provided, the system name defines the hardware access of the desired turnout, and the user address is associated with it.
        • If a matching UserName is located, that will be returned.
        • Else If a matching SystemName is located, that will be returned.
        • Else A New Bean will be created with the given System Name. The UserName will be added to the New Bean if no existing.
        Note that it is possible to make an inconsistent request if both addresses are provided, but the given values are associated with different objects. This is a problem, and we don't have a good solution except to issue warnings. This will mostly happen if you're creating NamedBean when you should be looking them up.

        If the System Name contains the start of a specified Manager, that will be used, else the default manager will be used.

        Parameters:
        systemName - the system name
        userName - the user name
        Returns:
        requested NamedBean object (never null)
        Throws:
        java.lang.IllegalArgumentException
        See Also:
        AbstractProxyManager.getManager(java.lang.String)
      • makeBean

        @Nonnull
        protected abstract E makeBean​(Manager<E> manager,
                                      @Nonnull
                                      java.lang.String systemName,
                                      java.lang.String userName)
                               throws java.lang.IllegalArgumentException
        Defer creation of the proper type to the subclass.
        Parameters:
        manager - the manager to invoke
        systemName - the system name
        userName - the user name
        Returns:
        a bean
        Throws:
        java.lang.IllegalArgumentException - if unable to make.