1 28 29 package com.caucho.ejb.cfg; 30 31 import com.caucho.amber.field.IdField; 32 import com.caucho.amber.manager.AmberPersistenceUnit; 33 import com.caucho.amber.type.EntityType; 34 import com.caucho.bytecode.JClass; 35 import com.caucho.bytecode.JMethod; 36 import com.caucho.config.ConfigException; 37 import com.caucho.util.CharBuffer; 38 import com.caucho.util.L10N; 39 40 43 public class CmpProperty { 44 private static final L10N L = new L10N(CmpProperty.class); 45 46 private EjbEntityBean _entity; 47 48 private String _location; 49 50 private String _name; 51 private String _description; 52 53 private boolean _isId; 54 55 60 public CmpProperty(EjbEntityBean entity) 61 { 62 _entity = entity; 63 } 64 65 68 public EjbEntityBean getEntity() 69 { 70 return _entity; 71 } 72 73 76 public EjbEntityBean getBean() 77 { 78 return _entity; 79 } 80 81 84 public void setConfigLocation(String filename, int line) 85 { 86 _location = filename + ":" + line + ": "; 87 } 88 89 92 public void setLocation(String location) 93 { 94 if (location != null) 95 _location = location; 96 } 97 98 101 public String getLocation() 102 { 103 if (_location != null) 104 return _location; 105 else 106 return _entity.getLocation(); 107 } 108 109 112 public void setFieldName(String name) 113 { 114 _name = name; 115 } 116 117 120 public String getName() 121 { 122 return _name; 123 } 124 125 128 public void setId(boolean id) 129 { 130 _isId = id; 131 } 132 133 136 public boolean isId() 137 { 138 return _isId; 139 } 140 141 144 public void setDescription(String description) 145 { 146 _description = description; 147 } 148 149 152 public JMethod getGetter() 153 { 154 String methodName = ("get" + 155 Character.toUpperCase(_name.charAt(0)) + 156 _name.substring(1)); 157 158 return _entity.getMethod(methodName, new JClass[0]); 159 } 160 161 164 public JMethod getSetter() 165 { 166 String methodName = ("set" + 167 Character.toUpperCase(_name.charAt(0)) + 168 _name.substring(1)); 169 170 JMethod getter = getGetter(); 171 172 if (getter != null) 173 return _entity.getMethod(methodName, 174 new JClass[] { getter.getReturnType() }); 175 else 176 return null; 177 } 178 179 182 public IdField createId(AmberPersistenceUnit amberPersistenceUnit, EntityType type) 183 throws ConfigException 184 { 185 throw new UnsupportedOperationException (getClass().getName()); 186 } 187 188 static String toSqlName(String name) 189 { 190 CharBuffer cb = new CharBuffer(); 191 192 for (int i = 0; i < name.length(); i++) { 193 char ch = name.charAt(i); 194 195 if (! Character.isUpperCase(ch)) 196 cb.append(ch); 197 else if (i > 0 && ! Character.isUpperCase(name.charAt(i - 1))) { 198 cb.append("_"); 199 cb.append(Character.toLowerCase(ch)); 200 } 201 else if (i + 1 < name.length() && 202 ! Character.isUpperCase(name.charAt(i + 1))) { 203 cb.append("_"); 204 cb.append(Character.toLowerCase(ch)); 205 } 206 else 207 cb.append(Character.toLowerCase(ch)); 208 } 209 210 return cb.toString(); 211 } 212 213 public String toString() 214 { 215 return "CmpProperty[" + _name + "]"; 216 } 217 } 218 | Popular Tags |