YourKit Java Profiler |
JFacets /
InstanceFacetsFacets are assigned and searched for target types. You specify the facet's target type in its descriptor (annotation, XML, whatever), and at run time the type is used in order to lookup for the facet. JFacets also includes (as of v2.1) a mechanism that allows to write and use instance facets, that are bound to a target type but also depend on the target object's (instance) state. Writing Instance FacetsWriting instance facets is easy, you just have to implement the public boolean matchesTargetObject(Object targetObject); This callback method is invoked by JFacets when it traverses the profiles and types graphs in order to check wether or not the facets are matching for requested target object. This way, you can implement The following example shows a @FacetKey(name="confirm",profileId="ROLE_CUSTOMER",targetObjectType=Order.class) public class ConfirmOrderFacet implements IFacet, IInstanceFacet { public boolean matchesTargetObject(Object targetObject) { Order order = (Order)targetObject; return !order.isConfirmed(); } public void confirmOrder() { Order order = (Order)getContext().getTargetObject(); order.setConfirmed(true); ... } } Retrieving Instance FacetsRetrievement of instance facets is identical to retrievement of type-wide facets. All the job of selecting matching facets is done for you by JFacets when you invoke For more infos, have a look to the javadocs. |