org.rhq.enterprise.server.rest
Class AbstractRestBean

java.lang.Object
  extended by org.rhq.enterprise.server.rest.AbstractRestBean
Direct Known Subclasses:
AlertHandlerBean, GroupHandlerBean, MetricHandlerBean, OperationsHandlerBean, ResourceHandlerBean, StatusHandlerBean, UserHandlerBean

public class AbstractRestBean
extends Object

Abstract base class for EJB classes that implement REST methods. For the cache and its evicion policies see rhq-cache-service.xml

Author:
Heiko W. Rupp

Constructor Summary
AbstractRestBean()
           
 
Method Summary
 ResourceWithType fillRWT(org.rhq.core.domain.resource.Resource res, javax.ws.rs.core.UriInfo uriInfo)
           
protected
<T> org.jboss.cache.Fqn
getFqn(int id, Class<T> clazz)
          Construct a Fqn object from the passed data
protected
<T> T
getFromCache(org.jboss.cache.Fqn fqn, Class<T> clazz)
          Retrieve an object from the cache if present or null otherwise.
protected
<T> T
getFromCache(int id, Class<T> clazz)
          Retrieve an object from the cache.
protected  org.rhq.core.domain.resource.Resource getResourceFromCache(int resourceid)
           
protected  List<org.rhq.core.domain.resource.Resource> getResourcesFromCacheByParentId(int pid)
           
protected  void putResourceToCache(org.rhq.core.domain.resource.Resource res)
           
protected
<T> boolean
putToCache(org.jboss.cache.Fqn fqn, T o)
          Put an object into the cache.
protected
<T> boolean
putToCache(int id, Class<T> clazz, T o)
          Put an object into the cache identified by its type and id
protected
<T> boolean
removeFromCache(int operationId, Class<T> clazz)
          Remove an item from the cache
protected  String renderTemplate(String templateName, Object objectToRender)
          Renders the passed object with the help of a freemarker template into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRestBean

public AbstractRestBean()
Method Detail

renderTemplate

protected String renderTemplate(String templateName,
                                Object objectToRender)
Renders the passed object with the help of a freemarker template into a string. Freemarket templates are searched in the class path in a directory called "/rest_templates". In the usual Maven tree structure, this is below src/main/resources/.

Parameters:
templateName - Template to use for rendering. If the template name does not end in .ftl, .ftl is appended.
objectToRender - Object to render via template
Returns:
Template filled with data from objectToRender

getFromCache

protected <T> T getFromCache(int id,
                             Class<T> clazz)
Retrieve an object from the cache. This is identified by its class and id

Parameters:
id - Id of the object to load.
clazz - Wanted return type
Returns:
Object if found and the caller has access to it.
See Also:
getFqn(int, Class)

getFromCache

protected <T> T getFromCache(org.jboss.cache.Fqn fqn,
                             Class<T> clazz)
Retrieve an object from the cache if present or null otherwise. We need to be careful here as we must not return objects the current caller has no access to. We do this by checking the "readers" attribute of the selected node to see if the caller has put the object there

Parameters:
fqn - FullyQualified name (=path in cache) ot the object to retrieve
clazz - Return type
Returns:
The desired object if found and valid for the current caller. Null otherwise.
See Also:
putToCache(org.jboss.cache.Fqn, Object)

putToCache

protected <T> boolean putToCache(org.jboss.cache.Fqn fqn,
                                 T o)
Put an object into the cache. We need to record the caller so that we can later check if the caller can access that object or not.

Parameters:
fqn - Fully qualified name (=path to object)
o - Object to put
Returns:
true if put was successful
See Also:
getFromCache(org.jboss.cache.Fqn, Class)

putToCache

protected <T> boolean putToCache(int id,
                                 Class<T> clazz,
                                 T o)
Put an object into the cache identified by its type and id

Parameters:
id - Id of the object to put
clazz - Type to put in
o - Object to put
Returns:
true if put was successful
See Also:
putToCache(org.jboss.cache.Fqn, Object)

putResourceToCache

protected void putResourceToCache(org.rhq.core.domain.resource.Resource res)

getResourcesFromCacheByParentId

protected List<org.rhq.core.domain.resource.Resource> getResourcesFromCacheByParentId(int pid)

getResourceFromCache

protected org.rhq.core.domain.resource.Resource getResourceFromCache(int resourceid)

getFqn

protected <T> org.jboss.cache.Fqn getFqn(int id,
                                         Class<T> clazz)
Construct a Fqn object from the passed data

Parameters:
id - Id of the target object
clazz - Type of object for that node
Returns:
Fqn object

removeFromCache

protected <T> boolean removeFromCache(int operationId,
                                      Class<T> clazz)
Remove an item from the cache

Parameters:
operationId - Id of the item
clazz - Type of object for that node
Returns:
true if object is no longer in cache

fillRWT

public ResourceWithType fillRWT(org.rhq.core.domain.resource.Resource res,
                                javax.ws.rs.core.UriInfo uriInfo)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.