2.8.3: 2008-10-15

net.sf.basedb.core
Class Annotation

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<AnnotationData>
      extended by net.sf.basedb.core.Annotation
All Implemented Interfaces:
AccessControlled, Identifiable

public class Annotation
extends BasicItem<AnnotationData>

This class represents an annotation. Annotations are user-defined properties that can be attached to Annotatable items. They can be very useful in the filtering and analysis process.

An annotation must have an AnnotationType, which controls the type of and how many values that can be attached to an annotation.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2008-09-05 17:16:27 +0200 (Fri, 05 Sep 2008) $

Nested Class Summary
private static class Annotation.QueryRuntimeFilterImpl
           
 
Field Summary
private  AnnotationSet annotationSet
           
private static QueryRuntimeFilter RUNTIME_FILTER
          This filter gives everybody read permission to annotations.
static Item TYPE
          The type of item represented by this class.
 
Constructor Summary
Annotation(AnnotationData annotationData)
           
Annotation(AnnotationData annotationData, AnnotationSet annotationSet)
           
 
Method Summary
 AnnotationSet getAnnotationSet()
          Get the annotation set this annotation belongs to.
 AnnotationType getAnnotationType()
          Get the annotation type of this annotation.
static Annotation getById(DbControl dc, int id)
          Get an Annotation item when you know the id.
(package private) static Annotation getNew(DbControl dc, AnnotationType annotationType, AnnotationSet annotationSet)
          Create a new annotation.
(package private)  PluginPermission getPluginPermissions()
           
(package private) static ItemQuery<Annotation> getQuery()
          Get a query configured to retrieve annotations.
 Item getType()
          Get the type of item represented by the object.
 List<?> getValues()
          Get the values this annotation contains.
 int getValuesVersion()
          Get the version number of the item keeping the values.
 Type getValueType()
          Get the value type for this annotation type.
(package private)  void initPermissions(int granted, int denied)
          READ permission is granted if the logged in user has READ permission on the associated item.
 void setValue(Object value)
          Set the value of the annotation, replacing any previous values.
 void setValues(List<?> values)
          Set the values of the annotation, replacing any previous values.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.ANNOTATION, getType()

RUNTIME_FILTER

private static final QueryRuntimeFilter RUNTIME_FILTER
This filter gives everybody read permission to annotations.


annotationSet

private AnnotationSet annotationSet
Constructor Detail

Annotation

Annotation(AnnotationData annotationData)

Annotation

Annotation(AnnotationData annotationData,
           AnnotationSet annotationSet)
Method Detail

getNew

static Annotation getNew(DbControl dc,
                         AnnotationType annotationType,
                         AnnotationSet annotationSet)
                  throws BaseException
Create a new annotation.

Parameters:
dc - The DbControl object
annotationType - The annotation type of the new annotation
annotationSet - The annotation set of the new annotation
Throws:
BaseException
See Also:
AnnotationSet.getAnnotation(AnnotationType)

getById

public static Annotation getById(DbControl dc,
                                 int id)
                          throws ItemNotFoundException,
                                 PermissionDeniedException,
                                 BaseException
Get an Annotation item when you know the id.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The id of the item to load
Returns:
The Annotation item
Throws:
ItemNotFoundException - If an item with the specified id is not found
PermissionDeniedException - If the logged in user doesn't have read permission to the item
BaseException - If there is another error

getQuery

static ItemQuery<Annotation> getQuery()
Get a query configured to retrieve annotations. This query may return items which the logged in user doesn't have read permission to. At the moment there is no way to solve this problem.

Returns:
An ItemQuery object

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

initPermissions

void initPermissions(int granted,
                     int denied)
               throws BaseException
READ permission is granted if the logged in user has READ permission on the associated item. CREATE, WRITE and DELETE permissions are granted if the logged in user has WRITE permission on the associated item.

Overrides:
initPermissions in class BasicItem<AnnotationData>
Parameters:
granted - Permissions that have been granted by the subclass
denied - Permissions that have been denied by the subclass
Throws:
BaseException - If the permissions couldn't be initialised

getPluginPermissions

PluginPermission getPluginPermissions()
Overrides:
getPluginPermissions in class BasicItem<AnnotationData>

getAnnotationSet

public AnnotationSet getAnnotationSet()
                               throws PermissionDeniedException,
                                      BaseException
Get the annotation set this annotation belongs to.

Returns:
An AnnotationSet
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the annotation set (should never happen)
BaseException - If anything else goes wrong when getting the annotation set.

getAnnotationType

public AnnotationType getAnnotationType()
                                 throws PermissionDeniedException,
                                        BaseException
Get the annotation type of this annotation.

Returns:
An AnnotationType
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the annotation type
BaseException - If anything else goes wrong when getting the annotation type.

getValueType

public Type getValueType()
Get the value type for this annotation type. It can't be change once the object has been created.

Returns:
Type value type as an enum.
Since:
2.2

getValues

public List<?> getValues()
                  throws BaseException
Get the values this annotation contains. The values are of a Type appropriate for the given annotation type, ie. Integer object for an integer annotation type. All objects in the list are of the same type.

Returns:
A list of objects
Throws:
BaseException - If there is an error
See Also:
AnnotationType.getValueType()

getValuesVersion

public int getValuesVersion()
Get the version number of the item keeping the values. This is useful when you need to know if the annotation values has been modified by another transaction since they were read from the database. Unlike other items the version number of the annotation item doesn't change when the values are modified.

Returns:
The version number as an int.

setValue

public void setValue(Object value)
              throws PermissionDeniedException,
                     InvalidDataException,
                     BaseException
Set the value of the annotation, replacing any previous values.

Parameters:
value - The new value
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission for the annotation or read permission for the annotation type
InvalidDataException - If the value isn't a valid value for the annotation type, see AnnotationType.validateAnnotationValue(Object)
BaseException - If there is another error

setValues

public void setValues(List<?> values)
               throws PermissionDeniedException,
                      InvalidDataException,
                      BaseException
Set the values of the annotation, replacing any previous values.

Parameters:
values - A list containing the new values
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission for the annotation or read permission for the annotation type
InvalidDataException - If the number of values are too many according to the AnnotationType.getMultiplicity() setting any of the values isn't a valid value for the annotation type, see AnnotationType.validateAnnotationValue(Object)
BaseException - If there is another error

2.8.3: 2008-10-15