org.openbp.common.generic.propertybrowser
Class ObjectDescriptorMgr

java.lang.Object
  extended by org.openbp.common.generic.propertybrowser.ObjectDescriptorMgr

public final class ObjectDescriptorMgr
extends java.lang.Object

This singleton class manages ObjectDescriptor objects. The ObjectDescriptorMgr class accesses object descriptors for a particular class. The descriptor is expected to reside in the same location as the class file of the class (named "AbcProp.xml" if the class name is "Abc"). The manager will automatically locate and locate the object descriptor for this class. After loading the OD, the object descriptor manager will iterate the property list. The manager will try to resolve attribute information of a property that is not set (e. g. description, type name, editor class name) from the OD of the super class or from the OD of its implemented interfaces.
This means that for common attributes you only need to specify their property name in the property descriptor list; the remaining information about the property will be retrieved from the base class. In addition to the regular object descriptors, the manager also supports custom descriptors. These descriptors may override the regular descriptors. The custom descriptors are grouped in custom descriptor sets. A set is located in a sub directory of the custom descriptor directory (setCustomDescriptorResourcePath(java.lang.String)). Each descriptor file of the set must be named by the fully qualified class name of the class to describe with the ending "Prop.xml" appended (e. g. "org.openbp.common.generic.description.DisplayObjectProp.xml").
A set can be activated by calling loadCustomDescriptorSet(java.lang.String).

Author:
Heiko Erhardt

Field Summary
static int ODM_EXCLUDE_CUSTOM
          Flag for getDescriptor(java.lang.Class, int): Consider custom descriptors.
static int ODM_THROW_ERROR
          Flag for getDescriptor(java.lang.Class, int): Throw error if descriptor not found.
 
Method Summary
 void clearCache()
          Clears the cache of the node structure manager.
 java.lang.String getCustomDescriptorResourcePath()
          Gets the resource path to folder that may contain sub folders with custom descriptors.
 ObjectDescriptor getDescriptor(java.lang.Class cls, int flags)
          Gets the descriptor for a particular object class.
static ObjectDescriptorMgr getInstance()
          Gets the singleton instance of this class.
 void loadCustomDescriptors(java.lang.String resourcePath)
          Loads custom descriptors from the specified resource path.
 void loadCustomDescriptorSet(java.lang.String customDescriptorSetName)
          Loads the specified custom descriptor set or clears the set.
 void setCustomDescriptorResourcePath(java.lang.String customDescriptorResourcePath)
          Sets the resource path to folder that may contain sub folders with custom descriptors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ODM_THROW_ERROR

public static final int ODM_THROW_ERROR
Flag for getDescriptor(java.lang.Class, int): Throw error if descriptor not found. If set, the method will throw an exception if the descriptor could not be loaded.
Note that if loading has already been attempted in a previous call, the method will return null. If the descriptor file is invalid, an exception will be thrown in either case.

See Also:
Constant Field Values

ODM_EXCLUDE_CUSTOM

public static final int ODM_EXCLUDE_CUSTOM
Flag for getDescriptor(java.lang.Class, int): Consider custom descriptors. If set, the method will use only regular descriptors. Otherwise, it will look for custom descriptors also (see setCustomDescriptorResourcePath(java.lang.String)/loadCustomDescriptorSet(java.lang.String)).

See Also:
Constant Field Values
Method Detail

getInstance

public static ObjectDescriptorMgr getInstance()
Gets the singleton instance of this class.


getDescriptor

public ObjectDescriptor getDescriptor(java.lang.Class cls,
                                      int flags)
                               throws XMLDriverException
Gets the descriptor for a particular object class. The method will try to retrieve the descriptor for the specified class. If this fails, it will continue with the super class and the implemented interfaces. However, the method will check one level only, i. e. it will not traverse the super class of the interfaces etc. The manager expects the descriptor file to be located in the same directory as the class file of the object. The name of the descriptor file is constructed by appending "Prop.xml" to the name of the class. The manager will cache all loaded descriptors. It will try to load a descriptor only once. If loading failed, subsequent calls of getDescriptor for the same class will always return null.

Parameters:
cls - Class to load the mapping for
flags - Flags the control the way the method works (ODM_THROW_ERROR|ODM_EXCLUDE_CUSTOM)
Returns:
The descriptor or null if no such descriptor exists
Throws:
XMLDriverException - If no descriptor file exists for this class

clearCache

public void clearCache()
Clears the cache of the node structure manager.


getCustomDescriptorResourcePath

public java.lang.String getCustomDescriptorResourcePath()
Gets the resource path to folder that may contain sub folders with custom descriptors.


setCustomDescriptorResourcePath

public void setCustomDescriptorResourcePath(java.lang.String customDescriptorResourcePath)
Sets the resource path to folder that may contain sub folders with custom descriptors.


loadCustomDescriptorSet

public void loadCustomDescriptorSet(java.lang.String customDescriptorSetName)
                             throws XMLDriverException
Loads the specified custom descriptor set or clears the set. The set is loaded from the sub directory with the specified name in the directory specified by setCustomDescriptorResourcePath(java.lang.String).
This method will always clear the object descriptor cache.

Parameters:
customDescriptorSetName - The set name or null if only the regular descriptors should be used
Throws:
XMLDriverException - If the specified set or the set directory does not exist

loadCustomDescriptors

public void loadCustomDescriptors(java.lang.String resourcePath)
                           throws XMLDriverException
Loads custom descriptors from the specified resource path.

Parameters:
resourcePath - ResourcePath of the resource folder to load the descriptors from
Throws:
XMLDriverException - If the specified directory does not exist


Copyright © 2011. All Rights Reserved.