1 56 57 package org.objectstyle.cayenne.gen; 58 59 import java.util.Iterator ; 60 61 import org.objectstyle.cayenne.map.ObjEntity; 62 import org.objectstyle.cayenne.map.Relationship; 63 import org.objectstyle.cayenne.project.validator.MappingNamesHelper; 64 import org.objectstyle.cayenne.util.NameConverter; 65 66 75 public class ClassGenerationInfo { 76 77 protected ObjEntity entity; 78 79 protected String packageName; 81 protected String className; 82 protected String superPrefix; 83 protected String prop; 84 protected String superPackageName; 85 protected String superClassName; 86 87 90 public String getPackageName() { 91 return packageName; 92 } 93 94 97 protected void setPackageName(String packageName) { 98 this.packageName = packageName; 99 } 100 101 105 public String getSuperPackageName() { 106 return superPackageName; 107 } 108 109 113 protected void setSuperPackageName(String superPackageName) { 114 this.superPackageName = superPackageName; 115 } 116 117 121 public String getClassName() { 122 return className; 123 } 124 125 129 protected void setClassName(String className) { 130 this.className = className; 131 } 132 133 protected void setSuperPrefix(String superPrefix) { 134 this.superPrefix = superPrefix; 135 } 136 137 public String formatJavaType(String type) { 138 if (type != null) { 139 if (type.startsWith("java.lang.") && type.indexOf(10, '.') < 0) { 140 return type.substring("java.lang.".length()); 141 } 142 143 if (packageName != null 144 && type.startsWith(packageName + '.') 145 && type.indexOf(packageName.length() + 1, '.') < 0) { 146 return type.substring(packageName.length() + 1); 147 } 148 } 149 150 return type; 151 } 152 153 public String formatVariableName(String variableName) { 154 if (MappingNamesHelper.getInstance().isReservedJavaKeyword(variableName)) { 155 return "_" + variableName; 156 } else { 157 return variableName; 158 } 159 } 160 161 165 public String getSuperPrefix() { 166 return superPrefix; 167 } 168 169 173 public void setProp(String prop) { 174 this.prop = prop; 175 } 176 177 public String getProp() { 178 return prop; 179 } 180 181 186 public String capitalized(String name) { 187 if (name == null || name.length() == 0) 188 return name; 189 190 char c = Character.toUpperCase(name.charAt(0)); 191 return (name.length() == 1) ? Character.toString(c) : c + name.substring(1); 192 } 193 194 199 public String capitalizedAsConstant(String name) { 200 if (name == null || name.length() == 0) 201 return name; 202 203 return NameConverter.javaToUnderscored(name); 204 } 205 206 207 public String getCappedProp() { 208 return capitalized(prop); 209 } 210 211 217 public String getPropAsConstantName() { 218 return capitalizedAsConstant(prop); 219 } 220 221 226 public boolean isContainingListProperties() { 227 if (entity == null) { 228 return false; 229 } 230 231 Iterator it = entity.getRelationships().iterator(); 232 while(it.hasNext()) { 233 Relationship r = (Relationship) it.next(); 234 if(r.isToMany()) { 235 return true; 236 } 237 } 238 239 return false; 240 } 241 242 246 public boolean isUsingPackage() { 247 return packageName != null; 248 } 249 250 254 public boolean isUsingSuperPackage() { 255 return superPackageName != null; 256 } 257 258 259 public ObjEntity getEntity() { 260 return entity; 261 } 262 263 266 protected void setObjEntity(ObjEntity entity) { 267 this.entity = entity; 268 } 269 270 274 public String getSuperClassName() { 275 return superClassName; 276 } 277 278 282 protected void setSuperClassName(String value) { 283 this.superClassName = value; 284 } 285 } | Popular Tags |