T - type of the service that user registers to be processed by Whiteboard extender (whether standard
OSGi CMPN Whiteboard or Pax Web specific Whiteboard extender)D - type of the DTO-like object that carries registration information of real service - to be able
to get notified about (un)registration without the way to change actual registration datapublic abstract class ElementModel<T,D extends WebElementEventData> extends Identity implements Comparable<ElementModel<T,D>>
Base class for all models representing actual elements of a web application (or
context), the most obvious model is representing Servlet.
What user does (through HttpService or by publishing Whiteboard services) is
a registration of web elements (like servlets) always within the context of ... well, a context
(possibly many, as permitted by Whiteboard Service specification).
A context is not an element itself (thus - not a model), it's rather:
ServletContext from server point of viewHttpContext or
ServletContextHelper) providing additional/bridged functionality,
when delegating some of it to actual ServletContextEach element, when registered through Whiteboard Service, may turn out to unregister some existing
element when it uses conflicting URL mapping but has lower ranking or service id. Such conflicts lead
to trivial NamespaceException when using Http Service.
| Modifier and Type | Field and Description |
|---|---|
protected List<OsgiContextModel> |
contextModels
List of
osgi contexts with which given ElementModel is associated. |
protected String |
contextModelsInfo |
protected int |
dtoFailureCode
If there's any failure during the lifetime of the context, we can provide a failure DTO information here.
|
protected Boolean |
isValid |
| Constructor and Description |
|---|
ElementModel() |
| Modifier and Type | Method and Description |
|---|---|
void |
addContextModel(OsgiContextModel model)
This method is used to add
OsgiContextModel when an ElementModel is created for the first
time (whether it's Whiteboard or HttpService scenario). |
abstract D |
asEventData()
When sending events related to
ElementModel we can't use the same instance which is kept in
ServerModel, we have to copy relevant
information to lightweight object. |
void |
changeContextModels(List<OsgiContextModel> models)
This method replaces the models for existing when conditions change (when for example
new
OsgiContextModel is registered and element should be registered to it after it was already
registered to other context matching the context selector). |
int |
compareTo(ElementModel<T,D> o)
Returns negative value if this element is "lesser" than the argument, which means it should have higher
priority.
|
boolean |
equals(Object o) |
org.osgi.framework.Filter |
getContextFilter() |
List<OsgiContextModel> |
getContextModels()
Get unmodifiable list of
osgi models with which given ElementModel
should be associated during registration. |
String |
getContextModelsInfo() |
String |
getContextSelector() |
int |
getDtoFailureCode() |
org.osgi.framework.ServiceReference<T> |
getElementReference() |
Supplier<? extends T> |
getElementSupplier() |
org.osgi.framework.Bundle |
getRegisteringBundle() |
long |
getServiceId() |
int |
getServiceRank() |
long |
getTimestamp() |
boolean |
hasContextModels() |
int |
hashCode() |
boolean |
isAsynchronusRegistration() |
boolean |
isPrototype()
Should be used only when
getElementReference() returns non-null value. |
boolean |
isValid()
This method should be called from Whiteboard infrastructure to really perform the validation and set
isValid flag, which is then used for "Failure DTO" purposes.
|
abstract Boolean |
performValidation()
Perform element-specific validation and throws different exceptions for all element-specific validation
problems.
|
abstract void |
register(WhiteboardWebContainerView view)
Each
ElementModel can register itself as Whiteboard element. |
void |
resetContextModels()
Method used when Whiteboard service changes its registration properties
|
void |
setAsynchronusRegistration(boolean async) |
protected void |
setCommonEventProperties(WebElementEventData data)
Set
ElementModel information in WebElementEventData - to be called in specializations
of asEventData() method. |
void |
setContextSelectFilter(org.osgi.framework.Filter contextFilter)
Method corresponding to
ContextRelated.getContextSelectFilter() that sets actual context-selection
Filter to be used for this ElementModel after customizing incoming user-registered
OSGi service. |
void |
setContextSelector(String mappingSelector)
Some Whiteboard services specify context selector using
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT service
registration property and some (legacy) using ContextRelated.getContextId()/ContextRelated.getContextSelectFilter(). |
void |
setDtoFailureCode(int dtoFailureCode) |
void |
setElementReference(org.osgi.framework.ServiceReference<T> elementReference) |
void |
setElementSupplier(Supplier<? extends T> elementSupplier) |
void |
setRegisteringBundle(org.osgi.framework.Bundle registeringBundle) |
void |
setServiceId(long serviceId) |
void |
setServiceRank(int serviceRank) |
void |
setTimestamp(long timestamp) |
String |
toString() |
abstract void |
unregister(WhiteboardWebContainerView view)
Each
ElementModel can unregister itself as Whiteboard element. |
getId, getIdPrefix, getNumericIdprotected List<OsgiContextModel> contextModels
osgi contexts with which given ElementModel is associated.
This list may be altered using addContextModel(OsgiContextModel), but on first invocation of
getContextModels(), this list is latched, sorted and can't be modified any further.protected String contextModelsInfo
protected Boolean isValid
protected int dtoFailureCode
public boolean isValid()
This method should be called from Whiteboard infrastructure to really perform the validation and set isValid flag, which is then used for "Failure DTO" purposes.
public abstract Boolean performValidation() throws Exception
Perform element-specific validation and throws different exceptions for all element-specific validation problems. This method should not be called for Whiteboard purposes, where "failure DTO" has to be configured.
This method should be called in Http Service scenario where we immediately need strong feedback - with exceptions thrown for all validation problems. In Whiteboard scenario, the exception is caught, logged and it's the tracker that prevents further registration.
This method may alter the state of the model when (which is possible during validation) some extra information is obtained/compiled/processed.
Exceptionpublic List<OsgiContextModel> getContextModels()
osgi models with which given ElementModel
should be associated during registration.public String getContextModelsInfo()
public void addContextModel(OsgiContextModel model)
OsgiContextModel when an ElementModel is created for the first
time (whether it's Whiteboard or HttpService scenario).model - public void changeContextModels(List<OsgiContextModel> models)
OsgiContextModel is registered and element should be registered to it after it was already
registered to other context matching the context selector).public void resetContextModels()
public abstract void register(WhiteboardWebContainerView view)
ElementModel can register itself as Whiteboard element.view - public abstract void unregister(WhiteboardWebContainerView view)
ElementModel can unregister itself as Whiteboard element.view - public abstract D asEventData()
ElementModel we can't use the same instance which is kept in
ServerModel, we have to copy relevant
information to lightweight object.protected void setCommonEventProperties(WebElementEventData data)
ElementModel information in WebElementEventData - to be called in specializations
of asEventData() method.data - public boolean hasContextModels()
public int getServiceRank()
public void setServiceRank(int serviceRank)
public long getServiceId()
public void setServiceId(long serviceId)
public long getTimestamp()
public void setTimestamp(long timestamp)
public org.osgi.framework.ServiceReference<T> getElementReference()
public void setElementReference(org.osgi.framework.ServiceReference<T> elementReference)
public boolean isPrototype()
getElementReference() returns non-null value.public org.osgi.framework.Bundle getRegisteringBundle()
public void setRegisteringBundle(org.osgi.framework.Bundle registeringBundle)
public void setContextSelector(String mappingSelector)
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT service
registration property and some (legacy) using ContextRelated.getContextId()/ContextRelated.getContextSelectFilter().
After setting the selector, we no longer have to resolve one.mappingSelector - public String getContextSelector()
public void setContextSelectFilter(org.osgi.framework.Filter contextFilter)
Method corresponding to ContextRelated.getContextSelectFilter() that sets actual context-selection
Filter to be used for this ElementModel after customizing incoming user-registered
OSGi service.
This filter can be changed only by calling ServiceRegistration.setProperties(Dictionary)
on existing registration, but it's rather rare scenario. The point is that this filter is called every time
new OsgiContextModel is tracked (or changed or removed) to check whether existing set of contexts
associated with given ElementModel has changed - to check whether this ElementModel should
be added to new or removed from existing contexts (or both)
contextFilter - public org.osgi.framework.Filter getContextFilter()
public int getDtoFailureCode()
public void setDtoFailureCode(int dtoFailureCode)
public void setAsynchronusRegistration(boolean async)
public boolean isAsynchronusRegistration()
public int compareTo(ElementModel<T,D> o)
compareTo in interface Comparable<ElementModel<T,D extends WebElementEventData>>o - Copyright © 2006–2024 OPS4J - Open Participation Software for Java. All rights reserved.