1 19 20 21 package org.apache.cayenne.gen; 22 23 import java.util.Iterator ; 24 25 import org.apache.cayenne.map.DataMap; 26 import org.apache.cayenne.map.MappingNamespace; 27 import org.apache.cayenne.map.ObjEntity; 28 import org.apache.cayenne.map.Relationship; 29 30 36 public class EntityUtils { 37 38 protected String subClassName; 40 protected String superClassName; 41 protected String baseClassName; 42 protected String subPackageName; 43 protected String superPackageName; 44 protected String basePackageName; 45 46 protected DataMap primaryDataMap; 47 protected ObjEntity objEntity; 48 49 public EntityUtils(DataMap dataMap, ObjEntity objEntity, String fqnBaseClass, 50 String fqnSuperClass, String fqnSubClass) { 51 super(); 52 53 StringUtils stringUtils = StringUtils.getInstance(); 54 55 this.baseClassName = stringUtils.stripPackageName(fqnBaseClass); 56 this.basePackageName = stringUtils.stripClass(fqnBaseClass); 57 this.superClassName = stringUtils.stripPackageName(fqnSuperClass); 58 this.superPackageName = stringUtils.stripClass(fqnSuperClass); 59 this.subClassName = stringUtils.stripPackageName(fqnSubClass); 60 this.subPackageName = stringUtils.stripClass(fqnSubClass); 61 62 this.primaryDataMap = dataMap; 63 64 this.objEntity = objEntity; 65 } 66 67 71 public String getSubClassName() { 72 return subClassName; 73 } 74 75 79 public String getSuperClassName() { 80 return superClassName; 81 } 82 83 87 public String getBaseClassName() { 88 return baseClassName; 89 } 90 91 94 public String getSubPackageName() { 95 return subPackageName; 96 } 97 98 102 public String getSuperPackageName() { 103 return superPackageName; 104 } 105 106 110 public String getBasePackageName() { 111 return basePackageName; 112 } 113 114 118 public DataMap getPrimaryDataMap() { 119 return primaryDataMap; 120 } 121 122 127 public MappingNamespace getEntityResolver() { 128 return primaryDataMap.getNamespace(); 129 } 130 131 134 public boolean hasToManyRelationships() { 135 return hasToManyRelationships(objEntity); 136 } 137 138 141 public boolean hasToManyRelationships(ObjEntity anObjEntity) { 142 if (anObjEntity == null) { 143 return false; 144 } 145 146 Iterator it = anObjEntity.getRelationships().iterator(); 147 while (it.hasNext()) { 148 Relationship r = (Relationship) it.next(); 149 if (r.isToMany()) { 150 return true; 151 } 152 } 153 154 return false; 155 } 156 157 163 public boolean hasToManyDeclaredRelationships() { 164 return hasToManyDeclaredRelationships(objEntity); 165 } 166 167 173 public boolean hasToManyDeclaredRelationships(ObjEntity anObjEntity) { 174 if (anObjEntity == null) { 175 return false; 176 } 177 178 Iterator it = anObjEntity.getDeclaredRelationships().iterator(); 179 while (it.hasNext()) { 180 Relationship r = (Relationship) it.next(); 181 if (r.isToMany()) { 182 return true; 183 } 184 } 185 186 return false; 187 } 188 189 192 public boolean hasToOneRelationships() { 193 return hasToOneRelationships(objEntity); 194 } 195 196 199 public boolean hasToOneRelationships(ObjEntity anObjEntity) { 200 if (anObjEntity == null) { 201 return false; 202 } 203 204 Iterator it = anObjEntity.getRelationships().iterator(); 205 while (it.hasNext()) { 206 Relationship r = (Relationship) it.next(); 207 if (false == r.isToMany()) { 208 return true; 209 } 210 } 211 212 return false; 213 } 214 215 219 public boolean hasToOneDeclaredRelationships() { 220 return hasToOneDeclaredRelationships(objEntity); 221 } 222 223 227 public boolean hasToOneDeclaredRelationships(ObjEntity anObjEntity) { 228 if (anObjEntity == null) { 229 return false; 230 } 231 232 Iterator it = anObjEntity.getDeclaredRelationships().iterator(); 233 while (it.hasNext()) { 234 Relationship r = (Relationship) it.next(); 235 if (!r.isToMany()) { 236 return true; 237 } 238 } 239 240 return false; 241 } 242 } 243 | Popular Tags |