Class KnowledgeBaseServiceLocator
java.lang.Object
org.projog.core.kb.KnowledgeBaseServiceLocator
Associates arbitrary objects with a
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstance(Class<?> referenceType, Object instance) Adds the specifiedinstancewith the specifiedreferenceTypeas its key.<T> TgetInstance(Class<?> instanceType) Returns theObjectassociated the specifiedinstanceType.<T> TgetInstance(Class<?> referenceType, Class<?> instanceType) Returns theObjectassociated the specifiedreferenceType.static KnowledgeBaseServiceLocatorReturns theKnowledgeBaseServiceLocatorassociated with the specifiedKnowledgeBase.
-
Method Details
-
getServiceLocator
Returns theKnowledgeBaseServiceLocatorassociated with the specifiedKnowledgeBase.If no
KnowledgeBaseServiceLocatoris already associated with the specifiedKnowledgeBasethen a newKnowledgeBaseServiceLocatorwill be created. -
addInstance
Adds the specifiedinstancewith the specifiedreferenceTypeas its key.- Throws:
IllegalArgumentException- Ifinstanceis not an instance ofReferenceType.IllegalStateException- If there is already a service associated withreferenceType.
-
getInstance
Returns theObjectassociated the specifiedinstanceType.If no
Objectis already associated withinstanceTypethen a new instance ofinstanceTypewill be created and associated withinstanceTypefor future use.- Throws:
RuntimeException- if an attempt to instantiate a new instance of theinstanceTypefails. e.g. If it does not have a public constructor that accepts either no arguments or a singleKnowledgeBaseargument.
-
getInstance
Returns theObjectassociated the specifiedreferenceType.If no
Objectis already associated withreferenceTypethen a new instance ofinstanceTypewill be created and associated withreferenceTypefor future use.- Parameters:
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 withreferenceType.- Throws:
RuntimeException- If an attempt to instantiate a new instance of theinstanceTypefails. e.g. IfinstanceTypedoes not have a public constructor that accepts either no arguments or a singleKnowledgeBaseargument - or ifreferenceTypeis not the same as, nor is a superclass or superinterface of,instanceType.
-