org.shept.org.springframework.web.servlet.mvc.support
Class ModelUtils

java.lang.Object
  extended by org.shept.org.springframework.web.servlet.mvc.support.ModelUtils

public class ModelUtils
extends Object

Version:
$$Id: ModelUtils.java 110 2011-02-21 09:16:15Z aha $$
Author:
Andi

Field Summary
static String initMethod
           
protected static org.apache.commons.logging.Log logger
          Logger that is available to subclasses
 
Constructor Summary
ModelUtils()
           
 
Method Summary
private static Object cloneCopy(Object model)
          When the object to be copied provides a clone implementation return a clone of the object.
static Object copyModel(org.springframework.dao.support.DaoSupport dao, Object model)
          Trying to copy a model as generic as possible when Dao Layer is available 1st we check if a #clone method is implemented.
static Object copyModel(Object model)
          Trying to copy a model as generic as possible when no Dao layer is available 1st we check if a #clone method is implemented.
static ModelCreation getNewModelTemplate(ChainConfiguration cc, Object model, String initString)
           
static ModelCreation getNewModelTemplate(Class<?> clazz, Object model, String initString)
           
static ModelCreation getNewModelTemplate(Class<?> clazz, String initString)
           
static void initialize(Object target, Object sourceModel)
           
private static Object shallowCopy(Object model)
          Answer a shallow copy of the object
static Object unwrapIfNecessary(Object commandOrModel)
          Unwrap a command or model from its envelope.
static Object wrapIfNecessary(Object model)
          This is the counterpart of unwrapIfNecessary(Object) When showing model entity objects in a form we may want to decorate them with additional information that should'nt be saved to the database, e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initMethod

public static String initMethod

logger

protected static org.apache.commons.logging.Log logger
Logger that is available to subclasses

Constructor Detail

ModelUtils

public ModelUtils()
Method Detail

unwrapIfNecessary

public static Object unwrapIfNecessary(Object commandOrModel)
Unwrap a command or model from its envelope. You may have compound objects as a result of a database query and now we need to obtain the base object entity. If commandOrModel is an Array we take the first object from the array. If commandOrModel implements ModelSupplier then we ask for the wrapped object. Note that cascading will be done until we have reached the bare object. Not that the ModelSupplier interface should never be implemented by Entity model objects Current implementation doesn't check for recursion

Parameters:
commandOrModel -
Returns:

wrapIfNecessary

public static Object wrapIfNecessary(Object model)
This is the counterpart of unwrapIfNecessary(Object) When showing model entity objects in a form we may want to decorate them with additional information that should'nt be saved to the database, e.g. repeat information fields (passwords other temporary or compound fields) Wrapping provides a solution to present a command object instead of the real model entity.

Parameters:
model -
Returns:

copyModel

public static Object copyModel(Object model)
Trying to copy a model as generic as possible when no Dao layer is available 1st we check if a #clone method is implemented. In this case we will use object.clone() Then we will resort to a shallowCopy of the object.

Parameters:
model -
Returns:

copyModel

public static Object copyModel(org.springframework.dao.support.DaoSupport dao,
                               Object model)
Trying to copy a model as generic as possible when Dao Layer is available 1st we check if a #clone method is implemented. In this case we will use object.clone() 2nd we check if it is an entity supported by the dao. In this case we will use the entity-copy method provided by the dao At last we will resort to a shallowCopy of the object.

Parameters:
model -
Returns:

cloneCopy

private static Object cloneCopy(Object model)
When the object to be copied provides a clone implementation return a clone of the object.

Parameters:
model -
Returns:

shallowCopy

private static Object shallowCopy(Object model)
Answer a shallow copy of the object

Parameters:
model -
Returns:

getNewModelTemplate

public static ModelCreation getNewModelTemplate(Class<?> clazz,
                                                Object model,
                                                String initString)
Returns:
the newModelTemplate if any

getNewModelTemplate

public static ModelCreation getNewModelTemplate(Class<?> clazz,
                                                String initString)
Returns:
the newModelTemplate if any

getNewModelTemplate

public static ModelCreation getNewModelTemplate(ChainConfiguration cc,
                                                Object model,
                                                String initString)
Returns:
the newModelTemplate if any

initialize

public static void initialize(Object target,
                              Object sourceModel)


Copyright © 2011. All Rights Reserved.