Class 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.
-
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 registeredprotected void
initializeModel()
Initialize the SingletonModel
instance.void
registerProxy(IProxy proxy)
Register anIProxy
with theModel
.IProxy
removeProxy(java.lang.String proxyName)
Remove anIProxy
from theModel
.IProxy
retrieveProxy(java.lang.String proxyName)
Retrieve anIProxy
from theModel
.
-
Field Details
-
proxyMap
-
instance
-
SINGLETON_MSG
protected final java.lang.String SINGLETON_MSG- See Also:
- Constant Field Values
-
-
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 methodModel.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
Model
Singleton Factory method.- Parameters:
factory
- model supplier function- Returns:
- the Singleton instance
-
registerProxy
Register an
IProxy
with theModel
.- Specified by:
registerProxy
in interfaceIModel
- Parameters:
proxy
- anIProxy
to be held by theModel
.
-
retrieveProxy
Retrieve an
IProxy
from theModel
.- Specified by:
retrieveProxy
in interfaceIModel
- Parameters:
proxyName
- proxy name- Returns:
- the
IProxy
instance previously registered with the givenproxyName
.
-
hasProxy
public boolean hasProxy(java.lang.String proxyName)Check if a Proxy is registered
-
removeProxy
Remove an
IProxy
from theModel
.- Specified by:
removeProxy
in interfaceIModel
- Parameters:
proxyName
- name of theIProxy
instance to be removed.- Returns:
- the
IProxy
that was removed from theModel
-