/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope;

/**
 * Signals, that an attempt to write an attribute has been failed,
 * because it cannot be written with any value.
 *
 * This exception will be thrown by {@link Item#set(FunctionAttribute,Object) Item.set}
 * if that attribute is {@link Attribute#isFinal() final}.
 * 
 * @author Ralf Wiebicke
 */
public final class FinalViolationException extends ConstraintViolationException
{

	private final Item item;
	private final Attribute readOnlyAttribute;
	
	/**
	 * Creates a new FinalViolationException with the neccessary information about the violation.
	 * @param item initializes, what is returned by {@link #getItem()}.
	 * @param readOnlyAttribute initializes, what is returned by {@link #getFinalAttribute()}.
	 */
	public FinalViolationException(final Item item, final Attribute readOnlyAttribute)
	{
		super(null);
		this.item = item;
		this.readOnlyAttribute = readOnlyAttribute;
	}
	
	/**
	 * Returns the item that was attempted to be modified.
	 */
	public final Item getItem()
	{
		return item;
	}

	/**
	 * Returns the attribute, that was attempted to be written.
	 */
	public Attribute getFinalAttribute()
	{
		return readOnlyAttribute;
	}

	public String getMessage()
	{
		return "read-only violation on " + item.getCopeID() + " for " + readOnlyAttribute;
	}
	
}

/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope;

/**
 * Signals, that an attempt to write an attribute has been failed,
 * because it cannot be written with any value.
 *
 * This exception will be thrown by {@link Item#set(FunctionAttribute,Object) Item.set}
 * if that attribute is {@link Attribute#isFinal() final}.
 * 
 * @author Ralf Wiebicke
 */
public final class FinalViolationException extends ConstraintViolationException
{

	private final Item item;
	private final Attribute finalAttribute;
	
	/**
	 * Creates a new FinalViolationException with the neccessary information about the violation.
	 * @param item initializes, what is returned by {@link #getItem()}.
	 * @param finalAttribute initializes, what is returned by {@link #getFinalAttribute()}.
	 */
	public FinalViolationException(final Item item, final Attribute finalAttribute)
	{
		super(null);
		this.item = item;
		this.finalAttribute = finalAttribute;
	}
	
	/**
	 * Returns the item that was attempted to be modified.
	 */
	public final Item getItem()
	{
		return item;
	}

	/**
	 * Returns the attribute, that was attempted to be written.
	 */
	public Attribute getFinalAttribute()
	{
		return finalAttribute;
	}

	public String getMessage()
	{
		return "read-only violation on " + item.getCopeID() + " for " + finalAttribute;
	}
	
}

rename readOnlyAttribute to finalAttribute