Recent Changes - Search:


SourceForge Logo









YourKit Java Profiler

UsingFacets

Using facets from Java code is very simple. You simply have to :

  • get hold of a JFacets instance ;
  • invoke the bean's getFacet(...) methods.

Obtaining the JFacets top-level object

The 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 facets

Once 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();

NOTE
You have other ways to use facets if you develop J2EE webapps. Take a look at the WebFacets docs for more infos about this.

Edit - History - Print - Recent Changes - Search
Page last modified on April 11, 2009, at 11:12 PM