org.slim3.commons.beanutil
Class AbstractCopy<S extends AbstractCopy<S>>

java.lang.Object
  extended by org.slim3.commons.beanutil.AbstractCopy<S>
Type Parameters:
S - the sub type.
Direct Known Subclasses:
Copy, CreateAndCopy

public abstract class AbstractCopy<S extends AbstractCopy<S>>
extends Object

An abstract class to copy an object to an another object.

Since:
3.0
Author:
higa

Field Summary
protected  Map<String,Converter> converterMap
          The converters that are bound to the specific property.
protected  List<Converter> converters
          The converters that are not bound to any properties.
protected  boolean copyEmptyString
          Whether emptyString is copied.
protected  boolean copyNull
          Whether null is copied.
protected static Converter DEFAULT_DATE_CONVERTER
          The default converter for Date.
protected static Converter DEFAULT_TIME_CONVERTER
          The default converter for Time.
protected static Converter DEFAULT_TIMESTAMP_CONVERTER
          The default converter for Timestamp.
protected static String[] EMPTY_STRINGS
          The empty strings.
protected  String[] excludedPropertyNames
          The excluded property names.
protected  String[] includedPropertyNames
          The included property names.
 
Constructor Summary
AbstractCopy()
           
 
Method Summary
 S converter(Converter converter, CharSequence... propertyNames)
          Specifies the converter.
protected  Object convertValue(Object value, String destPropertyName, Class<?> destPropertyClass)
          Converts the value.
protected  void copyBeanToBean(Object src, Object dest)
          Copies a bean to an another bean.
protected  void copyBeanToMap(Object src, Map<String,Object> dest)
          Copies a bean to an another map.
 S copyEmptyString()
          Specifies whether empty string is copied.
protected  void copyMapToBean(Map<String,Object> src, Object dest)
          Copies a map to an another bean.
protected  void copyMapToMap(Map<String,Object> src, Map<String,Object> dest)
          Copies a map to an another map.
 S copyNull()
          Specifies whether null is copied.
 S dateConverter(String pattern, CharSequence... propertyNames)
          Specifies the converter for Date.
 S exclude(CharSequence... propertyNames)
          Specifies the excluded property names.
protected  Converter findConverter(Class<?> clazz)
          Finds the converter for the class.
protected  Converter findDefaultConverter(Class<?> clazz)
          Finds the default converter.
 S include(CharSequence... propertyNames)
          Specifies the included property names.
protected  boolean isTargetProperty(String name)
          Determines if the property is target.
protected  boolean isTargetValue(Object value)
          Determines if the value is target.
 S numberConverter(String pattern, CharSequence... propertyNames)
          Specifies the number converter.
 S sqlDateConverter(String pattern, CharSequence... propertyNames)
          Specifies the converter for Date.
 S timeConverter(String pattern, CharSequence... propertyNames)
          Specifies the converter for Time.
 S timestampConverter(String pattern, CharSequence... propertyNames)
          Specifies the converter for Timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRINGS

protected static final String[] EMPTY_STRINGS
The empty strings.


DEFAULT_DATE_CONVERTER

protected static final Converter DEFAULT_DATE_CONVERTER
The default converter for Date.


DEFAULT_TIMESTAMP_CONVERTER

protected static final Converter DEFAULT_TIMESTAMP_CONVERTER
The default converter for Timestamp.


DEFAULT_TIME_CONVERTER

protected static final Converter DEFAULT_TIME_CONVERTER
The default converter for Time.


includedPropertyNames

protected String[] includedPropertyNames
The included property names.


excludedPropertyNames

protected String[] excludedPropertyNames
The excluded property names.


copyNull

protected boolean copyNull
Whether null is copied.


copyEmptyString

protected boolean copyEmptyString
Whether emptyString is copied.


converterMap

protected Map<String,Converter> converterMap
The converters that are bound to the specific property.


converters

protected List<Converter> converters
The converters that are not bound to any properties.

Constructor Detail

AbstractCopy

public AbstractCopy()
Method Detail

include

public S include(CharSequence... propertyNames)
Specifies the included property names.

Parameters:
propertyNames - the included property names
Returns:
this instance

exclude

public S exclude(CharSequence... propertyNames)
Specifies the excluded property names.

Parameters:
propertyNames - the excluded property names
Returns:
this instance

copyNull

public S copyNull()
Specifies whether null is copied.

Returns:
this instance

copyEmptyString

public S copyEmptyString()
Specifies whether empty string is copied.

Returns:
this instance

converter

public S converter(Converter converter,
                   CharSequence... propertyNames)
Specifies the converter.

Parameters:
converter - the converter
propertyNames - the property names
Returns:
this instance

dateConverter

public S dateConverter(String pattern,
                       CharSequence... propertyNames)
Specifies the converter for Date.

Parameters:
pattern - the pattern for SimpleDateFormat
propertyNames - the property names
Returns:
this instance

sqlDateConverter

public S sqlDateConverter(String pattern,
                          CharSequence... propertyNames)
Specifies the converter for Date.

Parameters:
pattern - the pattern for SimpleDateFormat
propertyNames - the property names
Returns:
this instance

timeConverter

public S timeConverter(String pattern,
                       CharSequence... propertyNames)
Specifies the converter for Time.

Parameters:
pattern - the pattern for SimpleDateFormat
propertyNames - the property names
Returns:
this instance

timestampConverter

public S timestampConverter(String pattern,
                            CharSequence... propertyNames)
Specifies the converter for Timestamp.

Parameters:
pattern - the pattern for SimpleDateFormat
propertyNames - the property names
Returns:
this instance

numberConverter

public S numberConverter(String pattern,
                         CharSequence... propertyNames)
Specifies the number converter.

Parameters:
pattern - the pattern for DecimalFormat
propertyNames - the property names
Returns:
this instance

isTargetProperty

protected boolean isTargetProperty(String name)
Determines if the property is target.

Parameters:
name - the property name
Returns:
whether the property is target

isTargetValue

protected boolean isTargetValue(Object value)
Determines if the value is target.

Parameters:
value - the value
Returns:
whether the value is target

copyBeanToBean

protected void copyBeanToBean(Object src,
                              Object dest)
Copies a bean to an another bean.

Parameters:
src - the source bean
dest - the destination bean

copyBeanToMap

protected void copyBeanToMap(Object src,
                             Map<String,Object> dest)
Copies a bean to an another map.

Parameters:
src - the source bean
dest - the destination map

copyMapToBean

protected void copyMapToBean(Map<String,Object> src,
                             Object dest)
Copies a map to an another bean.

Parameters:
src - the source map
dest - the destination bean

copyMapToMap

protected void copyMapToMap(Map<String,Object> src,
                            Map<String,Object> dest)
Copies a map to an another map.

Parameters:
src - the source map
dest - the destination map

convertValue

protected Object convertValue(Object value,
                              String destPropertyName,
                              Class<?> destPropertyClass)
                       throws ConverterRuntimeException
Converts the value.

Parameters:
value - the value
destPropertyName - the destination property name
destPropertyClass - the destination property class
Returns:
the converted value
Throws:
ConverterRuntimeException - if an exception is encountered while coverting

findConverter

protected Converter findConverter(Class<?> clazz)
Finds the converter for the class.

Parameters:
clazz - the class.
Returns:
converter

findDefaultConverter

protected Converter findDefaultConverter(Class<?> clazz)
Finds the default converter.

Parameters:
clazz - the converter.
Returns:
the default converter.


Copyright © 2008-2009 The Slim3 project. All Rights Reserved.