Package org.pipservices3.commons.refer
Class References
java.lang.Object
org.pipservices3.commons.refer.References
- All Implemented Interfaces:
IReferences
The most basic implementation of
IReferences
to store and locate component references.
### Example ###
public class MyController implements IReferenceable {
public IMyPersistence _persistence;
...
public void setReferences(IReferences references) {
this._persistence = (IMyPersistence)references.getOneRequired(
new Descriptor("mygroup", "persistence", "*", "*", "1.0")
);
}
...
}
MyMongoDbPersistence persistence = new MyMongoDbPersistence();
MyController controller = new MyController();
References references = References.fromTuples(
new Descriptor("mygroup", "persistence", "mongodb", "default", "1.0"), persistence,
new Descriptor("mygroup", "controller", "default", "default", "1.0"), controller
);
controller.setReferences(references);
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionReferences
(Object[] tuples) Creates a new instance of references and initializes it with references. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the references list<T> List<T>
Gets all component references that match specified locator and matching to the specified type.Gets all component references that match specified locator.static References
fromTuples
(Object... tuples) Creates a new References from a list of key-value pairs called tuples.getAll()
Gets all component references registered in this reference map.Gets locators for all registered component references in this reference map.<T> T
getOneOptional
(Class<T> type, Object locator) Gets an optional component reference that matches specified locator and matching to the specified type.getOneOptional
(Object locator) Gets an optional component reference that matches specified locator.<T> T
getOneRequired
(Class<T> type, Object locator) Gets a required component reference that matches specified locator and matching to the specified type.getOneRequired
(Object locator) Gets a required component reference that matches specified locator.<T> List<T>
getOptional
(Class<T> type, Object locator) Gets all component references that match specified locator and matching to the specified type.getOptional
(Object locator) Gets all component references that match specified locator.<T> List<T>
getRequired
(Class<T> type, Object locator) Gets all component references that match specified locator.getRequired
(Object locator) Gets all component references that match specified locator.void
Puts a new reference into this reference map.Removes a previously added reference that matches specified locator.Removes all component references that match the specified locator.
-
Field Details
-
_references
-
_lock
-
-
Constructor Details
-
References
public References() -
References
Creates a new instance of references and initializes it with references.- Parameters:
tuples
- (optional) a list of values where odd elements are locators and the following even elements are component references
-
-
Method Details
-
put
Puts a new reference into this reference map.- Specified by:
put
in interfaceIReferences
- Parameters:
locator
- a locator to find the reference by.component
- a component reference to be added.- Throws:
NullPointerException
-
remove
Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll() method instead.- Specified by:
remove
in interfaceIReferences
- Parameters:
locator
- a locator to remove reference- Returns:
- the removed component reference.
- See Also:
-
removeAll
Removes all component references that match the specified locator.- Specified by:
removeAll
in interfaceIReferences
- Parameters:
locator
- the locator to remove references by.- Returns:
- a list, containing all removed references.
-
getAllLocators
Gets locators for all registered component references in this reference map.- Specified by:
getAllLocators
in interfaceIReferences
- Returns:
- a list with component locators.
-
getAll
Gets all component references registered in this reference map.- Specified by:
getAll
in interfaceIReferences
- Returns:
- a list with component references.
-
getOneOptional
Gets an optional component reference that matches specified locator.- Specified by:
getOneOptional
in interfaceIReferences
- Parameters:
locator
- the locator to find references by.- Returns:
- a matching component reference or null if nothing was found.
-
getOneOptional
Gets an optional component reference that matches specified locator and matching to the specified type.- Specified by:
getOneOptional
in interfaceIReferences
- Parameters:
type
- the Class type that defined the type of the result.locator
- the locator to find references by.- Returns:
- a matching component reference or null if nothing was found.
-
getOneRequired
Gets a required component reference that matches specified locator.- Specified by:
getOneRequired
in interfaceIReferences
- Parameters:
locator
- the locator to find a reference by.- Returns:
- a matching component reference.
- Throws:
ReferenceException
- when no references found.
-
getOneRequired
Gets a required component reference that matches specified locator and matching to the specified type.- Specified by:
getOneRequired
in interfaceIReferences
- Parameters:
type
- the Class type that defined the type of the result.locator
- the locator to find a reference by.- Returns:
- a matching component reference.
- Throws:
ReferenceException
- when no references found.
-
getOptional
Gets all component references that match specified locator.- Specified by:
getOptional
in interfaceIReferences
- Parameters:
locator
- the locator to find references by.- Returns:
- a list with matching component references or empty list if nothing was found.
-
getOptional
Gets all component references that match specified locator and matching to the specified type.- Specified by:
getOptional
in interfaceIReferences
- Parameters:
type
- the Class type that defined the type of the result.locator
- the locator to find references by.- Returns:
- a list with matching component references or empty list if nothing was found.
-
getRequired
Gets all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error.- Specified by:
getRequired
in interfaceIReferences
- Parameters:
locator
- the locator to find references by.- Returns:
- a list with matching component references.
- Throws:
ReferenceException
- when no references found.
-
getRequired
Gets all component references that match specified locator. At least one component reference must be present and matching to the specified type.If it doesn't the method throws an error.
- Specified by:
getRequired
in interfaceIReferences
- Parameters:
type
- the Class type that defined the type of the result.locator
- the locator to find references by.- Returns:
- a list with matching component references.
- Throws:
ReferenceException
- when no references found.
-
find
Gets all component references that match specified locator.- Specified by:
find
in interfaceIReferences
- Parameters:
locator
- the locator to find a reference by.required
- forces to raise an exception if no reference is found.- Returns:
- a list with matching component references.
- Throws:
ReferenceException
- when required is set to true but no references found.
-
find
Gets all component references that match specified locator and matching to the specified type.- Specified by:
find
in interfaceIReferences
- Parameters:
type
- the Class type that defined the type of the result.locator
- the locator to find a reference by.required
- forces to raise an exception if no reference is found.- Returns:
- a list with matching component references.
- Throws:
ReferenceException
- when required is set to true but no references found.
-
clear
public void clear()Clear the references list -
fromTuples
Creates a new References from a list of key-value pairs called tuples.- Parameters:
tuples
- a list of values where odd elements are locators and the following even elements are component references- Returns:
- a newly created References.
- Throws:
ReferenceException
- when no references found.
-