Search in sources :

Example 1 with Type

use of org.obeonetwork.dsl.typeslibrary.Type in project InformationSystem by ObeoNetwork.

the class ColumnServices method typeName.

/**
 * Returns the name of the column's type.
 *
 * @param column
 * @return the name of the column's type.
 */
public String typeName(Column column) {
    final String res;
    Type type = column.getType();
    if (type instanceof UserDefinedTypeRef) {
        res = ((UserDefinedTypeRef) type).getType().getName();
    } else if (type instanceof TypeInstance) {
        res = ((TypeInstance) type).getNativeType().getName();
    } else {
        res = "no name found";
    }
    return res;
}
Also used : Type(org.obeonetwork.dsl.typeslibrary.Type) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) UserDefinedTypeRef(org.obeonetwork.dsl.typeslibrary.UserDefinedTypeRef)

Example 2 with Type

use of org.obeonetwork.dsl.typeslibrary.Type in project InformationSystem by ObeoNetwork.

the class ColumnServices method typeLength.

/**
 * Returns the length and the precision of the type associated to the column.
 * Result is like follows :
 * <ul>
 * <li>&lt;length&gt; if the type has the NativeKind.LENGTH attribute</li>
 * <li>&lt;length,precision&gt; if the type has the NativeKind.LENGTH_AND_PRECISION attribute</li>
 *
 * @param col
 *            the column
 * @return a description of the length of the column's type.
 */
public String typeLength(Column col) {
    final String res;
    Type type = col.getType();
    if (type instanceof TypeInstance) {
        TypeInstance instance = (TypeInstance) type;
        switch(instance.getNativeType().getSpec()) {
            case LENGTH:
                res = instance.getLength().toString();
                break;
            case LENGTH_AND_PRECISION:
                res = instance.getLength() + "," + instance.getPrecision();
                break;
            default:
                res = "";
        }
    } else {
        res = "";
    }
    return res;
}
Also used : Type(org.obeonetwork.dsl.typeslibrary.Type) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Aggregations

Type (org.obeonetwork.dsl.typeslibrary.Type)2 TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)2 UserDefinedTypeRef (org.obeonetwork.dsl.typeslibrary.UserDefinedTypeRef)1