YourKit Java Profiler |
JFacets /
ConfigurationEverything in JFacets is configured using the Spring Application Context. Components used, as well as their properties and dependencies, have to be specified in an XML Spring context that is loaded from the CLASSPATH in order to instanciate the JFacets bean (and everything it needs in order to work).
Of course, you don't have to change everything in the Spring context : most of it is already working and doesn't need any modification. The mandatory information that has to be provided is :
Here under is a Spring Context that allows the use of Java/XML and Groovy facets in the same application : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- A Spring Context for JFacets that already provides support for Java/XML and Groovy facets. Configurable stuff in there : * profileRepository : specify your implementation class (and config options if any) ; * xmlFacetDescriptorManager : specify the path the the XML file (CLASSPATH resource) ; * groovyFacetDescriptorManager : specify the base packages for Groovy facets discovery. --> <beans> <!-- --> <!-- ProfileRepository --> <!-- --> <!-- This *has* to be configured --> <!-- for your application. --> <!-- --> <bean id="profileRepository" singleton="true" class="net.sourceforge.jfacets.simpleprofiles.SimpleProfileRepository"> </bean> <!-- --> <!-- Facet Managers --> <!-- --> <!-- The config below allows to use --> <!-- both plain java and groovy --> <!-- facets in the same app. --> <!-- --> <!-- Look at each manager's config --> <!-- options. --> <!-- --> <!-- the XML facet descriptor manager --> <bean id="xmlFacetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.impl.FacetDescriptorManager"> <!-- The path to the XML Descriptor File (CLASSPATH resource) --> <constructor-arg index="0"><value>facets.xml</value></constructor-arg> </bean> <!-- the Groovy facet descriptor manager --> <bean id="groovyFacetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.groovy.GroovyFacetDescriptorManager" init-method="initialize"> <!-- A list of base packages to search into for Groovy Facets Discovery --> <constructor-arg index="0"> <list> <value>test-facets</value> </list> </constructor-arg> </bean> <!-- the Meta facet descriptor manager : wraps the two other ones --> <bean id="facetDescriptorManager" singleton="true" class="net.sourceforge.jfacets.impl.MetaFacetDescriptorManager" init-method="initialize"> <property name="managers"> <list> <ref bean="groovyFacetDescriptorManager"/> <ref bean="xmlFacetDescriptorManager"/> </list> </property> </bean> <!-- --> <!-- Facet & Facet Context factories --> <!-- --> <!-- No additional config is --> <!-- required here. --> <!-- --> <!-- a fall back factory, so that we can crate non-groovy facets too --> <bean id="fallbackFacetFactory" singleton="true" class="net.sourceforge.jfacets.impl.DefaultFacetFactory"> </bean> <!-- the main facet factory : creates GroovyFacets --> <bean id="facetFactory" singleton="true" class="net.sourceforge.jfacets.groovy.GroovyFacetFactory"> <property name="fallbackFactory"><ref bean="fallbackFacetFactory"/></property> </bean> <!-- the facet context factory (default one) --> <bean id="facetContextFactory" singleton="true" class="net.sourceforge.jfacets.impl.DefaultFacetContextFactory"> </bean> <!-- --> <!-- Facet Repository --> <!-- --> <!-- No additional config is required --> <!-- here. --> <!-- --> <bean id="facetRepository" singleton="true" class="net.sourceforge.jfacets.impl.FacetRepositoryImpl"> <constructor-arg index="0"><ref bean="profileRepository"/></constructor-arg> <constructor-arg index="1"><ref bean="facetFactory"/></constructor-arg> <constructor-arg index="2"><ref bean="facetContextFactory"/></constructor-arg> <constructor-arg index="3"><ref bean="facetDescriptorManager"/></constructor-arg> </bean> <!-- --> <!-- top-level JFacets bean --> <!-- --> <!-- No additional config is required --> <!-- here. --> <!-- --> <bean id="jFacets" singleton="true" class="net.sourceforge.jfacets.JFacets"> <property name="facetRepository"><ref bean="facetRepository"/></property> </bean> </beans> For more infos, check out the example contexts in the Extending JFacetsAs you can see, JFacets is pretty modular, thanks to IoC and factories. Of course, you could easily replace some parts of it in order to achieve something else. For a concrete example, you may have a look at WebFacets. It's an extension of JFacets for using facets in J2EE webapps, with e few added features (e.g. make all the http* stuff available in the facet context). |