public class KnowledgeBaseServiceLocator extends Object
KnowledgeBase
.
Provides a way to implement a one-to-one relationship between a KnowledgeBase
and its services. i.e. A
KnowledgeBase
can be associated with one, and only one, RecordedDatabase
- and a
RecordedDatabase
can be associated with one, and only one, KnowledgeBase
.
Modifier and Type | Method and Description |
---|---|
void |
addInstance(Class<?> referenceType,
Object instance)
Adds the specified
instance with the specified referenceType as its key. |
<T> T |
getInstance(Class<?> instanceType)
Returns the
Object associated the specified instanceType . |
<T> T |
getInstance(Class<?> referenceType,
Class<?> instanceType)
Returns the
Object associated the specified referenceType . |
static KnowledgeBaseServiceLocator |
getServiceLocator(KnowledgeBase kb)
Returns the
KnowledgeBaseServiceLocator associated with the specified KnowledgeBase . |
public static KnowledgeBaseServiceLocator getServiceLocator(KnowledgeBase kb)
KnowledgeBaseServiceLocator
associated with the specified KnowledgeBase
.
If no KnowledgeBaseServiceLocator
is already associated with the specified KnowledgeBase
then a
new KnowledgeBaseServiceLocator
will be created.
public void addInstance(Class<?> referenceType, Object instance)
instance
with the specified referenceType
as its key.IllegalArgumentException
- If instance
is not an instance of ReferenceType
.IllegalStateException
- If there is already a service associated with referenceType
.public <T> T getInstance(Class<?> instanceType)
Object
associated the specified instanceType
.
If no Object
is already associated with instanceType
then a new instance of instanceType
will be created and associated with instanceType
for future use.
RuntimeException
- if an attempt to instantiate a new instance of the instanceType
fails. e.g. If it
does not have a public constructor that accepts either no arguments or a single KnowledgeBase
argument.public <T> T getInstance(Class<?> referenceType, Class<?> instanceType)
Object
associated the specified referenceType
.
If no Object
is already associated with referenceType
then a new instance of instanceType
will be created and associated with referenceType
for future use.
referenceType
- The class to use as the key to retrieve an existing service.instanceType
- The class to create a new instance of if there is no existing service associated with
referenceType
.RuntimeException
- If an attempt to instantiate a new instance of the instanceType
fails. e.g. If
instanceType
does not have a public constructor that accepts either no arguments or a single
KnowledgeBase
argument - or if referenceType
is not the same as, nor is a superclass or
superinterface of, instanceType
.Copyright © 2024. All rights reserved.