net.sourceforge.jfacets
Class JFacets

java.lang.Object
  extended by net.sourceforge.jfacets.JFacets

public class JFacets
extends java.lang.Object

Top-level class for clients : used for retrieving facets at run time (see the getFacet(...) methods). The lifecycle of instances of this class goes like :

The preferred way to obtain a JFacets instance is to use the JFacetsBuilder.

Author:
Remi VANKEISBELCK - rvkb.com (remi 'at' rvkb.com)

Field Summary
private  IFacetRepository facetRepository
          The facet repository to be used for facet lookup.
private  java.lang.String fallbackProfileId
          The fallback profile to be used in case get/execFacet is invoked with a null profile or no principal associated to the current request.
private static JFacetsLogger logger
           
private  java.util.concurrent.ConcurrentHashMap<java.lang.String,IProfile> profilesCache
          The cache of already obtained profiles.
private  boolean useProfilesCache
          Indicates wether or not to use cached profiles or not (default=false).
 
Constructor Summary
JFacets()
           
 
Method Summary
 void afterPropertiesSet()
          To be invoked after all props have been set.
 void clearCache()
          Clears the profiles cache
 java.lang.String dumpFacetsAsXml()
          Dump all facets as an XML facet descriptor (utility method, can be handy sometimes to get a list of all facet definitions).
 java.lang.Object getFacet(java.lang.String facetName, java.lang.String profileId)
          Retrieves a facet for passed parameters.
 java.lang.Object getFacet(java.lang.String facetName, java.lang.String profileId, java.lang.Object targetObject)
          Retrieves a facet for passed parameters (uses targetObject's class to retrieve the facet).
 java.lang.Object getFacet(java.lang.String facetName, java.lang.String profileId, java.lang.Object targetObject, java.lang.Class targetObjectClass)
          Retrieves a facet for passed parameters (uses targetObjectClass class to retrieve the facet, so targetObject can be null).
 IFacetRepository getFacetRepository()
           
 java.lang.String getFallbackProfileId()
           
protected  IProfile getProfile(java.lang.String profileId)
          Retrieve a profile for passed ID.
 IProfileRepository getProfileRepository()
           
private static boolean isDescriptorOk(FacetDescriptor fd)
          Return true if all fields of the descriptor are filled in (name, profileId, targetObjectType and facetClass), false otherwise.
 boolean isUseProfilesCache()
           
 void setFacetRepository(IFacetRepository facetRepository)
           
 void setFallbackProfileId(java.lang.String fallbackProfileId)
           
 void setUseProfilesCache(boolean useProfilesCache)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final JFacetsLogger logger

useProfilesCache

private boolean useProfilesCache
Indicates wether or not to use cached profiles or not (default=false).


profilesCache

private java.util.concurrent.ConcurrentHashMap<java.lang.String,IProfile> profilesCache
The cache of already obtained profiles.


fallbackProfileId

private java.lang.String fallbackProfileId
The fallback profile to be used in case get/execFacet is invoked with a null profile or no principal associated to the current request. Handy for allowing unauthenticated users to use facets that are assigned e.g. to a "GUEST" profile or smth like this... Defaults to null.


facetRepository

private IFacetRepository facetRepository
The facet repository to be used for facet lookup.

Constructor Detail

JFacets

public JFacets()
Method Detail

getProfile

protected IProfile getProfile(java.lang.String profileId)
Retrieve a profile for passed ID. Checks for fallback profile and profiles cache if needed.

Returns:
the profile for passed ID if found, null if no such profile

clearCache

public void clearCache()
Clears the profiles cache


getFacet

public java.lang.Object getFacet(java.lang.String facetName,
                                 java.lang.String profileId,
                                 java.lang.Object targetObject,
                                 java.lang.Class targetObjectClass)
Retrieves a facet for passed parameters (uses targetObjectClass class to retrieve the facet, so targetObject can be null).

Parameters:
facetName - The name of the facet
profileId - The id of the profile
targetObject - The target object
targetObjectClass - The target object's class to be used to retrieve the facet
Returns:
the facet for passed params if found, null if not found.

getFacet

public java.lang.Object getFacet(java.lang.String facetName,
                                 java.lang.String profileId,
                                 java.lang.Object targetObject)
Retrieves a facet for passed parameters (uses targetObject's class to retrieve the facet).

Parameters:
facetName - The name of the facet
profileId - The id of the profile
targetObject - The target object
Returns:
the facet for passed params if found, null if not found.

getFacet

public java.lang.Object getFacet(java.lang.String facetName,
                                 java.lang.String profileId)
Retrieves a facet for passed parameters. This version passes a fake Object as the target object of the facet. It can be used when you need only the profile assignation, but don't really care about the target object.

Parameters:
facetName - The name of the facet
profileId - The id of the profile
Returns:
the facet for passed params if found, null if not found.

getFacetRepository

public IFacetRepository getFacetRepository()

setFacetRepository

public void setFacetRepository(IFacetRepository facetRepository)

getProfileRepository

public IProfileRepository getProfileRepository()

getFallbackProfileId

public java.lang.String getFallbackProfileId()

setFallbackProfileId

public void setFallbackProfileId(java.lang.String fallbackProfileId)

afterPropertiesSet

public void afterPropertiesSet()
To be invoked after all props have been set. Checks that required components have been injected, and creates the profiles cache map if required.


isUseProfilesCache

public boolean isUseProfilesCache()

setUseProfilesCache

public void setUseProfilesCache(boolean useProfilesCache)

dumpFacetsAsXml

public java.lang.String dumpFacetsAsXml()
Dump all facets as an XML facet descriptor (utility method, can be handy sometimes to get a list of all facet definitions).


isDescriptorOk

private static boolean isDescriptorOk(FacetDescriptor fd)
Return true if all fields of the descriptor are filled in (name, profileId, targetObjectType and facetClass), false otherwise.



Copyright © 2010. All Rights Reserved.