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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReferences(Object[] tuples) Creates a new instance of references and initializes it with references. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()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 ReferencesfromTuples(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> TgetOneOptional(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> TgetOneRequired(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.voidPuts 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:
putin 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:
removein 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:
removeAllin 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:
getAllLocatorsin interfaceIReferences- Returns:
- a list with component locators.
-
getAll
Gets all component references registered in this reference map.- Specified by:
getAllin interfaceIReferences- Returns:
- a list with component references.
-
getOneOptional
Gets an optional component reference that matches specified locator.- Specified by:
getOneOptionalin 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:
getOneOptionalin 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:
getOneRequiredin 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:
getOneRequiredin 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:
getOptionalin 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:
getOptionalin 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:
getRequiredin 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:
getRequiredin 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:
findin 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:
findin 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.
-