// Path: OCM Compiler/src/com/kissintellignetsystems/ocm/compiler/parser/ASTColumnFamily.java
// public class ASTColumnFamily extends SimpleNode {
// 	
// 	private String name;
// 	private String nameUpperCase;
// 	
// 	private String entityName = "";
// 	
// 	private String comment = "";
// 	private String compareWith = "";
// 	private String compareSubcolumnsWith = "";
// 	
//   public ASTColumnFamily(int id) {
//     super(id);
//   }
// 
//   public ASTColumnFamily(OCMParser p, int id) {
//     super(p, id);
//   }
// 
// public String getName() {
// 	return name;
// }
// 
// public void setName(String name) {
// 	
// 	this.nameUpperCase = name.substring(0,1);
// 	this.nameUpperCase = nameUpperCase.toUpperCase(Locale.UK);
// 	
// 	String rest =  name.substring(1);
// 	
// 	//Store both versions of the name
// 	this.name = name;
// 	this.nameUpperCase = nameUpperCase + rest;
// }
// 
// public String getNameUpperCase() {
// 	return nameUpperCase;
// }
// 
// public void setAnnotation(String anName, String anValue)
// {
// 	//Remove the outside quotes
// 	String value = anValue.substring(1, anValue.length() - 1);
// 	
// 	if(anName.equals("EntityName"))
// 	{
// 		//Make sure the entity names first letter is upper case
// 		entityName = value.substring(0,1).toUpperCase(Locale.UK) + value.substring(1);
// 	}
// 	
// 	else if(anName.equals("Comment"))
// 	{
// 		comment = value;
// 	}
// 	
// 	else if(anName.equals("CompareWith"))
// 	{
// 		compareWith = value;
// 	}
// 	
// 	else if(anName.equals("CompareSubcolumnsWith"))
// 	{
// 		compareSubcolumnsWith = value;
// 	}
// }
// 
// public String toString() { return "\nColumn Family: " + getName() + " Entity Name: " + entityName;}
// public String toString(String prefix) { return prefix + toString(); }
// 
// public String getEntityName() {
// 	return entityName;
// }
// 
// public String getComment() {
// 	return comment;
// }
// 
// public String getCompareWith() {
// 	return compareWith;
// }
// 
// public String getCompareSubcolumnsWith() {
// 	return compareSubcolumnsWith;
// }
// 
//   
// }
// 
// Path: OCM Compiler/src/com/kissintellignetsystems/ocm/compiler/parser/ASTMany2Many.java
// public class ASTMany2Many extends SimpleNode {
// 	
// 	private String name;
// 	private String nameUpperCase;
// 	
// 	private String columnFamily;
// 	private String field;
// 	
// 
// public ASTMany2Many(int id) {
//     super(id);
//   }
// 
//   public ASTMany2Many(OCMParser p, int id) {
//     super(p, id);
//   }
// 
//   public String getName() {
// 		return name;
// 	}
//   
//   public void setName(String name) {
// 		
// 		this.nameUpperCase = name.substring(0,1);
// 		this.nameUpperCase = nameUpperCase.toUpperCase(Locale.UK);
// 		
// 		String rest =  name.substring(1);
// 		
// 		//Store both versions of the name
// 		this.name = nameUpperCase.toLowerCase(Locale.UK) + rest;
// 		this.nameUpperCase = nameUpperCase + rest;
// 	}
//   
//   public String getNameUpperCase() {
// 		return nameUpperCase;
// 	}
//   
// public String toString() { return "Many 2 Many: " + getName() + " Destination: " + columnFamily + "." + field;}
// public String toString(String prefix) { return prefix + toString(); }
// 
// public String getColumnFamily() {
// 	return columnFamily;
// }
// 
// public void setColumnFamily(String columnFamily) {
// 	this.columnFamily = columnFamily;
// }
// 
// public String getField() {
// 	return field;
// }
// 
// public void setField(String field) {
// 	this.field = field;
// }
// 
// 
// 
// 
//   
// }


import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import com.kissintellignetsystems.ocm.compiler.parser.ASTColumnFamily;
import com.kissintellignetsystems.ocm.compiler.parser.ASTMany2Many;
/*
	Copyright 2010 KISS Intelligent Systems Limited
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
	
*/


package com.kissintellignetsystems.ocm.compiler;



public class Validator 
{
	public boolean validate(List<ASTColumnFamily> columnFamilies)
	{
		//We only validate the Many 2 Many Columns so far
		return validateMany2ManyColumns(columnFamilies);
	}
	
	private boolean validateMany2ManyColumns(List<ASTColumnFamily> columnFamilies)
	{
		//In the Form Column.Family to Column.Family
		Hashtable<String,String> relationships = new Hashtable<String, String>();
		
		
		for(int count=0; count < columnFamilies.size(); count++)
		{
			//Get the Column Family
			ASTColumnFamily family = columnFamilies.get(count);
		
			for(int count2=1; count2< family.jjtGetNumChildren(); count2++)
			{
				//Get the column family			
// Path: OCM Compiler/src/com/kissintellignetsystems/ocm/compiler/parser/ASTColumnFamily.java
// public class ASTColumnFamily extends SimpleNode {
// 	
// 	private String name;
// 	private String nameUpperCase;
// 	
// 	private String entityName = "";
// 	
// 	private String comment = "";
// 	private String compareWith = "";
// 	private String compareSubcolumnsWith = "";
// 	
//   public ASTColumnFamily(int id) {
//     super(id);
//   }
// 
//   public ASTColumnFamily(OCMParser p, int id) {
//     super(p, id);
//   }
// 
// public String getName() {
// 	return name;
// }
// 
// public void setName(String name) {
// 	
// 	this.nameUpperCase = name.substring(0,1);
// 	this.nameUpperCase = nameUpperCase.toUpperCase(Locale.UK);
// 	
// 	String rest =  name.substring(1);
// 	
// 	//Store both versions of the name
// 	this.name = name;
// 	this.nameUpperCase = nameUpperCase + rest;
// }
// 
// public String getNameUpperCase() {
// 	return nameUpperCase;
// }
// 
// public void setAnnotation(String anName, String anValue)
// {
// 	//Remove the outside quotes
// 	String value = anValue.substring(1, anValue.length() - 1);
// 	
// 	if(anName.equals("EntityName"))
// 	{
// 		//Make sure the entity names first letter is upper case
// 		entityName = value.substring(0,1).toUpperCase(Locale.UK) + value.substring(1);
// 	}
// 	
// 	else if(anName.equals("Comment"))
// 	{
// 		comment = value;
// 	}
// 	
// 	else if(anName.equals("CompareWith"))
// 	{
// 		compareWith = value;
// 	}
// 	
// 	else if(anName.equals("CompareSubcolumnsWith"))
// 	{
// 		compareSubcolumnsWith = value;
// 	}
// }
// 
// public String toString() { return "\nColumn Family: " + getName() + " Entity Name: " + entityName;}
// public String toString(String prefix) { return prefix + toString(); }
// 
// public String getEntityName() {
// 	return entityName;
// }
// 
// public String getComment() {
// 	return comment;
// }
// 
// public String getCompareWith() {
// 	return compareWith;
// }
// 
// public String getCompareSubcolumnsWith() {
// 	return compareSubcolumnsWith;
// }
// 
//   
// }
// 
// Path: OCM Compiler/src/com/kissintellignetsystems/ocm/compiler/parser/ASTMany2Many.java
// public class ASTMany2Many extends SimpleNode {
// 	
// 	private String name;
// 	private String nameUpperCase;
// 	
// 	private String columnFamily;
// 	private String field;
// 	
// 
// public ASTMany2Many(int id) {
//     super(id);
//   }
// 
//   public ASTMany2Many(OCMParser p, int id) {
//     super(p, id);
//   }
// 
//   public String getName() {
// 		return name;
// 	}
//   
//   public void setName(String name) {
// 		
// 		this.nameUpperCase = name.substring(0,1);
// 		this.nameUpperCase = nameUpperCase.toUpperCase(Locale.UK);
// 		
// 		String rest =  name.substring(1);
// 		
// 		//Store both versions of the name
// 		this.name = nameUpperCase.toLowerCase(Locale.UK) + rest;
// 		this.nameUpperCase = nameUpperCase + rest;
// 	}
//   
//   public String getNameUpperCase() {
// 		return nameUpperCase;
// 	}
//   
// public String toString() { return "Many 2 Many: " + getName() + " Destination: " + columnFamily + "." + field;}
// public String toString(String prefix) { return prefix + toString(); }
// 
// public String getColumnFamily() {
// 	return columnFamily;
// }
// 
// public void setColumnFamily(String columnFamily) {
// 	this.columnFamily = columnFamily;
// }
// 
// public String getField() {
// 	return field;
// }
// 
// public void setField(String field) {
// 	this.field = field;
// }
// 
// 
// 
// 
//   
// }


// Path: OCM Compiler/src/com/kissintellignetsystems/ocm/compiler/Validator.java
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import com.kissintellignetsystems.ocm.compiler.parser.ASTColumnFamily;
import com.kissintellignetsystems.ocm.compiler.parser.ASTMany2Many;

/*
	Copyright 2010 KISS Intelligent Systems Limited
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
	
*/


package com.kissintellignetsystems.ocm.compiler;



public class Validator 
{
	public boolean validate(List<ASTColumnFamily> columnFamilies)
	{
		//We only validate the Many 2 Many Columns so far
		return validateMany2ManyColumns(columnFamilies);
	}
	
	private boolean validateMany2ManyColumns(List<ASTColumnFamily> columnFamilies)
	{
		//In the Form Column.Family to Column.Family
		Hashtable<String,String> relationships = new Hashtable<String, String>();
		
		
		for(int count=0; count < columnFamilies.size(); count++)
		{
			//Get the Column Family
			ASTColumnFamily family = columnFamilies.get(count);
		
			for(int count2=1; count2< family.jjtGetNumChildren(); count2++)
			{
				//Get the column family			
				Object familyObj = family.jjtGetChild(count2);