Last update: 2011-06-23

org.proteios.core
Class BasicItem<D extends BasicData>

java.lang.Object
  extended by org.proteios.core.BasicItem<D>
All Implemented Interfaces:
AccessControlled, Identifiable
Direct Known Subclasses:
Annotation, AnnotationSet, BioMaterialEvent, DiskUsage, Feature, FileType, Group, HardwareType, Hit, Key, Message, MimeType, News, OwnedItem, Peak, PluginType, Precursor, ProtocolType, Quota, QuotaType, Role, Session, Setting, SoftwareType, User

public abstract class BasicItem<D extends BasicData>
extends Object
implements Identifiable

This is the root superclass of all item classes. All items must inherit from this class. This class provides access to the id, type and version of the item as well as permission checking methods.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Method Summary
 void checkPermission(Permission permission)
          Checks if the logged in user has the specified permission on this item.
 boolean equals(Object o)
          Check if this item is equal to another item.
 DbControl getDbControl()
          Get the DbControl object that currently manages this item.
 int getId()
          Get the id for the item.
 Set<Permission> getPermissions()
           
 SessionControl getSessionControl()
          Get the SessionControl object that manages this item.
 int getVersion()
          Get the version number of the item.
 int hashCode()
          The hash code is calculated at object construction and remains the same during the objects lifetime.
 boolean hasPermission(Permission permission)
          Checks if the logged in user has the specified permission on this item.
 boolean isDetached()
          Check if this item is attached to a DbControl object or not.
 boolean isInDatabase()
          Checks if the item has been saved to the database or not.
abstract  boolean isUsed()
          Check if this item is used by some other item.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getType
 

Method Detail

hasPermission

public final boolean hasPermission(Permission permission)
Checks if the logged in user has the specified permission on this item. The default implementation only checks the role keys for permissions. A subclass may not override this method since it would make it possible to bypass security checks.

Subclasses that needs to check other keys, such as the SharedItem should override the initPermissions(int,int) method instead.

Specified by:
hasPermission in interface AccessControlled
Parameters:
permission - A value from the Permission class
Returns:
TRUE if the user has the permission, FALSE otherwise

checkPermission

public final void checkPermission(Permission permission)
                           throws PermissionDeniedException
Checks if the logged in user has the specified permission on this item. If not, a PermissionDeniedException is thrown.

Specified by:
checkPermission in interface AccessControlled
Parameters:
permission - A value from the Permission class
Throws:
PermissionDeniedException - If the logged in user doesn't have the requested permission

getPermissions

public final Set<Permission> getPermissions()

getId

public final int getId()
Description copied from interface: Identifiable
Get the id for the item. If it hasn't yet been saved to the database 0 is returned.

Specified by:
getId in interface Identifiable
Returns:
The id of the item or 0

getVersion

public final int getVersion()
Description copied from interface: Identifiable
Get the version number of the item. The version number is incremented each time the item is updated and is used to prevent that the same item is updated at the same time by two or more different threads or processes.

Specified by:
getVersion in interface Identifiable

toString

public String toString()
Overrides:
toString in class Object

equals

public final boolean equals(Object o)
Check if this item is equal to another item. They are considered to be equal if their BasicData objects are equal.

Overrides:
equals in class Object
See Also:
BasicData.equals(Object)

hashCode

public final int hashCode()
The hash code is calculated at object construction and remains the same during the objects lifetime. For new items the hash code is randomly generated. Items loaded from the database calculates the hash code from the from the id.

Overrides:
hashCode in class Object
See Also:
BasicData.hashCode()

isInDatabase

public final boolean isInDatabase()
Checks if the item has been saved to the database or not.

Returns:
TRUE if the item is saved to the database, FALSE otherwise

isDetached

public final boolean isDetached()
Check if this item is attached to a DbControl object or not. An item is detached if there is no DbControl, if it is closed, or if is not managed by the DbControl.

Returns:
TRUE if the item is detached, FALSE otherwise
See Also:
DbControl.detachItem(BasicItem), DbControl.reattachItem(BasicItem), DbControl.saveItem(BasicItem)

isUsed

public abstract boolean isUsed()
                        throws BaseException
Check if this item is used by some other item. With used we mean that another item is linking to this item in way that prevents this item from beeing deleted. Ie. if we tried to delete an item that is used, we would get a foreign key violation error from the database.

Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException

getDbControl

public final DbControl getDbControl()
                             throws ConnectionClosedException
Get the DbControl object that currently manages this item.

Throws:
ConnectionClosedException - If the item is connected to a closed DbControl object, or not connected at all

getSessionControl

public final SessionControl getSessionControl()
                                       throws ConnectionClosedException
Get the SessionControl object that manages this item.

Throws:
ConnectionClosedException - If the item is connected to a closed DbControl object, or not connected at all

Last update: 2011-06-23