Class BazaarImpl<T>
- java.lang.Object
-
- org.eclipse.emfforms.bazaar.internal.BazaarImpl<T>
-
- Type Parameters:
T- the type of product produced by thisBazaar
- All Implemented Interfaces:
Bazaar<T>
- Direct Known Subclasses:
ThreadSafeBazaar
public class BazaarImpl<T> extends java.lang.Object implements Bazaar<T>
Implementation of aBazaarusing theIEclipseContextfor dependency injection.- Author:
- jonas
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.emfforms.bazaar.Bazaar
Bazaar.Builder<T>, Bazaar.PriorityOverlapCallBack<T>
-
-
Constructor Summary
Constructors Constructor Description BazaarImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContextFunction(java.lang.String key, BazaarContextFunction contextFunction)Adds aBazaarContextFunctionto thisBazaarto exchange existing parameters to a parameter requested by aVendor.org.eclipse.e4.core.contexts.IEclipseContextaddContextFunctions(org.eclipse.e4.core.contexts.IEclipseContext context)Transforms allBazaarContextFunctions toIContextFunctions and attaches those to anIEclipseContext.voidaddVendor(Vendor<? extends T> vendor)Adds aVendorto the bazaar.booleancheckPreConditions(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)Checks thePreconditions for a given vendor.org.eclipse.e4.core.contexts.IEclipseContextcreateEclipseContext(BazaarContext bazaarContext)Creates anIEclipseContextfrom aBazaarContext.TcreateProduct(BazaarContext bazaarContext)Creates a product of type T, provided by theVendorwith the highestBidand which is statisfied by the parameters in theBazaarContext.TcreateProduct(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)Returns the product which is provided with the highest priority by anyVendor.java.util.List<T>createProducts(BazaarContext bazaarContext)Creates a list of products of type T, provided byVendors which are statisfied by the parameters in theBazaarContext, ordered by theirBid.Vendor<? extends T>getBestVendor(org.eclipse.e4.core.contexts.IEclipseContext context)voidremoveVendor(Vendor<? extends T> vendor)Removes aVendorfrom the bazaar.voidsetPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
-
-
-
Method Detail
-
addVendor
public void addVendor(Vendor<? extends T> vendor)
Description copied from interface:BazaarAdds aVendorto the bazaar. Will be queried if a product is requested, the best fitting will create the product. Has no effect if thevendoris already present in this bazaar.
-
removeVendor
public void removeVendor(Vendor<? extends T> vendor)
Description copied from interface:BazaarRemoves aVendorfrom the bazaar. Has no effect if thevendoris not present in this bazaar.- Specified by:
removeVendorin interfaceBazaar<T>- Parameters:
vendor- theVendorto remove
-
createProduct
public T createProduct(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Returns the product which is provided with the highest priority by anyVendor.
-
addContextFunctions
public org.eclipse.e4.core.contexts.IEclipseContext addContextFunctions(org.eclipse.e4.core.contexts.IEclipseContext context)
Transforms allBazaarContextFunctions toIContextFunctions and attaches those to anIEclipseContext.- Parameters:
context- theIEclipseContextto attacheIContextFunctions to- Returns:
- the
IEclipseContextwith attachedIContextFunction
-
createEclipseContext
public org.eclipse.e4.core.contexts.IEclipseContext createEclipseContext(BazaarContext bazaarContext)
Creates anIEclipseContextfrom aBazaarContext. If the bazaar context contains an Eclipse context, then it is used and will have all other values set into it from the bazaar context.- Parameters:
bazaarContext- theBazaarContextto get key / values from- Returns:
- a
IEclipseContextcontainign all key / values provided by theBazaarContext
-
getBestVendor
public Vendor<? extends T> getBestVendor(org.eclipse.e4.core.contexts.IEclipseContext context)
- Parameters:
context- the Eclipse injection context- Returns:
- obtains the best available vendor for the give
context
-
setPriorityOverlapCallBack
public void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Description copied from interface:Bazaar- Specified by:
setPriorityOverlapCallBackin interfaceBazaar<T>- Parameters:
priorityOverlapCallBack- a PriorityOverlapCallBack
-
addContextFunction
public void addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)Description copied from interface:BazaarAdds aBazaarContextFunctionto thisBazaarto exchange existing parameters to a parameter requested by aVendor.- Specified by:
addContextFunctionin interfaceBazaar<T>- Parameters:
key-contextFunction-
-
createProduct
public T createProduct(BazaarContext bazaarContext)
Description copied from interface:BazaarCreates a product of type T, provided by theVendorwith the highestBidand which is statisfied by the parameters in theBazaarContext. In case of tied bids, theBazaar.PriorityOverlapCallBackif one is set will be notified of which vendor is chosen to break the tie. Note that during the bidding process, ties may have to be broken in this way that are later defeated by a higher bid.- Specified by:
createProductin interfaceBazaar<T>- Parameters:
bazaarContext- theBazaarContext, which is used to provide requested parameters forVendor- Returns:
- the product provided by the best
Vendor - See Also:
Bazaar.createProduct(org.eclipse.emfforms.bazaar.BazaarContext)
-
createProducts
public java.util.List<T> createProducts(BazaarContext bazaarContext)
Description copied from interface:BazaarCreates a list of products of type T, provided byVendors which are statisfied by the parameters in theBazaarContext, ordered by theirBid. Ties are not broken as all bids are successful and are used only for ordering.- Specified by:
createProductsin interfaceBazaar<T>- Parameters:
bazaarContext- theBazaarContext, which is used to provide requested parameters forVendor- Returns:
- a list of products ordered by the highest
Bid - See Also:
Bazaar.createProducts(org.eclipse.emfforms.bazaar.BazaarContext)
-
checkPreConditions
public boolean checkPreConditions(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Checks thePreconditions for a given vendor.- Parameters:
vendor- TheVendorto check thePreconditionfor.context- TheIEclipseContextto provide thePrecondition- Returns:
- whether the
Preconditions are fulfilled
-
-