package configure;

import p2.pao.PaoField;
import p2.pao.PaoSetRemote;
import p2.util.P2AppException;
import p2.util.P2Exception;

public class databindid extends
		p2.application.configure.cols.ColP2ColumnDfDBindID {

	public databindid(PaoField arg0) throws P2Exception {
		super(arg0);
	}

	@Override
	public void action() throws P2Exception {
		super.action();
		PaoSetRemote PS_DATABIND = getPaoField().getPao().getPaoSet(
				"PS_DATABIND");
		if (PS_DATABIND.count() == 1
				&& "SYSOBJ".equals(PS_DATABIND.getPao(0).getString("databindtype"))) {
			getPaoField("classname").setValue(
					"p2.pao.custom.SimplePaoFieldObjectBind");
		} else {
			getPaoField("classname").setValue("p2.pao.custom.SimplePaoFieldAdapter"); 
		}
	}

	@Override
	public void validate() throws P2Exception {
		super.validate();
		PaoSetRemote PS_DATABIND = getPaoField().getPao().getPaoSet(
				"PS_DATABIND");
		if (PS_DATABIND.count() == 1) {
			String mainobjectname = PS_DATABIND.getPao(0).getString(
					"mainobjectname");
			if (!"".equals(mainobjectname)
					&& !mainobjectname.equals(getPaoField("objectname")
							.getString())) {
				throw new P2AppException("", "该数据绑定为" + mainobjectname 
						+ "表专属，不可选择");
			}

		}

	}
}
