org.sharengo.wikitty
Class WikittyUtil

java.lang.Object
  extended by org.sharengo.wikitty.WikittyUtil

public class WikittyUtil
extends Object

Util static method for wikitty

Version:
$Revision: 1 $ Last update: $Date: 2010-04-16 10:29:38 +0200 (ven., 16 avril 2010) $ by : $Author: echatellier $
Author:
poussin

Nested Class Summary
static class WikittyUtil.SolrDateFormat
           
 
Field Summary
protected static Locale CANONICAL_LOCALE
           
protected static TimeZone CANONICAL_TZ
          used to format date for solr
static String DATE_FORMAT
           
static String DEFAULT_VERSION
           
protected static Pattern fieldPattern
          Field pattern parser group 1: type (string) group 2: name (string) group 3: lower bound (number) can be null group 4: upper bound (number) can be null, mutualy exclusif with group 5 group 5: upper bound (n or *) can be null group 6: unique can be null group 7: not null can be null group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")
static Map<Class,Class> interfaceToClass
          contains mapping between interface and concret class that must be used
protected static DateFormat[] parserDateFormats
          All date format parser used to convert string to date
static SimpleDateFormat solrDateFormat
           
protected static Pattern tagValuesPattern
           
protected static String tagValuesPatternString
          Pattern for tag value: tag="value" or tag=value. value can contains '"'
 
Constructor Summary
WikittyUtil()
           
 
Method Summary
static Wikitty beanToWikitty(BusinessEntity bean)
           
static Wikitty beanToWikitty(BusinessEntityBean bean)
           
static LinkedHashMap<String,FieldType> buildFieldMapExtension(String... definitions)
          Create map from string representation ex: "String name", "Wikitty children[0-*]"
static
<E> E
cast(Object obj, Class<E> clazz)
          Try to cast obj to class passed in arguement
static Wikitty checkExtensionVersion(WikittyService wikittyService, Wikitty wikitty, BusinessEntityWikitty entity)
          Check extension default, i.e. if bean contain a extension with a great version as in wikitty.
static Object fromString(FieldType field, String s)
          convert string field representation to correct value type
static String genUID()
           
static Class getClass(Object value)
          return class of argument, if argument is null, return null
static String incrementMajorRevision(String v)
          increment major version.
static String incrementMinorRevision(String v)
          increment minor version.
static
<E extends BusinessEntity>
E
newInstance(Class<E> clazz)
          Create new instance of WikittyDto without Wikitty object passed in argument.
static
<E extends BusinessEntity>
E
newInstance(WikittyService wikittyService, Class<E> clazz, Wikitty w)
          Create new instance of WikittyDto with Wikitty object passed in argument.
static String normalizeVersion(String version)
          if version if null return 0 else version If version is not in format .
static String parseField(String def, FieldType fieldType)
          parse FieldType definition and return field name.
static Map<String,String> tagValuesToMap(String tagValues)
          Deserialize tagValues to map
static String tagValuesToString(Map<String,String> tagValues)
          Serialize tagValues to string
static BigDecimal toBigDecimal(Object value)
           
static boolean toBoolean(Object value)
          Convert object to boolean: - null => false - 0 => false - numeric => true - object.toString() == false => false - other => true
static Date toDate(Object value)
           
static
<E> List<E>
toList(Object value, Class<E> clazz)
           
static String toString(FieldType field, Object o)
          Convert object o for indexation
static String toString(Object value)
           
static String toWikitty(Object value)
          return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller
static boolean versionEquals(String v1, String v2)
          return true if v1 and v2 are egals 1.2.0 et 1.2 ne sont pas egaux
static boolean versionGreaterThan(String v1, String v2)
          return true if v1 greater than v2
static
<E extends BusinessEntityBean,F extends BusinessEntityWikitty>
E
wikittyToBean(Class<E> clazz, F dto)
           
static
<E extends BusinessEntityBean>
E
wikittyToBean(Class<E> clazz, Wikitty w)
          Convert WikittyDto (dto that encapsulate Wikitty) to BeanDto (dto without internaly wikitty)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_VERSION

public static final String DEFAULT_VERSION
See Also:
Constant Field Values

DATE_FORMAT

public static final String DATE_FORMAT
See Also:
Constant Field Values

CANONICAL_TZ

protected static TimeZone CANONICAL_TZ
used to format date for solr


CANONICAL_LOCALE

protected static final Locale CANONICAL_LOCALE

solrDateFormat

public static final SimpleDateFormat solrDateFormat

parserDateFormats

protected static final DateFormat[] parserDateFormats
All date format parser used to convert string to date


interfaceToClass

public static Map<Class,Class> interfaceToClass
contains mapping between interface and concret class that must be used


tagValuesPatternString

protected static String tagValuesPatternString
Pattern for tag value: tag="value" or tag=value. value can contains '"'


tagValuesPattern

protected static Pattern tagValuesPattern

fieldPattern

protected static Pattern fieldPattern
Field pattern parser
  • group 1: type (string)
  • group 2: name (string)
  • group 3: lower bound (number) can be null
  • group 4: upper bound (number) can be null, mutualy exclusif with group 5
  • group 5: upper bound (n or *) can be null
  • group 6: unique can be null
  • group 7: not null can be null
  • group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")

  • Constructor Detail

    WikittyUtil

    public WikittyUtil()
    Method Detail

    parseField

    public static String parseField(String def,
                                    FieldType fieldType)
    parse FieldType definition and return field name. All field information are stored in fieldType object passed in argument

    Parameters:
    def - string field definition
    fieldType - object used to put parsed information
    Returns:
    field name parsed in definition

    tagValuesToString

    public static String tagValuesToString(Map<String,String> tagValues)
    Serialize tagValues to string

    Parameters:
    tagValues - tagValues as map
    Returns:
    string represent tagValues

    tagValuesToMap

    public static Map<String,String> tagValuesToMap(String tagValues)
    Deserialize tagValues to map

    Parameters:
    tagValues - tagValues as string
    Returns:
    map represent tagValues

    buildFieldMapExtension

    public static LinkedHashMap<String,FieldType> buildFieldMapExtension(String... definitions)
    Create map from string representation ex: "String name", "Wikitty children[0-*]"

    Parameters:
    definitions -
    Returns:

    normalizeVersion

    public static String normalizeVersion(String version)
    if version if null return 0 else version If version is not in format ., ".0" is added to the version

    Parameters:
    version -
    Returns:
    the normalized version

    versionEquals

    public static boolean versionEquals(String v1,
                                        String v2)
    return true if v1 and v2 are egals 1.2.0 et 1.2 ne sont pas egaux


    versionGreaterThan

    public static boolean versionGreaterThan(String v1,
                                             String v2)
    return true if v1 greater than v2

    Parameters:
    v1 -
    v2 -
    Returns:

    incrementMinorRevision

    public static String incrementMinorRevision(String v)
    increment minor version.

    Parameters:
    version - version as 3.1 where 1 is minor and 3 major
    Returns:
    incremented minor number (3.1 -> 3.2)

    incrementMajorRevision

    public static String incrementMajorRevision(String v)
    increment major version.

    Parameters:
    version - version as 3.2 where 2 is minor and 3 major
    Returns:
    incremented major number and reset minor number (3.2 -> 4.0)

    toBigDecimal

    public static BigDecimal toBigDecimal(Object value)
    Parameters:
    value - null and empty string are casted to '0' value.
    Throws:
    WikittyException - on NumberFormatException or if value object can't be casted to number.

    toBoolean

    public static boolean toBoolean(Object value)
    Convert object to boolean: - null => false - 0 => false - numeric => true - object.toString() == false => false - other => true

    Parameters:
    value -
    Returns:

    toString

    public static String toString(Object value)

    toDate

    public static Date toDate(Object value)

    toWikitty

    public static String toWikitty(Object value)
    return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller

    Parameters:
    value -
    Returns:
    id of wikitty object or null
    Throws:
    WikittyException

    toList

    public static <E> List<E> toList(Object value,
                                     Class<E> clazz)
    Type Parameters:
    E -
    Parameters:
    clazz -
    Returns:
    unmodifiable list

    toString

    public static String toString(FieldType field,
                                  Object o)
    Convert object o for indexation

    Parameters:
    field - field description
    o - field value
    Returns:
    solr representation

    fromString

    public static Object fromString(FieldType field,
                                    String s)
    convert string field representation to correct value type

    Parameters:
    field - field description
    s - string value
    Returns:
    object in type of field

    getClass

    public static Class getClass(Object value)
    return class of argument, if argument is null, return null

    Parameters:
    value -
    Returns:
    class of value or null

    newInstance

    public static <E extends BusinessEntity> E newInstance(Class<E> clazz)
    Create new instance of WikittyDto without Wikitty object passed in argument. If arguement is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of WikittyDto or business interface

    Parameters:
    clazz - class of the new instance
    Returns:

    newInstance

    public static <E extends BusinessEntity> E newInstance(WikittyService wikittyService,
                                                           Class<E> clazz,
                                                           Wikitty w)
    Create new instance of WikittyDto with Wikitty object passed in argument. If arguement is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of WikittyDto or business interface

    Parameters:
    clazz - class of the new instance
    w - wikitty object to use internaly for in new instance
    Returns:

    checkExtensionVersion

    public static Wikitty checkExtensionVersion(WikittyService wikittyService,
                                                Wikitty wikitty,
                                                BusinessEntityWikitty entity)
    Check extension default, i.e. if bean contain a extension with a great version as in wikitty. In this case the extension is stored in last version and wikitty it is restored again. The upgrade data is during the restoration.

    Parameters:
    wikittyService -
    wikitty -
    entity -
    Returns:

    cast

    public static <E> E cast(Object obj,
                             Class<E> clazz)
    Try to cast obj to class passed in arguement

    Parameters:
    obj - object to cast
    clazz - new type of object
    Returns:
    the same object but casted to class wanted, except for primitif where is new object if obj BigDecimal

    beanToWikitty

    public static Wikitty beanToWikitty(BusinessEntity bean)

    beanToWikitty

    public static Wikitty beanToWikitty(BusinessEntityBean bean)

    wikittyToBean

    public static <E extends BusinessEntityBean,F extends BusinessEntityWikitty> E wikittyToBean(Class<E> clazz,
                                                                                                 F dto)

    wikittyToBean

    public static <E extends BusinessEntityBean> E wikittyToBean(Class<E> clazz,
                                                                 Wikitty w)
    Convert WikittyDto (dto that encapsulate Wikitty) to BeanDto (dto without internaly wikitty)

    Parameters:
    clazz - target object clazz
    w - source object
    Returns:

    genUID

    public static String genUID()


    Copyright © 2009-2010 CodeLutin. All Rights Reserved.