/*
 * 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.instrument;


final class CopeUniqueConstraint
{
	final String name;
	final int modifier;
	final CopeAttribute[] copeAttributes;
	
	/**
	 * For constraints covering more than one attribute.
	 */
	CopeUniqueConstraint(final JavaAttribute javaAttribute, final CopeAttribute[] copeAttributes)
	{
		this.name = javaAttribute.name;
		this.modifier = javaAttribute.modifier;
		this.copeAttributes = copeAttributes;

		final CopeClass copeClass = CopeClass.getCopeClass(copeAttributes[0].javaAttribute.parent);
		copeClass.add(this);

		/*
		final ArrayList xAttributeNames = new ArrayList();
		for(int i = 0; i<copeAttributes.length; i++)
			xAttributeNames.add(copeAttributes[i].javaAttribute.name);
		System.out.println("------uniqueconstraint:"+name+xAttributeNames);

		final UniqueConstraint rtvalue = (UniqueConstraint)javaAttribute.evaluate();
		final ArrayList rtAttributeNames = new ArrayList();
		for(Iterator i = rtvalue.getUniqueAttributes().iterator(); i.hasNext(); )
		{
			final ObjectAttribute attribute = (ObjectAttribute)i.next();
			final JavaAttribute ja = (JavaAttribute)javaAttribute.parent.getByRtValue(attribute);
			rtAttributeNames.add(ja.name);
		}
		System.out.println("------uniqueconstraint:"+name+rtAttributeNames);
		*/
	}
	
	/**
	 * For constraints covering exactly one attribute.
	 */
	CopeUniqueConstraint(final CopeAttribute copeAttribute)
	{
		this.name = copeAttribute.getName();
		this.modifier = copeAttribute.javaAttribute.modifier;
		this.copeAttributes = new CopeAttribute[]{copeAttribute};
	}
	
}

@@ -834,16 +834,154 @@
 ument;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Iterator;%0A%0Aimport com.exedio.cope.ObjectAttribute;%0Aimport com.exedio.cope.UniqueConstraint;%0A%0A
 %0Afinal c
@@ -1490,17 +1490,99 @@
 s);%0A%0A%09%09/
-*
+/show(javaAttribute);%0A%09%7D%0A%09%0A%09private void show(final JavaAttribute javaAttribute)%0A%09%7B
 %0A%09%09final
@@ -2211,16 +2211,16 @@
 e);%0A%09%09%7D%0A
+
 %09%09System
@@ -2286,13 +2286,8 @@
 s);%0A
-%09%09*/%0A
 %09%7D%0A%09

introduce show()