All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.datasource.DomainFmt Maven / Gradle / Ivy

package at.spardat.xma.datasource;
/*
 * @(#) $Id:  $
 *
 * Copyright 2009/2010 by sIT Solutions,
 * A-1110 Wien, Geiselbergstr.21-25.
 * All rights reserved.
 *
 */


import at.spardat.enterprise.fmt.AParseException;
import at.spardat.enterprise.fmt.AStringFmt;
import at.spardat.enterprise.fmt.IFmt;
import at.spardat.enterprise.util.Types;
import at.spardat.xma.session.XMASession;

public class DomainFmt extends IFmt {

    /**
     * Display just the short value of each entry.
     */
    public static final int SHORT = IFmt.LAST_STYLE*2;

    /**
     * Display the long value of each domain entry.
     */
    public static final int LONG = SHORT*2;

    /**
     * Display short and long value of each entry,
     * separated by dash.
     */
    public static final int SHORT_LONG = LONG*2;


    /**
     * Display the key value of each domain entry
     */
    public static final int KEY = SHORT_LONG *2;


    private Domain domain;

    public DomainFmt(String dataSource,XMASession session,int style) {
        domain = Domain.getInstance(dataSource,session);
        this.style_=style;
    }

    public String format(String internal) {
        String shortValue = domain.getShortValue(internal);
        if(shortValue.length()==0) shortValue=internal;
        String longValue = domain.getLongValue(internal);
        if(longValue.length()==0) longValue=shortValue;

        if((style_&LONG)!=0) {
            return longValue;
        } else if((style_&SHORT_LONG)!=0) {
            return shortValue + " - " + longValue;
        } else if((style_&SHORT)!=0) {
            return shortValue;
        } else {
            return internal;
        }
    }

    public boolean isLegalExternalChar(char aChar) {
        return true;
    }

    public boolean isLegalInternal(String internal) {
        return domain.isInTable(internal);
    }

    public boolean isOneWay() {
        return true;
    }

    public int maxLenOfExternal() {
        return AStringFmt.MAX_MAX_LEN;
    }

    public boolean mayBeAppliedTo(byte type) {
        return type==Types.T_DOM||type==Types.T_STRING;
    }

    public String parse(String external) throws AParseException {
        throw new RuntimeException("not implemented");
    }

    public Domain getDomain(){
        return domain;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy