YourKit Java Profiler |
JFacets /
UsingFacetsUsing facets from Java code is very simple. You simply have to :
Obtaining the JFacets top-level objectThe JFacets class produces instances that act as the top-level object that you use in JFacets applications. It basically allows to retrieve facets at runtime. In order to work, the JFacets instances need collaborators, like explained in Architecture. You can wire them all yourself, or use a D.I. system like Spring. As of v3.0, ships with a Builder (JFacetsBuilder) that eases creation of the bean : // need profile repo IProfileRepository profileRepository = new MyProfileRepository(); // and facet descriptor manager (here we use annotated facets) List<String> packages = Arrays.asList("com.xyz.myapp.facets"); AnnotatedFacetDescriptorManager facetDescriptorManager = new AnnotatedFacetDescriptorManager(packages); // get JFacets bean using the builder JFacets jFacets = new JFacetsBuilder( profileRepository, facetDescriptorManager). build(); Retrieving and Executing facetsOnce you have a reference on the JFacets bean, you can use it to retrieve and use facets : // the profile ID String profileId = ... ; // the target object MyClass o = ... ; // retrieve a facet and use it MyFacet f = (MyFacet)jFacets.getFacet("doSomething", profileId, o); f.doStuff();
|