to.etc.domui.component.meta
Class MetaManager

java.lang.Object
  extended by to.etc.domui.component.meta.MetaManager

public final class MetaManager
extends java.lang.Object

Accessor class to the generalized metadata thingies.

Author:
Frits Jalvingh Created on Jun 16, 2008

Method Summary
static boolean areObjectsEqual(java.lang.Object a, java.lang.Object b)
           
static boolean areObjectsEqual(java.lang.Object a, java.lang.Object b, ClassMetaModel cmm)
          This is a complex EQUAL routine which compares objects.
static java.util.List<DisplayPropertyMetaModel> calculateObjectProperties(ClassMetaModel cm)
          Generate some set of columns to show from a class' metadata, if enabled.
static java.util.List<SearchPropertyMetaModel> calculateSearchProperties(ClassMetaModel cm)
          Try to calculate some search properties off a data class for debug/test pps, if enabled
static INodeContentRenderer<?> createDefaultComboRenderer(PropertyMetaModel<?> pmm, ClassMetaModel cmm)
          This creates a default combo option value renderer using whatever metadata is available.
static
<T extends java.lang.Enum<?>>
java.util.List<ValueLabelPair<T>>
createEnumList(java.lang.Class<T> clz)
          Creates a List of Pair's for each domain value in a class which represents a domain (like an enum or Boolean).
static ClassMetaModel findClassMeta(java.lang.Class<?> clz)
           
static ClassMetaModel findClassMeta(IMetaClass mc)
          Get the metamodel for some metadata-defined object.
static java.lang.Class<?> findCollectionType(java.lang.reflect.Type genericType)
          This tries to determine the value class for a property defined as some kind of Collection<T> or T[].
static
<T extends java.lang.Enum<?>>
java.lang.String
findEnumLabel(T val)
          Locate the enum's default label.
static PropertyMetaModel<?> findPropertyMeta(java.lang.Class<?> clz, java.lang.String name)
          Find a property using the metamodel for a class.
static PropertyMetaModel<?> findPropertyMeta(IMetaClass mc, java.lang.String name)
          Find a property using some genericized meta definition.
static java.lang.String getEnumLabel(java.lang.Class<?> clz, java.lang.String property, java.lang.Object value)
          Get a label for the enum value "value" presented on the property passed.
static java.lang.String getEnumLabel(java.lang.Enum<?> label)
          Get a NLSed label for the specified enum label.
static java.lang.String getEnumLabel(PropertyMetaModel<?> pmm, java.lang.Object value)
          Get a label for the enum value "value" presented on the property passed.
static java.lang.Object getPrimaryKey(java.lang.Object instance)
          Return the primary key field for a given instance.
static java.lang.Object getPrimaryKey(java.lang.Object instance, ClassMetaModel cmm)
           
static PropertyMetaModel<?> getPropertyMeta(java.lang.Class<?> clz, java.lang.String name)
           
static PropertyMetaModel<?> getPropertyMeta(IMetaClass clz, java.lang.String name)
           
static
<T> boolean
hasDuplicates(java.util.List<T> items, T instance, java.lang.String propertyname)
          Returns T if instance.propertyname is a duplicate in some other instance in the list.
static java.lang.String identify(java.lang.Object t)
           
static PropertyMetaModel<?> internalCalculateDottedPath(ClassMetaModel cmm, java.lang.String name)
           
static boolean isAccessAllowed(java.lang.String[][] roleset, IRequestContext ctx)
          Handles the permission sets like "viewpermission" and "editpermission".
static java.util.List<PropertyMetaModel<?>> parsePropertyPath(ClassMetaModel m, java.lang.String compoundName)
          Parse the property path and return the list of properties in the path.
static void registerModel(IClassMetaModelFactory model)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

registerModel

public static void registerModel(@Nonnull
                                 IClassMetaModelFactory model)

findClassMeta

@Nonnull
public static ClassMetaModel findClassMeta(@Nonnull
                                                   java.lang.Class<?> clz)

findClassMeta

@Nonnull
public static ClassMetaModel findClassMeta(@Nonnull
                                                   IMetaClass mc)
Get the metamodel for some metadata-defined object.

Parameters:
mc -
Returns:

findPropertyMeta

@Nullable
public static PropertyMetaModel<?> findPropertyMeta(java.lang.Class<?> clz,
                                                             java.lang.String name)
Find a property using the metamodel for a class. Returns null if not found.

Parameters:
clz -
name -
Returns:

findPropertyMeta

@Nullable
public static PropertyMetaModel<?> findPropertyMeta(IMetaClass mc,
                                                             java.lang.String name)
Find a property using some genericized meta definition. Returns null if not found.

Parameters:
mc -
name -
Returns:

getPropertyMeta

@Nonnull
public static PropertyMetaModel<?> getPropertyMeta(java.lang.Class<?> clz,
                                                           java.lang.String name)

getPropertyMeta

@Nonnull
public static PropertyMetaModel<?> getPropertyMeta(IMetaClass clz,
                                                           java.lang.String name)

isAccessAllowed

public static boolean isAccessAllowed(java.lang.String[][] roleset,
                                      IRequestContext ctx)
Handles the permission sets like "viewpermission" and "editpermission". If the array contains null the field can be seen by all users. If it has a value the first-level array is a set of ORs; the second level are ANDs. Meaning that an array in the format:
 { {"admin"}
 , {"editroles", "user"}
 , {"tester"}
 };
 
this means that the field is visible for a user with the roles:
        "admin" OR "tester" OR ("editroles" AND "user")
 

Parameters:
roleset -
ctx -
Returns:

createDefaultComboRenderer

@Nonnull
public static INodeContentRenderer<?> createDefaultComboRenderer(@Nullable
                                                                         PropertyMetaModel<?> pmm,
                                                                         @Nullable
                                                                         ClassMetaModel cmm)
This creates a default combo option value renderer using whatever metadata is available.

Parameters:
pmm - If not-null this takes precedence. This then must be the property that is to be filled from the list-of-values in the combo. The property is used to override the presentation only. Formally speaking, pmm.getActualType() must be equal to the combo's list item type, and the renderer expects items of that type.
cmm -
Returns:

areObjectsEqual

public static boolean areObjectsEqual(java.lang.Object a,
                                      java.lang.Object b,
                                      ClassMetaModel cmm)
This is a complex EQUAL routine which compares objects. Each of the objects can be null. Objects are considered equal when they are the same reference; if a.equal(b) holds or, when the objects are both objects for which a PK is known, when the PK's are equal. Also works for array types.

Parameters:
a -
b -
cmm -
Returns:

areObjectsEqual

public static boolean areObjectsEqual(java.lang.Object a,
                                      java.lang.Object b)

findEnumLabel

public static <T extends java.lang.Enum<?>> java.lang.String findEnumLabel(T val)
Locate the enum's default label.

Type Parameters:
T -
Parameters:
val -
Returns:

createEnumList

public static <T extends java.lang.Enum<?>> java.util.List<ValueLabelPair<T>> createEnumList(java.lang.Class<T> clz)
Creates a List of Pair's for each domain value in a class which represents a domain (like an enum or Boolean). The list is ready to be used by ComboFixed.

Parameters:
clz -
Returns:

internalCalculateDottedPath

public static PropertyMetaModel<?> internalCalculateDottedPath(ClassMetaModel cmm,
                                                               java.lang.String name)

parsePropertyPath

public static java.util.List<PropertyMetaModel<?>> parsePropertyPath(ClassMetaModel m,
                                                                     java.lang.String compoundName)
Parse the property path and return the list of properties in the path. This explicitly allows traversing child relations provided generic type information is present to denote the child's type.

Parameters:
m -
compoundName -
Returns:

findCollectionType

public static java.lang.Class<?> findCollectionType(java.lang.reflect.Type genericType)
This tries to determine the value class for a property defined as some kind of Collection<T> or T[]. If the type cannot be determined this returns null.

Parameters:
genericType -
Returns:

hasDuplicates

public static <T> boolean hasDuplicates(java.util.List<T> items,
                                        T instance,
                                        java.lang.String propertyname)
                             throws java.lang.Exception
Returns T if instance.propertyname is a duplicate in some other instance in the list.

Type Parameters:
T -
Parameters:
items -
instance -
propertyname -
Returns:
Throws:
java.lang.Exception

identify

public static java.lang.String identify(java.lang.Object t)
Parameters:
t -
Returns:

getPrimaryKey

public static java.lang.Object getPrimaryKey(java.lang.Object instance)
                                      throws java.lang.Exception
Return the primary key field for a given instance. This throws IllegalArgumentException's when the instance passed is not persistent or has an unknown primary key. If the primary key is just null this returns null.

Parameters:
instance -
Returns:
Throws:
java.lang.Exception

getPrimaryKey

public static java.lang.Object getPrimaryKey(java.lang.Object instance,
                                             ClassMetaModel cmm)
                                      throws java.lang.Exception
Throws:
java.lang.Exception

calculateSearchProperties

public static java.util.List<SearchPropertyMetaModel> calculateSearchProperties(ClassMetaModel cm)
Try to calculate some search properties off a data class for debug/test pps, if enabled

Parameters:
cm -
Returns:

calculateObjectProperties

public static java.util.List<DisplayPropertyMetaModel> calculateObjectProperties(ClassMetaModel cm)
Generate some set of columns to show from a class' metadata, if enabled.

Parameters:
cmm -
Returns:

getEnumLabel

public static java.lang.String getEnumLabel(java.lang.Enum<?> label)
Get a NLSed label for the specified enum label.


getEnumLabel

public static java.lang.String getEnumLabel(java.lang.Class<?> clz,
                                            java.lang.String property,
                                            java.lang.Object value)
Get a label for the enum value "value" presented on the property passed. This will first check to see if this property has overridden the labels for the enum before falling back to the enum's global bundle.

Parameters:
clz -
property -
value -
Returns:

getEnumLabel

public static java.lang.String getEnumLabel(PropertyMetaModel<?> pmm,
                                            java.lang.Object value)
Get a label for the enum value "value" presented on the property passed. This will first check to see if this property has overridden the labels for the enum before falling back to the enum's global bundle.

Parameters:
pmm -
value -
Returns: