first commit

This commit is contained in:
2025-07-28 13:56:49 +05:30
commit e9eb805edb
3438 changed files with 520990 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package org.apache.commons.beanutils.converters;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public abstract class AbstractArrayConverter implements Converter {
protected Object defaultValue = null;
protected static String[] strings = new String[0];
protected boolean useDefault = true;
public abstract Object convert(Class paramClass, Object paramObject);
protected List parseElements(String svalue) {
if (svalue == null)
throw new NullPointerException();
svalue = svalue.trim();
if (svalue.startsWith("{") && svalue.endsWith("}"))
svalue = svalue.substring(1, svalue.length() - 1);
try {
int ttype;
StreamTokenizer st = new StreamTokenizer(new StringReader(svalue));
st.whitespaceChars(44, 44);
st.ordinaryChars(48, 57);
st.ordinaryChars(46, 46);
st.ordinaryChars(45, 45);
st.wordChars(48, 57);
st.wordChars(46, 46);
st.wordChars(45, 45);
ArrayList list = new ArrayList();
while (true) {
ttype = st.nextToken();
if (ttype == -3 || ttype > 0) {
list.add(st.sval);
continue;
}
break;
}
if (ttype == -1)
return list;
throw new ConversionException("Encountered token of type " + ttype);
} catch (IOException e) {
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.apache.commons.beanutils.converters;
import java.math.BigDecimal;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class BigDecimalConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public BigDecimalConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public BigDecimalConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof BigDecimal)
return value;
try {
return new BigDecimal(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.apache.commons.beanutils.converters;
import java.math.BigInteger;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class BigIntegerConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public BigIntegerConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public BigIntegerConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof BigInteger)
return value;
try {
return new BigInteger(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,71 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class BooleanArrayConverter extends AbstractArrayConverter {
public BooleanArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public BooleanArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static boolean[] model = new boolean[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
boolean[] results = new boolean[values.length];
for (int i = 0; i < values.length; i++) {
String stringValue = values[i];
if (stringValue.equalsIgnoreCase("yes") || stringValue.equalsIgnoreCase("y") || stringValue.equalsIgnoreCase("true") || stringValue.equalsIgnoreCase("on") || stringValue.equalsIgnoreCase("1")) {
results[i] = true;
} else if (stringValue.equalsIgnoreCase("no") || stringValue.equalsIgnoreCase("n") || stringValue.equalsIgnoreCase("false") || stringValue.equalsIgnoreCase("off") || stringValue.equalsIgnoreCase("0")) {
results[i] = false;
} else {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString());
}
}
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
boolean[] results = new boolean[list.size()];
for (int i = 0; i < results.length; i++) {
String stringValue = list.get(i);
if (stringValue.equalsIgnoreCase("yes") || stringValue.equalsIgnoreCase("y") || stringValue.equalsIgnoreCase("true") || stringValue.equalsIgnoreCase("on") || stringValue.equalsIgnoreCase("1")) {
results[i] = true;
} else if (stringValue.equalsIgnoreCase("no") || stringValue.equalsIgnoreCase("n") || stringValue.equalsIgnoreCase("false") || stringValue.equalsIgnoreCase("off") || stringValue.equalsIgnoreCase("0")) {
results[i] = false;
} else {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString());
}
}
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,48 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class BooleanConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public BooleanConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public BooleanConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Boolean)
return value;
try {
String stringValue = value.toString();
if (stringValue.equalsIgnoreCase("yes") || stringValue.equalsIgnoreCase("y") || stringValue.equalsIgnoreCase("true") || stringValue.equalsIgnoreCase("on") || stringValue.equalsIgnoreCase("1"))
return Boolean.TRUE;
if (stringValue.equalsIgnoreCase("no") || stringValue.equalsIgnoreCase("n") || stringValue.equalsIgnoreCase("false") || stringValue.equalsIgnoreCase("off") || stringValue.equalsIgnoreCase("0"))
return Boolean.FALSE;
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(stringValue);
} catch (ClassCastException e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class ByteArrayConverter extends AbstractArrayConverter {
public ByteArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public ByteArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static byte[] model = new byte[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
byte[] results = new byte[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Byte.parseByte(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
byte[] results = new byte[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Byte.parseByte((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class ByteConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public ByteConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public ByteConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Byte)
return value;
if (value instanceof Number)
return new Byte(((Number)value).byteValue());
try {
return new Byte(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class CharacterArrayConverter extends AbstractArrayConverter {
public CharacterArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public CharacterArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static char[] model = new char[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
char[] results = new char[values.length];
for (int i = 0; i < values.length; i++)
results[i] = values[i].charAt(0);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
char[] results = new char[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = ((String)list.get(i)).charAt(0);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,41 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class CharacterConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public CharacterConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public CharacterConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Character)
return value;
try {
return new Character(value.toString().charAt(0));
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,44 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class ClassConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public ClassConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public ClassConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Class)
return value;
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null)
classLoader = ClassConverter.class.getClassLoader();
return classLoader.loadClass(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class DoubleArrayConverter extends AbstractArrayConverter {
public DoubleArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public DoubleArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static double[] model = new double[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
double[] results = new double[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Double.parseDouble(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
double[] results = new double[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Double.parseDouble((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class DoubleConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public DoubleConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public DoubleConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Double)
return value;
if (value instanceof Number)
return new Double(((Number)value).doubleValue());
try {
return new Double(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class FloatArrayConverter extends AbstractArrayConverter {
public FloatArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public FloatArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static float[] model = new float[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
float[] results = new float[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Float.parseFloat(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
float[] results = new float[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Float.parseFloat((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class FloatConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public FloatConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public FloatConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Float)
return value;
if (value instanceof Number)
return new Float(((Number)value).floatValue());
try {
return new Float(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class IntegerArrayConverter extends AbstractArrayConverter {
public IntegerArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public IntegerArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static int[] model = new int[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
int[] results = new int[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Integer.parseInt(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
int[] results = new int[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Integer.parseInt((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class IntegerConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public IntegerConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public IntegerConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Integer)
return value;
if (value instanceof Number)
return new Integer(((Number)value).intValue());
try {
return new Integer(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class LongArrayConverter extends AbstractArrayConverter {
public LongArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public LongArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static long[] model = new long[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
long[] results = new long[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Long.parseLong(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
long[] results = new long[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Long.parseLong((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class LongConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public LongConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public LongConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Long)
return value;
if (value instanceof Number)
return new Long(((Number)value).longValue());
try {
return new Long(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,51 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class ShortArrayConverter extends AbstractArrayConverter {
public ShortArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public ShortArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static short[] model = new short[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
if (AbstractArrayConverter.strings.getClass() == value.getClass())
try {
String[] values = (String[])value;
short[] results = new short[values.length];
for (int i = 0; i < values.length; i++)
results[i] = Short.parseShort(values[i]);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
try {
List list = parseElements(value.toString());
short[] results = new short[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = Short.parseShort((String)list.get(i));
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,43 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class ShortConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public ShortConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public ShortConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Short)
return value;
if (value instanceof Number)
return new Short(((Number)value).shortValue());
try {
return new Short(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.apache.commons.beanutils.converters;
import java.sql.Date;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class SqlDateConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public SqlDateConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public SqlDateConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Date)
return value;
try {
return Date.valueOf(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.apache.commons.beanutils.converters;
import java.sql.Time;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class SqlTimeConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public SqlTimeConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public SqlTimeConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Time)
return value;
try {
return Time.valueOf(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.apache.commons.beanutils.converters;
import java.sql.Timestamp;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class SqlTimestampConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public SqlTimestampConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public SqlTimestampConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Timestamp)
return value;
try {
return Timestamp.valueOf(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}

View File

@@ -0,0 +1,39 @@
package org.apache.commons.beanutils.converters;
import java.util.List;
import org.apache.commons.beanutils.ConversionException;
public final class StringArrayConverter extends AbstractArrayConverter {
public StringArrayConverter() {
this.defaultValue = null;
this.useDefault = false;
}
public StringArrayConverter(Object defaultValue) {
this.defaultValue = defaultValue;
this.useDefault = true;
}
private static String[] model = new String[0];
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (model.getClass() == value.getClass())
return value;
try {
List list = parseElements(value.toString());
String[] results = new String[list.size()];
for (int i = 0; i < results.length; i++)
results[i] = list.get(i);
return results;
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(value.toString(), e);
}
}
}

View File

@@ -0,0 +1,11 @@
package org.apache.commons.beanutils.converters;
import org.apache.commons.beanutils.Converter;
public final class StringConverter implements Converter {
public Object convert(Class type, Object value) {
if (value == null)
return null;
return value.toString();
}
}