/*******************************************************************************
* Copyright (c) 2012 Arapiki Solutions Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* psmith - initial API and
* implementation and/or initial documentation
*******************************************************************************/
package com.buildml.refactor;
/**
* An Exception class for reporting the reason why a refactoring operation could not
* be completed. Use getCauseCode() to return the reason (see the enum Cause for detail)
* and then getCauseIDs() to obtain more detail on which paths or actions caused the failure.
*
* @author Peter Smith <psmith@arapiki.com>
*/
@SuppressWarnings("serial")
public class CanNotRefactorException extends Exception {
/*=====================================================================================*
* FIELDS/TYPES
*=====================================================================================*/
/** error code so that the caller can determine exactly what went wrong */
public enum Cause {
/**
* An invalid path number was provided. getCauseIDs() returns the ID(s) of
* the invalid path, or paths.
*/
INVALID_PATH,
/**
* An invalid action ID was provided. getCauseIDs() returns the ID(s) of
* the invalid action, or actions.
*/
INVALID_ACTION,
/**
* An invalid file group ID was provided. getCauseIDs() returns the ID(s) of
* the invalid file group, or groups.
*/
INVALID_FILE_GROUP,
/**
* The type of the member is not valid (i.e. not IPackageMemberMgr.TYPE_*).
* getCauseIDs() returns the type number of the member.
*/
INVALID_MEMBER,
/**
* The package we're refactoring to is invalid, or is a folder. getCauseIDs() returns
* the ID of the package.
*/
INVALID_PACKAGE,
/**
* The file is still in use by one or more actions. getCauseIDs() returns the IDs of
* the actions that are using this path.
*/
PATH_IN_USE,
/**
* The path is still being generated by an action. getCauseIDs() returns the IDs
* of the action, or actions, that generate this path.
*/
PATH_IS_GENERATED,
/**
* The action is still in use because it generates a file that is needed. getCauseIDs()
* returns the paths that are busy (used by other actions).
*/
ACTION_IN_USE,
/**
* The action is not atomic, so this operation can not proceed. getCauseIDs() returns
* the ID(s) of the action, or actions, that are not atomic.
*/
ACTION_NOT_ATOMIC,
/**
* The action has been trashed, so this operation is invalid. getCauseIDs() returns the
* ID(s) of the action, or actions that are trashed.
*/
ACTION_IS_TRASHED,
/**
* Couldn't delete a directory, since it's still contains paths (files and subdirectories).
* getCauseIDs() returns the ID(s) of the directory (or directories) that are not empty.
*/
DIRECTORY_NOT_EMPTY,
/**
* The directory is used as the working directory for some actions. getCauseIDs()
* returns the ID(s) of the action, or actions, that are in the directory.
*/
DIRECTORY_CONTAINS_ACTIONS,
/**
* The path, or paths are not within the bounds (roots) of the destination package.
* getCauseIDs() return the ID(s) of the paths that are out of range.
*/
PATH_OUT_OF_RANGE,
/**
* There are multiple actions that generate a specific file, which is not allowed.
* getCauseIDs() return the ID of the file(s) that are modified.
*/
FILE_IS_MODIFIED,
/**
* The file to be deleted is still a member of a file group, and therefore can't be
* removed. getCauseIDs() returns the ID of the file groups that contain the file.
*/
FILE_STILL_IN_GROUP
}
/** The cause of the exception */
private Cause causeCode = null;
/** path, action or file group IDs that caused the failure */
private Integer[] causeIds = null;
/** Type of member that caused failure */
private int memberType = -1;
/*=====================================================================================*
* CONSTRUCTORS
*=====================================================================================*/
/**
* Create a new CanNotRefactorException, with a specific cause (and set of actions or
* paths) for the failure of the refactoring operation.
*
* @param causeCode Reason that the refactoring failed.
* @param args Optional arguments (file or action IDs) that provide more information.
*/
public CanNotRefactorException(Cause causeCode, Integer... args) {
super();
this.causeCode = causeCode;
causeIds = args;
}
/*=====================================================================================*
* PUBLIC METHODS
*=====================================================================================*/
/**
* @return The detailed cause of this exception.
*/
public Cause getCauseCode() {
return causeCode;
}
/*-------------------------------------------------------------------------------------*/
/**
* @return The list of path, action or file group IDs that caused the refactoring to fail.
* Or null, if this was not the cause.
*/
public Integer[] getCauseIDs() {
return causeIds;
}
/*-------------------------------------------------------------------------------------*/
}