2.17.2: 2011-06-17

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: 2010-11-03 15:02:49 +0100 (Wed, 03 Nov 2010) $

Nested Class Summary
(package private) static class Metadata.BasicData2ItemPropertyPath<C extends BasicData,V extends BasicItem<C>>
          Property path implementation that converts a BasicData object to a BasicItem.
(package private) static class Metadata.BasicItem2DataPropertyPath<C extends BasicItem<V>,V extends BasicData>
          Property path implementation that converts a BasicItem to a BasicData object.
(package private) static class Metadata.CollectionPropertyPath<C>
          Property path implementation which wraps a collection inside an unmodifiable collection.
(package private) static class Metadata.CombinedPropertyPath<C,V>
          Property path implementation that combines a list of property paths to create a long chain.
(package private) static class Metadata.ComponentPropertyPath<C,V>
          Property path implementation which gets a value from a component.
(package private) static class Metadata.DateCopyPropertyPath
          Property path implementation clones a Date.
(package private) static class Metadata.EntityPropertyPath<C,V>
          Property path implementation which gets a value from an entity.
(package private) static class Metadata.EvictPropertyPath<C>
          Property path implementation that evicts the selected item from the Hibernate first-level cache.
(package private) static class Metadata.IdentifierPropertyPath
          Property path implementation which gets the id from an entity.
(package private) static class Metadata.MapPropertyPath
          Property path implementation which wraps a map inside an unmodifiable map.
(package private) static class Metadata.NoopPropertyPath<C>
          Property path implementation that does nothing.
static interface Metadata.PropertyPath<C,V>
          Contract for getting the value of a specific property for an item.
(package private) static class Metadata.ReporterScore2DataPropertyPath
          Property path implementation that converts a ReporterScore to a ReporterListScoreData object.
 
Field Summary
private static Set<Item> annotatableItems
           
private  Map<String,Metadata.PropertyPath> cachedPaths
           
private  org.hibernate.metadata.ClassMetadata classMetadata
           
private  Class<C> clazz
           
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(Class<C> clazz, 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.
private  int getIndex(String s, String[] list, Comparator<String> check)
           
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.
<V> Metadata.PropertyPath<C,V>
getPropertyPath(String path, boolean ignoreCase)
          Get a property path that can be used to retrieve a value from an item instead of using the regular get methods.
static Object getPropertyValue(BasicItem item, String propertyName)
          Deprecated. In 2.15, use getPropertyPath(String, boolean) instead
 Object getPropertyValue(DbControl dc, C item, String propertyName)
          Deprecated. In 2.15, use getPropertyPath(String, boolean) instead
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 org.hibernate.metadata.ClassMetadata classMetadata

entityName

private final String entityName

clazz

private final Class<C> clazz

cachedPaths

private final Map<String,Metadata.PropertyPath> cachedPaths
Constructor Detail

Metadata

private Metadata(Class<C> clazz,
                 String entityName)
          throws BaseException
Throws:
BaseException
Method Detail

init

static void init()

unload

static void unload()
Unload all settings.


getPropertyValue

@Deprecated
public static Object getPropertyValue(BasicItem item,
                                                 String propertyName)
                               throws BaseException
Deprecated. In 2.15, use getPropertyPath(String, boolean) instead

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.

getPropertyPath

public <V> Metadata.PropertyPath<C,V> getPropertyPath(String path,
                                                      boolean ignoreCase)
Get a property path that can be used to retrieve a value from an item instead of using the regular get methods. The following method calls are equivalent:
// Using getter method
String name = item.getName();

// Using PropertyPath
PropertyPath path = metadata.getPropertyPath("name");
String name = (String)path.getValue(dc, item);
        
You can even use dot notation to navigate to associated items:
// Using getter methods
String quota = item.getOwner().getQuota().getName();

// Using PropertyPath
PropertyPath path = metadata.getPropertyPath("owner.quota.name");
String quota = (String)path.getValue(dc, item);

Type Parameters:
V - The class of the returned values
Parameters:
path - The name of the property to get. Null is not allowed. Use . or # as a separator between property and association names
Returns:
A property path object
Throws:
NullPointerException - If the path is null
InvalidDataException - If the path is not a valid path
Since:
2.15

getIndex

private int getIndex(String s,
                     String[] list,
                     Comparator<String> check)

getPropertyValue

@Deprecated
public Object getPropertyValue(DbControl dc,
                                          C item,
                                          String propertyName)
                        throws BaseException
Deprecated. In 2.15, use getPropertyPath(String, boolean) instead

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:
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.17.2: 2011-06-17