View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2009 Ordina and committers to Mod4j
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *     Ordina - initial implementation
10   *******************************************************************************/
11  package BusinessDomainDsl.validation;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  import BusinessDomainDsl.BusinessClass;
17  
18  public class ValidationUtils {
19  
20  	public static boolean circularInheritance(BusinessClass cls){
21  		if( cls.getSuperclass() == null ) { return false; }
22  
23  		List<BusinessClass> tmp = new ArrayList<BusinessClass>();
24  		return checkInheritance(tmp, cls.getSuperclass(), cls);
25  	}
26  	
27  	private static boolean checkInheritance(List<BusinessClass> children, BusinessClass cls, BusinessClass original) {
28  		if( children.contains(original) ) {
29  			return true;
30  		} else if( children.contains(cls) ){
31  			return false;
32  		} else {
33  			if( cls.getSuperclass() == null ) {
34  				return false; 
35  			}
36  			children.add(cls);
37  			return checkInheritance(children, cls.getSuperclass(), original);
38  		}
39  	}
40  }