1 19 20 21 package org.apache.cayenne.gen; 22 23 import java.util.Iterator ; 24 25 import org.apache.cayenne.map.ObjEntity; 26 import org.apache.cayenne.map.Relationship; 27 import org.apache.cayenne.project.validator.MappingNamesHelper; 28 import org.apache.cayenne.util.NameConverter; 29 30 39 public class ClassGenerationInfo { 40 41 protected ObjEntity entity; 42 43 protected String packageName; 45 protected String className; 46 protected String superPrefix; 47 protected String prop; 48 protected String superPackageName; 49 protected String superClassName; 50 51 54 public String getPackageName() { 55 return packageName; 56 } 57 58 61 protected void setPackageName(String packageName) { 62 this.packageName = packageName; 63 } 64 65 69 public String getSuperPackageName() { 70 return superPackageName; 71 } 72 73 77 protected void setSuperPackageName(String superPackageName) { 78 this.superPackageName = superPackageName; 79 } 80 81 85 public String getClassName() { 86 return className; 87 } 88 89 93 protected void setClassName(String className) { 94 this.className = className; 95 } 96 97 protected void setSuperPrefix(String superPrefix) { 98 this.superPrefix = superPrefix; 99 } 100 101 public String formatJavaType(String type) { 102 if (type != null) { 103 if (type.startsWith("java.lang.") && type.indexOf('.', 10) < 0) { 104 return type.substring("java.lang.".length()); 105 } 106 107 if (packageName != null 108 && type.startsWith(packageName + '.') 109 && type.indexOf(packageName.length() + 1, '.') < 0) { 110 return type.substring(packageName.length() + 1); 111 } 112 } 113 114 return type; 115 } 116 117 public String formatVariableName(String variableName) { 118 if (MappingNamesHelper.getInstance().isReservedJavaKeyword(variableName)) { 119 return "_" + variableName; 120 } else { 121 return variableName; 122 } 123 } 124 125 129 public String getSuperPrefix() { 130 return superPrefix; 131 } 132 133 137 public void setProp(String prop) { 138 this.prop = prop; 139 } 140 141 public String getProp() { 142 return prop; 143 } 144 145 150 public String capitalized(String name) { 151 if (name == null || name.length() == 0) 152 return name; 153 154 char c = Character.toUpperCase(name.charAt(0)); 155 return (name.length() == 1) ? Character.toString(c) : c + name.substring(1); 156 } 157 158 163 public String capitalizedAsConstant(String name) { 164 if (name == null || name.length() == 0) 165 return name; 166 167 return NameConverter.javaToUnderscored(name); 168 } 169 170 171 public String getCappedProp() { 172 return capitalized(prop); 173 } 174 175 181 public String getPropAsConstantName() { 182 return capitalizedAsConstant(prop); 183 } 184 185 190 public boolean isContainingDeclaredListProperties() { 191 if (entity == null) { 192 return false; 193 } 194 195 Iterator it = entity.getDeclaredRelationships().iterator(); 196 while(it.hasNext()) { 197 Relationship r = (Relationship) it.next(); 198 if(r.isToMany()) { 199 return true; 200 } 201 } 202 203 return false; 204 } 205 206 211 public boolean isContainingListProperties() { 212 if (entity == null) { 213 return false; 214 } 215 216 Iterator it = entity.getRelationships().iterator(); 217 while(it.hasNext()) { 218 Relationship r = (Relationship) it.next(); 219 if(r.isToMany()) { 220 return true; 221 } 222 } 223 224 return false; 225 } 226 227 231 public boolean isUsingPackage() { 232 return packageName != null; 233 } 234 235 239 public boolean isUsingSuperPackage() { 240 return superPackageName != null; 241 } 242 243 244 public ObjEntity getEntity() { 245 return entity; 246 } 247 248 251 protected void setObjEntity(ObjEntity entity) { 252 this.entity = entity; 253 } 254 255 259 public String getSuperClassName() { 260 return superClassName; 261 } 262 263 267 protected void setSuperClassName(String value) { 268 this.superClassName = value; 269 } 270 } 271 | Popular Tags |