Recent Changes - Search:


SourceForge Logo









YourKit Java Profiler

UsingFacets

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

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

Obtaining the JFacets top-level object

The JFacets bean is the top-level object that you use in JFacets applications. It allows retrievement and execution of facets (see below).

It's a Spring Bean, so if you're familiar with Spring, you can get a reference to it directly from the JFacets Application Context. It also proposes static methods in order to use it without dealing with Spring. Depending on your project, you can choose one or the other option.

The "Spring" way :

// get the jFacets bean from the Spring context
ApplicationContext c = ... ;
JFacets jFacets = (JFacets)c.getBean("jFacets");

The "static method" way :

// get the jFacets bean using a static method

// using the default app context name
JFacets jFacets = JFacets.get();

// or specifying another app context
JFacets jFacets = JFacets.get("/myAppCtx.xml");

Retrieving and Executing facets

Once you have a reference on the JFacets bean, you can use it to retrieve and use facets :

// get the jFacets bean
JFacets jFacets = JFacets.get();

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

If your facet implements IExecutable (or if it's a Plain Groovy Script), you can directly execute it like this :

// get the jFacets bean
JFacets jFacets = JFacets.get();

// the profile ID
String profileId = ... ;
// the target object
MyClass o = ... ;

// retrieve and execute a facet
MyResult result = (MyResult)jFacets.execFacet("doSomething", profileId, o);
result.xyz();

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 September 01, 2006, at 04:52 PM