ezmorph-1.0.5

16:35:48.282 INFO  jd.cli.Main - Decompiling ezmorph-1.0.5.jar
package net.sf.ezmorph;

import org.apache.commons.lang.exception.NestableRuntimeException;

public class MorphException
  extends NestableRuntimeException
{
  private static final long serialVersionUID = -540093801787033824L;
  protected Throwable cause = null;
  
  public MorphException(String message)
  {
    super(message);
  }
  
  public MorphException(String message, Throwable cause)
  {
    super(message);
    this.cause = cause;
  }
  
  public MorphException(Throwable cause)
  {
    super(cause.getMessage());
    this.cause = cause;
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.MorphException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class CharacterObjectMorpher
  extends AbstractObjectMorpher
{
  private Character defaultValue;
  
  public CharacterObjectMorpher() {}
  
  public CharacterObjectMorpher(Character defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof CharacterObjectMorpher)) {
      return false;
    }
    CharacterObjectMorpher other = (CharacterObjectMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public Character getDefaultValue()
  {
    return defaultValue;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      throw new MorphException("value is null");
    }
    if ((value instanceof Character)) {
      return (Character)value;
    }
    String s = String.valueOf(value);
    if (s.length() > 0) {
      return new Character(s.charAt(0));
    }
    if (isUseDefault()) {
      return defaultValue;
    }
    throw new MorphException("Can't morph value: " + value);
  }
  
  public Class morphsTo()
  {
    return Character.class;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.CharacterObjectMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class BooleanObjectMorpher
  extends AbstractObjectMorpher
{
  private Boolean defaultValue;
  
  public BooleanObjectMorpher() {}
  
  public BooleanObjectMorpher(Boolean defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof BooleanObjectMorpher)) {
      return false;
    }
    BooleanObjectMorpher other = (BooleanObjectMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public Boolean getDefaultValue()
  {
    return defaultValue;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      throw new MorphException("value is null");
    }
    if ((value instanceof Boolean)) {
      return (Boolean)value;
    }
    String s = String.valueOf(value);
    if ((s.equalsIgnoreCase("true")) || (s.equalsIgnoreCase("yes")) || 
      (s.equalsIgnoreCase("on"))) {
      return Boolean.TRUE;
    }
    if ((s.equalsIgnoreCase("false")) || (s.equalsIgnoreCase("no")) || 
      (s.equalsIgnoreCase("off"))) {
      return Boolean.FALSE;
    }
    if (isUseDefault()) {
      return defaultValue;
    }
    throw new MorphException("Can't morph value: " + value);
  }
  
  public Class morphsTo()
  {
    return Boolean.class;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.BooleanObjectMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.ObjectMorpher;

public final class StringMorpher
  implements ObjectMorpher
{
  private static final StringMorpher INSTANCE = new StringMorpher();
  
  public static StringMorpher getInstance()
  {
    return INSTANCE;
  }
  
  public boolean equals(Object obj)
  {
    return INSTANCE == obj;
  }
  
  public int hashCode()
  {
    return 42 + getClass().hashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    if (!supports(value.getClass())) {
      throw new MorphException("Class not supported. " + value.getClass());
    }
    if (String.class.isAssignableFrom(value.getClass())) {
      return (String)value;
    }
    return String.valueOf(value);
  }
  
  public Class morphsTo()
  {
    return String.class;
  }
  
  public boolean supports(Class clazz)
  {
    return !clazz.isArray();
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.StringMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.ObjectMorpher;

public final class ClassMorpher
  implements ObjectMorpher
{
  private static final ClassMorpher INSTANCE = new ClassMorpher();
  
  public static ClassMorpher getInstance()
  {
    return INSTANCE;
  }
  
  public boolean equals(Object obj)
  {
    return INSTANCE == obj;
  }
  
  public int hashCode()
  {
    return 42 + getClass().hashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    if ((value instanceof Class)) {
      return (Class)value;
    }
    if ("null".equals(value)) {
      return null;
    }
    try
    {
      return Class.forName(value.toString());
    }
    catch (Exception e)
    {
      throw new MorphException(e);
    }
  }
  
  public Class morphsTo()
  {
    return Class.class;
  }
  
  public boolean supports(Class clazz)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.ClassMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class DateMorpher
  extends AbstractObjectMorpher
{
  private Date defaultValue;
  private String[] formats;
  private boolean lenient;
  private Locale locale;
  
  public DateMorpher(String[] formats)
  {
    this(formats, Locale.getDefault(), false);
  }
  
  public DateMorpher(String[] formats, boolean lenient)
  {
    this(formats, Locale.getDefault(), lenient);
  }
  
  public DateMorpher(String[] formats, Date defaultValue)
  {
    this(formats, defaultValue, Locale.getDefault(), false);
  }
  
  public DateMorpher(String[] formats, Date defaultValue, Locale locale, boolean lenient)
  {
    super(true);
    if ((formats == null) || (formats.length == 0)) {
      throw new MorphException("invalid array of formats");
    }
    this.formats = formats;
    if (locale == null) {
      this.locale = Locale.getDefault();
    } else {
      this.locale = locale;
    }
    this.lenient = lenient;
    setDefaultValue(defaultValue);
  }
  
  public DateMorpher(String[] formats, Locale locale)
  {
    this(formats, locale, false);
  }
  
  public DateMorpher(String[] formats, Locale locale, boolean lenient)
  {
    if ((formats == null) || (formats.length == 0)) {
      throw new MorphException("invalid array of formats");
    }
    this.formats = formats;
    if (locale == null) {
      this.locale = Locale.getDefault();
    } else {
      this.locale = locale;
    }
    this.lenient = lenient;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof DateMorpher)) {
      return false;
    }
    DateMorpher other = (DateMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    builder.append(formats, formats);
    builder.append(locale, locale);
    builder.append(lenient, lenient);
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public Date getDefaultValue()
  {
    return (Date)defaultValue.clone();
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    builder.append(formats);
    builder.append(locale);
    builder.append(lenient);
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    if (Date.class.isAssignableFrom(value.getClass())) {
      return (Date)value;
    }
    if (!supports(value.getClass())) {
      throw new MorphException(value.getClass() + " is not supported");
    }
    String strValue = (String)value;
    SimpleDateFormat dateParser = null;
    for (int i = 0; i < formats.length; i++)
    {
      if (dateParser == null) {
        dateParser = new SimpleDateFormat(formats[i], locale);
      } else {
        dateParser.applyPattern(formats[i]);
      }
      dateParser.setLenient(lenient);
      try
      {
        return dateParser.parse(strValue.toLowerCase());
      }
      catch (ParseException localParseException) {}
    }
    if (isUseDefault()) {
      return defaultValue;
    }
    throw new MorphException("Unable to parse the date " + value);
  }
  
  public Class morphsTo()
  {
    return Date.class;
  }
  
  public void setDefaultValue(Date defaultValue)
  {
    this.defaultValue = ((Date)defaultValue.clone());
  }
  
  public boolean supports(Class clazz)
  {
    return String.class.isAssignableFrom(clazz);
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.DateMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.math.BigDecimal;
import java.math.BigInteger;
import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.primitive.ByteMorpher;
import net.sf.ezmorph.primitive.DoubleMorpher;
import net.sf.ezmorph.primitive.FloatMorpher;
import net.sf.ezmorph.primitive.IntMorpher;
import net.sf.ezmorph.primitive.LongMorpher;
import net.sf.ezmorph.primitive.ShortMorpher;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class NumberMorpher
  extends AbstractObjectMorpher
{
  private Number defaultValue;
  private Class type;
  
  public NumberMorpher(Class type)
  {
    super(false);
    if (type == null) {
      throw new MorphException("Must specify a type");
    }
    if ((type != Byte.TYPE) && (type != Short.TYPE) && (type != Integer.TYPE) && (type != Long.TYPE) && 
      (type != Float.TYPE) && (type != Double.TYPE) && (!Byte.class.isAssignableFrom(type)) && 
      (!Short.class.isAssignableFrom(type)) && (!Integer.class.isAssignableFrom(type)) && 
      (!Long.class.isAssignableFrom(type)) && (!Float.class.isAssignableFrom(type)) && 
      (!Double.class.isAssignableFrom(type)) && (!BigInteger.class.isAssignableFrom(type)) && 
      (!BigDecimal.class.isAssignableFrom(type))) {
      throw new MorphException("Must specify a Number subclass");
    }
    this.type = type;
  }
  
  public NumberMorpher(Class type, Number defaultValue)
  {
    super(true);
    if (type == null) {
      throw new MorphException("Must specify a type");
    }
    if ((type != Byte.TYPE) && (type != Short.TYPE) && (type != Integer.TYPE) && (type != Long.TYPE) && 
      (type != Float.TYPE) && (type != Double.TYPE) && (!Byte.class.isAssignableFrom(type)) && 
      (!Short.class.isAssignableFrom(type)) && (!Integer.class.isAssignableFrom(type)) && 
      (!Long.class.isAssignableFrom(type)) && (!Float.class.isAssignableFrom(type)) && 
      (!Double.class.isAssignableFrom(type)) && (!BigInteger.class.isAssignableFrom(type)) && 
      (!BigDecimal.class.isAssignableFrom(type))) {
      throw new MorphException("Must specify a Number subclass");
    }
    if ((defaultValue != null) && (!type.isInstance(defaultValue))) {
      throw new MorphException("Default value must be of type " + type);
    }
    this.type = type;
    setDefaultValue(defaultValue);
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof NumberMorpher)) {
      return false;
    }
    NumberMorpher other = (NumberMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    builder.append(type, type);
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public Number getDefaultValue()
  {
    return defaultValue;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    builder.append(type);
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if ((value != null) && (type.isAssignableFrom(value.getClass()))) {
      return value;
    }
    String str = String.valueOf(value)
      .trim();
    if ((!type.isPrimitive()) && (
      (value == null) || (str.length() == 0) || ("null".equalsIgnoreCase(str)))) {
      return null;
    }
    if (isDecimalNumber(type))
    {
      if ((Float.class.isAssignableFrom(type)) || (Float.TYPE == type)) {
        return morphToFloat(str);
      }
      if ((Double.class.isAssignableFrom(type)) || (Double.TYPE == type)) {
        return morphToDouble(str);
      }
      return morphToBigDecimal(str);
    }
    if ((Byte.class.isAssignableFrom(type)) || (Byte.TYPE == type)) {
      return morphToByte(str);
    }
    if ((Short.class.isAssignableFrom(type)) || (Short.TYPE == type)) {
      return morphToShort(str);
    }
    if ((Integer.class.isAssignableFrom(type)) || (Integer.TYPE == type)) {
      return morphToInteger(str);
    }
    if ((Long.class.isAssignableFrom(type)) || (Long.TYPE == type)) {
      return morphToLong(str);
    }
    return morphToBigInteger(str);
  }
  
  public Class morphsTo()
  {
    return type;
  }
  
  public void setDefaultValue(Number defaultValue)
  {
    if ((defaultValue != null) && (!type.isInstance(defaultValue))) {
      throw new MorphException("Default value must be of type " + type);
    }
    this.defaultValue = defaultValue;
  }
  
  private boolean isDecimalNumber(Class type)
  {
    return (Double.class.isAssignableFrom(type)) || (Float.class.isAssignableFrom(type)) || (Double.TYPE == type) || (Float.TYPE == type) || (BigDecimal.class.isAssignableFrom(type));
  }
  
  private Object morphToBigDecimal(String str)
  {
    Object result = null;
    if (isUseDefault()) {
      result = new BigDecimalMorpher((BigDecimal)defaultValue).morph(str);
    } else {
      result = new BigDecimal(str);
    }
    return result;
  }
  
  private Object morphToBigInteger(String str)
  {
    Object result = null;
    if (isUseDefault()) {
      result = new BigIntegerMorpher((BigInteger)defaultValue).morph(str);
    } else {
      result = new BigInteger(str);
    }
    return result;
  }
  
  private Object morphToByte(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Byte(new ByteMorpher(defaultValue.byteValue()).morph(str));
    }
    else
    {
      result = new Byte(new ByteMorpher().morph(str));
    }
    return result;
  }
  
  private Object morphToDouble(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Double(new DoubleMorpher(defaultValue.doubleValue()).morph(str));
    }
    else
    {
      result = new Double(new DoubleMorpher().morph(str));
    }
    return result;
  }
  
  private Object morphToFloat(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Float(new FloatMorpher(defaultValue.floatValue()).morph(str));
    }
    else
    {
      result = new Float(new FloatMorpher().morph(str));
    }
    return result;
  }
  
  private Object morphToInteger(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Integer(new IntMorpher(defaultValue.intValue()).morph(str));
    }
    else
    {
      result = new Integer(new IntMorpher().morph(str));
    }
    return result;
  }
  
  private Object morphToLong(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Long(new LongMorpher(defaultValue.longValue()).morph(str));
    }
    else
    {
      result = new Long(new LongMorpher().morph(str));
    }
    return result;
  }
  
  private Object morphToShort(String str)
  {
    Object result = null;
    if (isUseDefault())
    {
      if (defaultValue == null) {
        return null;
      }
      result = new Short(new ShortMorpher(defaultValue.shortValue()).morph(str));
    }
    else
    {
      result = new Short(new ShortMorpher().morph(str));
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.NumberMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.MorpherRegistry;
import net.sf.ezmorph.ObjectMorpher;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class SwitchingMorpher
  implements ObjectMorpher
{
  private Map classMap = new HashMap();
  private MorpherRegistry morpherRegistry;
  
  public SwitchingMorpher(Map classMap, MorpherRegistry morpherRegistry)
  {
    this.morpherRegistry = morpherRegistry;
    if ((classMap == null) || (classMap.isEmpty())) {
      throw new MorphException("Must specify at least one mapping");
    }
    this.classMap.putAll(classMap);
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof NumberMorpher)) {
      return false;
    }
    SwitchingMorpher other = (SwitchingMorpher)obj;
    if (classMap.size() != classMap.size()) {
      return false;
    }
    for (Iterator entries = classMap.entrySet()
          .iterator(); 
          entries.hasNext();)
    {
      Map.Entry entry = (Map.Entry)entries.next();
      if (!classMap.containsKey(entry.getKey())) {
        return false;
      }
      if (!entry.getValue().equals(classMap.get(entry.getKey()))) {
        return false;
      }
    }
    return true;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    for (Iterator entries = classMap.entrySet()
          .iterator(); 
          entries.hasNext();)
    {
      Map.Entry entry = (Map.Entry)entries.next();
      builder.append(entry.getKey());
      builder.append(entry.getValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    Class target = (Class)classMap.get(value.getClass());
    return morpherRegistry.morph(target, value);
  }
  
  public Class morphsTo()
  {
    return Object.class;
  }
  
  public boolean supports(Class clazz)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.SwitchingMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.math.BigDecimal;
import java.math.BigInteger;
import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class BigDecimalMorpher
  extends AbstractObjectMorpher
{
  private BigDecimal defaultValue;
  
  public BigDecimalMorpher() {}
  
  public BigDecimalMorpher(BigDecimal defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof BigDecimalMorpher)) {
      return false;
    }
    BigDecimalMorpher other = (BigDecimalMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public BigDecimal getDefaultValue()
  {
    return defaultValue;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if ((value instanceof BigDecimal)) {
      return value;
    }
    if (value == null)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      return null;
    }
    if ((value instanceof Number))
    {
      if ((value instanceof Float))
      {
        Float f = (Float)value;
        if ((f.isInfinite()) || (f.isNaN())) {
          throw new MorphException("BigDecimal can not be infinite or NaN");
        }
      }
      else if ((value instanceof Double))
      {
        Double d = (Double)value;
        if ((d.isInfinite()) || (d.isNaN())) {
          throw new MorphException("BigDecimal can not be infinite or NaN");
        }
      }
      else if ((value instanceof BigInteger))
      {
        return new BigDecimal((BigInteger)value);
      }
      return new BigDecimal(((Number)value).doubleValue());
    }
    try
    {
      String str = String.valueOf(value)
        .trim();
      if ((str.length() == 0) || (str.equalsIgnoreCase("null"))) {
        return null;
      }
      return new BigDecimal(str);
    }
    catch (NumberFormatException nfe)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      throw new MorphException(nfe);
    }
  }
  
  public Class morphsTo()
  {
    return BigDecimal.class;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.BigDecimalMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.ObjectMorpher;

public final class IdentityObjectMorpher
  implements ObjectMorpher
{
  private static final IdentityObjectMorpher INSTANCE = new IdentityObjectMorpher();
  
  public static IdentityObjectMorpher getInstance()
  {
    return INSTANCE;
  }
  
  public boolean equals(Object obj)
  {
    return INSTANCE == obj;
  }
  
  public int hashCode()
  {
    return 42 + getClass().hashCode();
  }
  
  public Object morph(Object value)
  {
    return value;
  }
  
  public Class morphsTo()
  {
    return Object.class;
  }
  
  public boolean supports(Class clazz)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.IdentityObjectMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.Morpher;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class ObjectListMorpher
  extends AbstractObjectMorpher
{
  private Object defaultValue;
  private Morpher morpher;
  private Method morphMethod;
  
  public ObjectListMorpher(Morpher morpher)
  {
    setMorpher(morpher);
  }
  
  public ObjectListMorpher(Morpher morpher, Object defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
    setMorpher(morpher);
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof ObjectListMorpher)) {
      return false;
    }
    ObjectListMorpher other = (ObjectListMorpher)obj;
    return morpher.equals(morpher);
  }
  
  public int hashCode()
  {
    return 
      new HashCodeBuilder().append(morpher).toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    if (!supports(value.getClass())) {
      throw new MorphException(value.getClass() + " is not supported");
    }
    List list = new ArrayList();
    for (Iterator i = ((List)value).iterator(); i.hasNext();)
    {
      Object object = i.next();
      if (object == null)
      {
        if (isUseDefault()) {
          list.add(defaultValue);
        } else {
          list.add(object);
        }
      }
      else
      {
        if (!morpher.supports(object.getClass())) {
          throw new MorphException(object.getClass() + " is not supported");
        }
        try
        {
          list.add(morphMethod.invoke(morpher, new Object[] { object }));
        }
        catch (MorphException me)
        {
          throw me;
        }
        catch (Exception e)
        {
          throw new MorphException(e);
        }
      }
    }
    return list;
  }
  
  public Class morphsTo()
  {
    return List.class;
  }
  
  public boolean supports(Class clazz)
  {
    return (clazz != null) && (List.class.isAssignableFrom(clazz));
  }
  
  private void setMorpher(Morpher morpher)
  {
    if (morpher == null) {
      throw new IllegalArgumentException("morpher can not be null");
    }
    this.morpher = morpher;
    try
    {
      morphMethod = 
        morpher.getClass().getDeclaredMethod("morph", new Class[] { Object.class });
    }
    catch (NoSuchMethodException nsme)
    {
      throw new IllegalArgumentException(nsme.getMessage());
    }
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.ObjectListMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class MapToDateMorpher
  extends AbstractObjectMorpher
{
  private Date defaultValue;
  
  public MapToDateMorpher() {}
  
  public MapToDateMorpher(Date defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof MapToDateMorpher)) {
      return false;
    }
    MapToDateMorpher other = (MapToDateMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public Date getDefaultValue()
  {
    return (Date)defaultValue.clone();
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if (value == null) {
      return null;
    }
    if (Date.class.isAssignableFrom(value.getClass())) {
      return (Date)value;
    }
    if (!supports(value.getClass())) {
      throw new MorphException(value.getClass() + " is not supported");
    }
    Map map = (Map)value;
    if (map.isEmpty())
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      throw new MorphException("Unable to parse the date " + value);
    }
    Calendar c = Calendar.getInstance();
    c.set(1, getValue(map, "year"));
    c.set(2, getValue(map, "month"));
    c.set(5, getValue(map, "day"));
    c.set(11, getValue(map, "hour"));
    c.set(12, getValue(map, "minutes"));
    c.set(13, getValue(map, "seconds"));
    c.set(14, getValue(map, "milliseconds"));
    return c.getTime();
  }
  
  public Class morphsTo()
  {
    return Date.class;
  }
  
  public void setDefaultValue(Date defaultValue)
  {
    this.defaultValue = ((Date)defaultValue.clone());
  }
  
  public boolean supports(Class clazz)
  {
    return (clazz != null) && (Map.class.isAssignableFrom(clazz));
  }
  
  private int getValue(Map map, String key)
  {
    Object value = map.get(key);
    if ((value == null) || (!(value instanceof Number))) {
      return 0;
    }
    Number n = (Number)value;
    return n.intValue();
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.MapToDateMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import net.sf.ezmorph.ObjectMorpher;

public abstract class AbstractObjectMorpher
  implements ObjectMorpher
{
  private boolean useDefault;
  
  public AbstractObjectMorpher() {}
  
  public AbstractObjectMorpher(boolean useDefault)
  {
    this.useDefault = useDefault;
  }
  
  public boolean isUseDefault()
  {
    return useDefault;
  }
  
  public void setUseDefault(boolean useDefault)
  {
    this.useDefault = useDefault;
  }
  
  public boolean supports(Class clazz)
  {
    return !clazz.isArray();
  }
  
  public abstract Class morphsTo();
  
  public abstract Object morph(Object paramObject);
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.AbstractObjectMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.object;

import java.math.BigDecimal;
import java.math.BigInteger;
import net.sf.ezmorph.MorphException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public final class BigIntegerMorpher
  extends AbstractObjectMorpher
{
  private BigInteger defaultValue;
  
  public BigIntegerMorpher() {}
  
  public BigIntegerMorpher(BigInteger defaultValue)
  {
    super(true);
    this.defaultValue = defaultValue;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof BigIntegerMorpher)) {
      return false;
    }
    BigIntegerMorpher other = (BigIntegerMorpher)obj;
    EqualsBuilder builder = new EqualsBuilder();
    if ((isUseDefault()) && (other.isUseDefault()))
    {
      builder.append(getDefaultValue(), other.getDefaultValue());
      return builder.isEquals();
    }
    if ((!isUseDefault()) && (!other.isUseDefault())) {
      return builder.isEquals();
    }
    return false;
  }
  
  public BigInteger getDefaultValue()
  {
    return defaultValue;
  }
  
  public int hashCode()
  {
    HashCodeBuilder builder = new HashCodeBuilder();
    if (isUseDefault()) {
      builder.append(getDefaultValue());
    }
    return builder.toHashCode();
  }
  
  public Object morph(Object value)
  {
    if ((value instanceof BigInteger)) {
      return value;
    }
    if (value == null)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      return null;
    }
    if ((value instanceof Number))
    {
      if ((value instanceof Float))
      {
        Float f = (Float)value;
        if ((f.isInfinite()) || (f.isNaN())) {
          throw new MorphException("BigInteger can not be infinite or NaN");
        }
      }
      else if ((value instanceof Double))
      {
        Double d = (Double)value;
        if ((d.isInfinite()) || (d.isNaN())) {
          throw new MorphException("BigInteger can not be infinite or NaN");
        }
      }
      else if ((value instanceof BigDecimal))
      {
        return ((BigDecimal)value).toBigInteger();
      }
      return BigInteger.valueOf(((Number)value).longValue());
    }
    try
    {
      String str = getIntegerValue(value);
      if ((str.length() == 0) || (str.equalsIgnoreCase("null"))) {
        return null;
      }
      return new BigInteger(str);
    }
    catch (NumberFormatException nfe)
    {
      if (isUseDefault()) {
        return defaultValue;
      }
      throw new MorphException(nfe);
    }
  }
  
  public Class morphsTo()
  {
    return BigInteger.class;
  }
  
  /* Error */
  protected String getIntegerValue(Object obj)
  {
    // Byte code:
    //   0: invokestatic 153	java/util/Locale:getDefault	()Ljava/util/Locale;
    //   3: astore_2
    //   4: aconst_null
    //   5: astore_3
    //   6: getstatic 159	java/util/Locale:US	Ljava/util/Locale;
    //   9: invokestatic 163	java/util/Locale:setDefault	(Ljava/util/Locale;)V
    //   12: aload_1
    //   13: invokestatic 167	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   16: invokevirtual 169	java/lang/String:trim	()Ljava/lang/String;
    //   19: astore_3
    //   20: goto +12 -> 32
    //   23: astore 4
    //   25: aload_2
    //   26: invokestatic 163	java/util/Locale:setDefault	(Ljava/util/Locale;)V
    //   29: aload 4
    //   31: athrow
    //   32: aload_2
    //   33: invokestatic 163	java/util/Locale:setDefault	(Ljava/util/Locale;)V
    //   36: aload_3
    //   37: ldc -84
    //   39: invokevirtual 174	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   42: istore 4
    //   44: iload 4
    //   46: iconst_m1
    //   47: if_icmpeq +11 -> 58
    //   50: aload_3
    //   51: iconst_0
    //   52: iload 4
    //   54: invokevirtual 178	java/lang/String:substring	(II)Ljava/lang/String;
    //   57: astore_3
    //   58: aload_3
    //   59: areturn
    // Line number table:
    //   Java source line #152	-> byte code offset #0
    //   Java source line #153	-> byte code offset #4
    //   Java source line #155	-> byte code offset #6
    //   Java source line #156	-> byte code offset #12
    //   Java source line #157	-> byte code offset #16
    //   Java source line #156	-> byte code offset #19
    //   Java source line #159	-> byte code offset #23
    //   Java source line #160	-> byte code offset #25
    //   Java source line #161	-> byte code offset #29
    //   Java source line #160	-> byte code offset #32
    //   Java source line #163	-> byte code offset #36
    //   Java source line #164	-> byte code offset #44
    //   Java source line #165	-> byte code offset #50
    //   Java source line #167	-> byte code offset #58
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	60	0	this	BigIntegerMorpher
    //   0	60	1	obj	Object
    //   3	30	2	defaultLocale	java.util.Locale
    //   5	54	3	str	String
    //   23	7	4	localObject	Object
    //   42	11	4	index	int
    // Exception table:
    //   from	to	target	type
    //   6	23	23	finally
  }
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.object.BigIntegerMorpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph;

public abstract interface Morpher
{
  public abstract Class morphsTo();
  
  public abstract boolean supports(Class paramClass);
}

/* Location:
 * Qualified Name:     net.sf.ezmorph.Morpher
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package net.sf.ezmorph.bean;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.MorphUtils;
import net.sf.ezmorph.MorpherRegistry;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public final class MorphDynaBean
  implements DynaBean, Serializable
{
  private static final long serialVersionUID = -605547389232706344L;
  private MorphDynaClass dynaClass;
  private Map dynaValues = new HashMap();
  private MorpherRegistry morpherRegistry;
  
  public MorphDynaBean()
  {
    this(null);
  }
  
  public MorphDynaBean(MorpherRegistry morpherRegistry)
  {
    setMorpherRegistry(morpherRegistry);
  }
  
  public boolean contains(String name, String key)
  {
    DynaProperty dynaProperty = getDynaProperty(name);
    
    Class type = dynaProperty.getType();
    if (!Map.class.isAssignableFrom(type)) {
      throw new MorphException("Non-Mapped property name: " + name + " key: " + key);
    }
    Object value = dynaValues.get(name);
    if (value == null)
    {
      value = new HashMap();
      dynaValues.put(name, value);
    }
    return ((Map)value).containsKey(key);
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof MorphDynaBean)) {
      return false;
    }
    MorphDynaBean other = (MorphDynaBean)obj;
    EqualsBuilder builder = new EqualsBuilder().append(dynaClass, dynaClass);
    DynaProperty[] props = dynaClass.getDynaProperties();
    for (int i = 0; i < props.length; i++)
    {
      DynaProperty prop = props[i];
      builder.append(dynaValues.get(prop.getName()), dynaValues.get(prop.getName()));
    }
    return builder.isEquals();
  }
  
  public Object get(String name)
  {
    Object value = dynaValues.get(name);
    if (value != null) {
      return value;
    }
    Class type = getDynaProperty(name).getType();
    if (!type.isPrimitive()) {
      return value;
    }
    return morpherRegistry.morph(type, value);
  }
  
  public Object get(String name, int index)
  {
    DynaProperty dynaProperty = getDynaProperty(name);
    
    Class type = dynaProperty.getType();
    if ((!type.isArray()) && (!List.class.isAssignableFrom(type))) {
      throw new MorphException("Non-Indexed property name: " + name + " index: " + index);
    }
    Object value = dynaValues.get(name);
    if (value.getClass().isArray()) {
      value = Array.get(value, index);
    } e
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd