blob: cba7ea1307e14c58b2f101262e691ff75b42343d [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.utils.fillertext;
import java.sql.Time;
import java.sql.Types;
import java.sql.Date;
import org.joda.time.DateTime;
public enum FillerTextType {
/** simple text */
TEXT(Types.CHAR, String.class),
/** timestamp or date & time */
TIMESTAMP(Types.TIMESTAMP, DateTime.class),
/** signed (positive) integer */
SIGNEDINTEGER(Types.INTEGER, Integer.class),
/** unsigned (positive or negative) integer */
UNSIGNEDINTEGER(Types.INTEGER, Integer.class),
/** date without time */
DATE(Types.DATE, Date.class),
/** time without date */
TIME(Types.TIME, Time.class),
/** boolean */
TRUEORFALSE(Types.BOOLEAN, Boolean.class),
/** signed (positive) double */
SIGNEDDOUBLE(Types.DOUBLE, Double.class),
/** unsigned (positive or negative) double */
UNSIGNEDDOUBLE(Types.DOUBLE, Double.class),
// JAVA_OBJECT(Types.JAVA_OBJECT),
// BINARY(Types.BINARY),
/** any other tex */
OTHER(Types.OTHER, TEXT),
/** any other text */
BLOB(Types.BLOB, TEXT),
/** signed (positive) double */
SIGNEDDECIMAL(Types.DECIMAL, SIGNEDDOUBLE),
/** unsigned (positive or negative) double */
UNSIGNEDDECIMAL(Types.DECIMAL, UNSIGNEDDOUBLE),
//
/** word(s) */
WORD(TEXT),
/** sentence(s) */
SENTENCE(TEXT),
/** paragraph(s) */
PARAGRAPH(TEXT),
// /** localized first name */
// FIRSTNAME(TEXT),
// /** localized last name */
// LASTNAME(TEXT),
// /** localized full name = first & last name */
// FULLNAME(TEXT),
// /** localized email containing first & last name */
// EMAIL(TEXT),
// /** localized postal code */
// POSTALCODE(TEXT),
// /** localized city */
// CITY(TEXT),
// /** localized phone number */
// PHONE(TEXT),
// /** localized phone number */
// GENDER_MALE(Types.BOOLEAN, Boolean.class),
;
private final int fSqlType;
private final FillerTextType fParentType;
private final Class<?> fObjectClass;
private FillerTextType(int sqlType, Class<?> objectClass) {
this(sqlType, objectClass, null);
}
private FillerTextType(FillerTextType parentType) {
this(0, null, parentType);
}
private FillerTextType(int sqlType, FillerTextType parentType) {
this(sqlType, null, parentType);
}
private FillerTextType(int sqlType, Class<?> objectClass, FillerTextType parentType) {
fSqlType = sqlType;
fObjectClass = objectClass;
fParentType = parentType;
}
/**
* @param object to be checked, if it is compatible to the corresponding class
* @return true/false
*/
public boolean instanceOf(Object object) {
if (fParentType == null) {
return fObjectClass.isInstance(object);
}
else {
return fParentType.instanceOf(object);
}
}
/**
* @return the corresponding {@link java.sql.Types}
*/
public int getSqlType() {
if (fParentType == null) {
return fSqlType;
}
else {
return fParentType.getSqlType();
}
}
/**
* @return the returning class
*/
public Class<?> getObjectClass() {
if (fParentType == null) {
return fObjectClass;
}
else {
return fParentType.getObjectClass();
}
}
/**
* @param name <u>case insensitive</u> name to searched for
* @return the corresponding {@link FillerTextType}
*/
public static FillerTextType typeFor(String name) {
for (FillerTextType type : values()) {
if (name.equalsIgnoreCase(type.toString())) {
return type;
}
}
return OTHER.fParentType;
}
/**
* @param sqlType the {@link java.sql.Types} to be searched for
* @return the <u>first</u> corresponding {@link FillerTextType}
*/
public static FillerTextType typeFor(int sqlType) {
for (FillerTextType type : values()) {
if (type.fSqlType == sqlType) {
while (type.fParentType != null) {
type = type.fParentType;
}
return type;
}
}
return OTHER.fParentType;
}
}