package psdi.app.mxobjcfg;
import java.rmi.RemoteException;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.mbo.MboValueAdapter;
import psdi.util.MXException;
public class FldOrgAttr extends MboValueAdapter
{
    public FldOrgAttr(MboValue mbovalue) throws MXException {
        super(mbovalue);
    }
    public void validate() throws MXException, RemoteException {
        /* empty */
    }
    public void action() throws MXException, RemoteException {
        String attributeName = getMboValue().getAttributeName();//获得当前字段名
        String orgattr = getMboValue().getCurrentValue().toString();//获得字段当前的值
        orgattr = (orgattr == null)?"":orgattr.trim();
        if(orgattr.length() > 0){
            String objectname = getMboValue().getMbo().getOwner().getString("OBJECTNAME");
            String child = getMboValue("child").getString();
            child =(child == null)?"":child.trim();
            if(child.length() > 0){
                objectname =  child;
            }
            MboSetRemote nMaxattributeSets = getMboValue().getMbo().getMboSet("$MAXATTRIBUTE_TEMP","MAXATTRIBUTE");
            nMaxattributeSets.setWhere(new StringBuilder("OBJECTNAME='").append(objectname).append("' and ATTRIBUTENAME ='" + orgattr + "'").toString());
            nMaxattributeSets.reset();
            int loop = nMaxattributeSets.count();
            if (loop > 0) {
                MboRemote maxattributembo = nMaxattributeSets.getMbo(0);
                String maxtype = maxattributembo.getString("MAXTYPE");//MAXTYPE
                String title = maxattributembo.getString("TITLE");//MAXTYPE
                boolean required = maxattributembo.getBoolean("REQUIRED");//REQUIRED
                getMboValue("ORGTYPE").setValue(maxtype,11L);
                getMboValue("ALIAS1").setValue(orgattr.toLowerCase(),11L);
                getMboValue("TITLE").setValue(title,11L);
                getMboValue("required").setValue(required,11L);
                getMboValue("readonly").setValue(false,11L);
            }
        }
    }
    public void init() throws MXException {
        /* empty */
    }
}