1 package xdoclet.modules.ojb.constraints; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 6 import xdoclet.modules.ojb.model.*; 7 import xjavadoc.XClass; 8 9 23 24 29 public class InheritanceHelper 30 { 31 38 public static Class getClass(String name) throws ClassNotFoundException 39 { 40 try 41 { 42 return Class.forName(name); 43 } 44 catch (ClassNotFoundException ex) 45 { 46 throw new ClassNotFoundException (name); 47 } 48 } 49 58 public boolean isSameOrSubTypeOf(XClass type, String baseType, boolean checkActualClasses) throws ClassNotFoundException 59 { 60 String qualifiedBaseType = baseType.replace('$', '.'); 61 62 if (type.getQualifiedName().equals(qualifiedBaseType)) 63 { 64 return true; 65 } 66 67 ArrayList queue = new ArrayList (); 69 boolean canSpecify = false; 70 XClass curType; 71 72 queue.add(type); 73 while (!queue.isEmpty()) 74 { 75 curType = (XClass)queue.get(0); 76 queue.remove(0); 77 if (qualifiedBaseType.equals(curType.getQualifiedName())) 78 { 79 return true; 80 } 81 if (curType.getInterfaces() != null) 82 { 83 for (Iterator it = curType.getInterfaces().iterator(); it.hasNext(); ) 84 { 85 queue.add(it.next()); 86 } 87 } 88 if (!curType.isInterface()) 89 { 90 if (curType.getSuperclass() != null) 91 { 92 queue.add(curType.getSuperclass()); 93 } 94 } 95 } 96 97 return checkActualClasses ? isSameOrSubTypeOf(type.getQualifiedName(), qualifiedBaseType) : false; 99 } 100 101 110 public boolean isSameOrSubTypeOf(ClassDescriptorDef type, String baseType, boolean checkActualClasses) throws ClassNotFoundException 111 { 112 if (type.getQualifiedName().equals(baseType.replace('$', '.'))) 113 { 114 return true; 115 } 116 else if (type.getOriginalClass() != null) 117 { 118 return isSameOrSubTypeOf(type.getOriginalClass(), baseType, checkActualClasses); 119 } 120 else 121 { 122 return checkActualClasses ? isSameOrSubTypeOf(type.getName(), baseType) : false; 123 } 124 } 125 126 134 public boolean isSameOrSubTypeOf(String type, String baseType) throws ClassNotFoundException 135 { 136 return type.replace('$', '.').equals(baseType.replace('$', '.')) ? true : isSameOrSubTypeOf(getClass(type), baseType); 137 } 138 139 147 public boolean isSameOrSubTypeOf(Class type, String baseType) throws ClassNotFoundException 148 { 149 return type.getName().equals(baseType.replace('$', '.')) ? true : getClass(baseType).isAssignableFrom(type); 150 } 151 } 152 | Popular Tags |