/*
 * Created on 2004-11-20
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.core.mmpmodel;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import pl.zalewski.mikolaj.symbdev.SymbdevPlugin;

/**
 * A subclass of CoreException used by the MMP model objects. Plugin
 * id for these exception is the main Symbian plug-in. The codes are
 * SymbdevPlugin.ERROR_MODEL_BASE to
 * SymbdevPlugin.ERROR_MODEL_BASE+0x10000
 * 
 * @author mikolaj
 */
public class MMPModelException extends CoreException {

    /**
     * Item not found
     */
    public final static int ITEM_NOT_FOUND = 1;
    /**
     * Item already exists
     */
    public final static int ITEM_EXISTS = 2;
    /**
     * The data provided is invalid for this field
     */
    public static final int INVALID_ARGUMENT = 3;
    /**
     * Some error about document led to an invalid document operation
     * (internal parser error)
     */
    public static final int DOCUMENT_ERROR = 4;
    /**
     * The intem in the tokens table is invalid - contains a white
     * character
     */
    public static final int INVALID_TOKEN = 5;
    /**
     * Path doesn't exist or is not relative to the current project
     */
    public static final int PATH_NOT_IN_PROJECT = 5;
    
    public MMPModelException(int subcode, String message)
    {
        this(subcode, message, null);
    }

    public MMPModelException(int subcode, String message, Exception e)
    {
        super(new Status(IStatus.ERROR, SymbdevPlugin.getUniqueIdentifier(),
                SymbdevPlugin.ERROR_MODEL_BASE+subcode, message, e));
    }    
    
    static public boolean isMMPModelException(Throwable t, int subcode)
    {
        if (!(t instanceof MMPModelException))
            return false;
        MMPModelException e=(MMPModelException)t;
        if (e.getStatus().getCode()==SymbdevPlugin.ERROR_MODEL_BASE+subcode &&
                e.getStatus().getPlugin().equals(SymbdevPlugin.getUniqueIdentifier()))
            return true;
        return false;
    }
}
