1 56 57 package org.objectstyle.cayenne.gen; 58 59 import java.util.Iterator ; 60 61 import org.objectstyle.cayenne.map.DataMap; 62 import org.objectstyle.cayenne.map.MappingNamespace; 63 import org.objectstyle.cayenne.map.ObjEntity; 64 import org.objectstyle.cayenne.map.Relationship; 65 66 72 public class EntityUtils { 73 74 protected String subClassName; 76 protected String superClassName; 77 protected String baseClassName; 78 protected String subPackageName; 79 protected String superPackageName; 80 protected String basePackageName; 81 82 protected DataMap primaryDataMap; 83 protected ObjEntity objEntity; 84 85 public EntityUtils(DataMap dataMap, ObjEntity objEntity, String fqnBaseClass, String fqnSuperClass, String fqnSubClass) 86 { 87 super(); 88 89 StringUtils stringUtils = StringUtils.getInstance(); 90 91 this.baseClassName = stringUtils.stripPackageName(fqnBaseClass); 92 this.basePackageName = stringUtils.stripClass(fqnBaseClass); 93 this.superClassName = stringUtils.stripPackageName(fqnSuperClass); 94 this.superPackageName = stringUtils.stripClass(fqnSuperClass); 95 this.subClassName = stringUtils.stripPackageName(fqnSubClass); 96 this.subPackageName = stringUtils.stripClass(fqnSubClass); 97 98 this.primaryDataMap = dataMap; 99 100 this.objEntity = objEntity; 101 } 102 103 107 public String getSubClassName() { 108 return subClassName; 109 } 110 111 115 public String getSuperClassName() { 116 return superClassName; 117 } 118 119 123 public String getBaseClassName() { 124 return baseClassName; 125 } 126 127 130 public String getSubPackageName() { 131 return subPackageName; 132 } 133 134 138 public String getSuperPackageName() { 139 return superPackageName; 140 } 141 142 146 public String getBasePackageName() { 147 return basePackageName; 148 } 149 150 155 public DataMap getPrimaryDataMap() { 156 return primaryDataMap; 157 } 158 159 164 public MappingNamespace getEntityResolver() { 165 return primaryDataMap.getNamespace(); 166 } 167 168 173 public boolean hasToManyRelationships() { 174 return hasToManyRelationships(objEntity); 175 } 176 177 182 public boolean hasToManyRelationships(ObjEntity anObjEntity) { 183 if (anObjEntity == null) { 184 return false; 185 } 186 187 Iterator it = anObjEntity.getRelationships().iterator(); 188 while(it.hasNext()) { 189 Relationship r = (Relationship) it.next(); 190 if(r.isToMany()) { 191 return true; 192 } 193 } 194 195 return false; 196 } 197 198 203 public boolean hasToOneRelationships() { 204 return hasToOneRelationships(objEntity); 205 } 206 207 212 public boolean hasToOneRelationships(ObjEntity anObjEntity) { 213 if (anObjEntity == null) { 214 return false; 215 } 216 217 Iterator it = anObjEntity.getRelationships().iterator(); 218 while(it.hasNext()) { 219 Relationship r = (Relationship) it.next(); 220 if(false == r.isToMany()) { 221 return true; 222 } 223 } 224 225 return false; 226 } 227 } | Popular Tags |