package devguide.advanced.simpledomains.common;

import java.io.Serializable;

import java.lang.Object;

import oracle.jbo.JboException;
import oracle.jbo.Transaction;
import oracle.jbo.domain.DataCreationException;
import oracle.jbo.domain.DomainInterface;
import oracle.jbo.domain.DomainOwnerInterface;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class ShortEmailAddress extends Object implements DomainInterface, Serializable {
    public ShortEmailAddress(String val) {
        mData = new String(val);
        validate();
    }
    private String mData;

    protected ShortEmailAddress() {
        mData = "";
    }

    public Object getData() {
        return mData;
    }

    /**<b>Internal:</b> <em>Applications should not use this method.</em>
     */
    public void setContext(DomainOwnerInterface owner, Transaction trans, 
                           Object obj) {
    }

    /**Implements domain validation logic and throws a JboException on error.
     */
    protected void validate() {
        /**Implements domain validation logic and throws a JboException on error.
         */
          int atpos = mData.indexOf('@');
          int dotpos = mData.lastIndexOf('.');
          if (atpos > -1 || dotpos > -1) {
            throw new DataCreationException(ErrorMessages.class,
            ErrorMessages.INVALID_SHORTEMAIL,null,null);
        }
    }

    public String toString() {
        if (mData != null) {
            return mData.toString();
        }
        return "<null>";
    }

    public boolean equals(Object obj) {
        if (obj instanceof DomainInterface) {
            if (mData != null) {
                return mData.equals(((DomainInterface)obj).getData());
            }
            return ((DomainInterface)obj).getData() == null;
        }
        return false;
    }
}
