Class Model

java.lang.Object
org.puremvc.java.core.Model
All Implemented Interfaces:
IModel

public class Model
extends java.lang.Object
implements IModel

A Singleton IModel implementation.

In PureMVC, the Model class provides access to model objects (Proxies) by named lookup.

The Model assumes these responsibilities:

  • Maintain a cache of IProxy instances.
  • Provide methods for registering, retrieving, and removing IProxy instances.

Your application must register IProxy instances with the Model. Typically, you use an ICommand to create and register IProxy instances once the Facade has initialized the Core actors.

See Also:
Proxy, IProxy
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static IModel instance  
    protected java.util.concurrent.ConcurrentMap<java.lang.String,​IProxy> proxyMap  
    protected java.lang.String SINGLETON_MSG  
  • Constructor Summary

    Constructors 
    Constructor Description
    Model()
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    static IModel getInstance​(java.util.function.Supplier<IModel> factory)
    Model Singleton Factory method.
    boolean hasProxy​(java.lang.String proxyName)
    Check if a Proxy is registered
    protected void initializeModel()
    Initialize the Singleton Model instance.
    void registerProxy​(IProxy proxy)
    Register an IProxy with the Model.
    IProxy removeProxy​(java.lang.String proxyName)
    Remove an IProxy from the Model.
    IProxy retrieveProxy​(java.lang.String proxyName)
    Retrieve an IProxy from the Model.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Model

      public Model()

      Constructor.

      This IModel implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method Model.getInstance()

      Throws:
      java.lang.Error - Error if Singleton instance has already been constructed
  • Method Details

    • initializeModel

      protected void initializeModel()

      Initialize the Singleton Model instance.

      Called automatically by the constructor, this is your opportunity to initialize the Singleton instance in your subclass without overriding the constructor.

    • getInstance

      public static IModel getInstance​(java.util.function.Supplier<IModel> factory)

      Model Singleton Factory method.

      Parameters:
      factory - model supplier function
      Returns:
      the Singleton instance
    • registerProxy

      public void registerProxy​(IProxy proxy)

      Register an IProxy with the Model.

      Specified by:
      registerProxy in interface IModel
      Parameters:
      proxy - an IProxy to be held by the Model.
    • retrieveProxy

      public IProxy retrieveProxy​(java.lang.String proxyName)

      Retrieve an IProxy from the Model.

      Specified by:
      retrieveProxy in interface IModel
      Parameters:
      proxyName - proxy name
      Returns:
      the IProxy instance previously registered with the given proxyName.
    • hasProxy

      public boolean hasProxy​(java.lang.String proxyName)

      Check if a Proxy is registered

      Specified by:
      hasProxy in interface IModel
      Parameters:
      proxyName - proxy name
      Returns:
      whether a Proxy is currently registered with the given proxyName.
    • removeProxy

      public IProxy removeProxy​(java.lang.String proxyName)

      Remove an IProxy from the Model.

      Specified by:
      removeProxy in interface IModel
      Parameters:
      proxyName - name of the IProxy instance to be removed.
      Returns:
      the IProxy that was removed from the Model