2.8.2: 2008-09-18

net.sf.basedb.core
Class Metadata<C>

java.lang.Object
  extended by net.sf.basedb.core.Metadata<C>

public class Metadata<C>
extends Object

Utility methods for retreiving metadata about items.

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

Field Summary
private static Set<Item> annotatableItems
           
private  ClassMetadata classMetadata
           
private static Set<Item> diskConsumableItems
           
private  String entityName
           
private static Set<Item> fileStoreEnabledItems
           
private static Map<String,Metadata<?>> instances
          Cache of Metadata instances.
private static boolean isInitialised
           
private static Set<Item> ownableItems
           
private static Set<Item> removableItems
           
private static Set<Item> shareableItems
           
 
Constructor Summary
private Metadata(String entityName)
           
 
Method Summary
static Set<Item> getAnnotatableItems()
          Get a set containing all Annotatable item types.
static Set<Item> getDiskConsumableItems()
          Get a set containing all DiskConsumable item types.
static Set<Item> getFileStoreEnabledItems()
          Get a set containing all FileStoreEnabled item types.
private static Set<Item> getImplementingItems(Class<?> clazz)
          Get all Item:s implementing/extinding the specified interface/class.
static
<I> Metadata<I>
getInstance(Class<I> itemClass)
          Get the metadata instance for the specified type of item.
static
<I> Metadata<I>
getInstance(Class<I> clazz, String entityName)
          Get the metadata instance for the item with the specified entity name.
static Set<Item> getOwnableItems()
          Get a set containing all Ownable item types.
static Object getPropertyValue(BasicItem item, String propertyName)
          Get the value of a property of an item.
 Object getPropertyValue(DbControl dc, C item, String propertyName)
          Get the value of a property of an item.
static Set<Item> getRemovableItems()
          Get a set containing all Removable item types.
static Set<Item> getShareableItems()
          Get a set containing all Shareable item types.
(package private) static void init()
           
 String toString()
           
(package private) static void unload()
          Unload all settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

annotatableItems

private static Set<Item> annotatableItems

shareableItems

private static Set<Item> shareableItems

removableItems

private static Set<Item> removableItems

ownableItems

private static Set<Item> ownableItems

diskConsumableItems

private static Set<Item> diskConsumableItems

fileStoreEnabledItems

private static Set<Item> fileStoreEnabledItems

isInitialised

private static boolean isInitialised

instances

private static final Map<String,Metadata<?>> instances
Cache of Metadata instances. Only one instance for each type of item exists.


classMetadata

private final ClassMetadata classMetadata

entityName

private final String entityName
Constructor Detail

Metadata

private Metadata(String entityName)
          throws BaseException
Throws:
BaseException
Method Detail

init

static void init()

unload

static void unload()
Unload all settings.


getPropertyValue

public static Object getPropertyValue(BasicItem item,
                                      String propertyName)
                               throws BaseException
Get the value of a property of an item. This method can be used in place of a regular get method of the item. Ie. the following method calls are equivalent:
String name = item.getName();
String name = (String)Metadata.getProperty(item, "name");
You can even use dot notation to navigate to associated items:
String quota = item.getOwner().getQuota().getName();
String quota = (String)Metadata.getProperty(item, "owner.quota.name");

Parameters:
item - The item object to get the value from. Null is not allowed
propertyName - The name of the property to get
Returns:
The value as a java.lang.Object
Throws:
BaseException - If something goes wrong.
InvalidUseOfNullException - If required parameter is null

getImplementingItems

private static Set<Item> getImplementingItems(Class<?> clazz)
Get all Item:s implementing/extinding the specified interface/class.


getAnnotatableItems

public static Set<Item> getAnnotatableItems()
Get a set containing all Annotatable item types. The set cannot be modified.


getShareableItems

public static Set<Item> getShareableItems()
Get a set containing all Shareable item types. The set cannot be modified.


getRemovableItems

public static Set<Item> getRemovableItems()
Get a set containing all Removable item types. The set cannot be modified.


getOwnableItems

public static Set<Item> getOwnableItems()
Get a set containing all Ownable item types. The set cannot be modified.


getDiskConsumableItems

public static Set<Item> getDiskConsumableItems()
Get a set containing all DiskConsumable item types. The set cannot be modified.


getFileStoreEnabledItems

public static Set<Item> getFileStoreEnabledItems()
Get a set containing all FileStoreEnabled item types. The set cannot be modified.


getInstance

public static <I> Metadata<I> getInstance(Class<I> itemClass)
                               throws BaseException
Get the metadata instance for the specified type of item.

Type Parameters:
I -
Parameters:
itemClass - The class of the item
Returns:
a new instance of this class.
Throws:
BaseException - If a new instance could not be created.

getInstance

public static <I> Metadata<I> getInstance(Class<I> clazz,
                                          String entityName)
                               throws BaseException
Get the metadata instance for the item with the specified entity name. Use this method where one class is mapped to several entities, for example RawData.

Type Parameters:
I -
Parameters:
clazz - The class of the item, should be either a BasicItem or BasicData class
entityName - The entity name for the item, normally this is clazz.getName() but some entities, for example RawData, have multiple names
Returns:
a new instance of this class
Throws:
BaseException - If a new instance could not be created.

getPropertyValue

public Object getPropertyValue(DbControl dc,
                               C item,
                               String propertyName)
                        throws BaseException
Get the value of a property of an item. This method can be used in place of a regular get method of the item. Ie. the following method calls are equivalent:
String name = item.getName();
String name = (String)Metadata.getProperty(item, "name");
You can even use dot notation to navigate to associated items:
String quota = item.getOwner().getQuota().getName();
String quota = (String)Metadata.getProperty(item, "owner.quota.name");

TODO - the implementation of this method is a mess. Can it be made more robust?

Parameters:
dc - The DbControl object used if database access is needed
item - The item object to get the value from. Null is not allowed.
propertyName - The name of the property to get. Null is not allowed.
Returns:
Property value as a java.lang.Object or null if the property has no value.
Throws:
BaseException - If getting the property value goes wrong.
InvalidUseOfNullException - if any of the required arguments is null.

toString

public String toString()
Overrides:
toString in class Object

2.8.2: 2008-09-18