1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.lang.reflect.Method ; 25 import org.jboss.deployment.DeploymentException; 26 import org.jboss.metadata.MetaData; 27 import org.w3c.dom.Element ; 28 29 36 public final class JDBCValuePropertyMetaData { 37 private final String propertyName; 38 private final Class propertyType; 39 private final String columnName; 40 private final String sqlType; 41 private final int jdbcType; 42 private final boolean notNull; 43 private final Method getter; 44 private final Method setter; 45 46 56 public JDBCValuePropertyMetaData(Element element, Class classType) 57 throws DeploymentException { 58 59 propertyName = MetaData.getUniqueChildContent(element, "property-name"); 61 62 String columnNameString = 64 MetaData.getOptionalChildContent(element, "column-name"); 65 if(columnNameString != null) { 66 columnName = columnNameString; 67 } else { 68 columnName = propertyName; 69 } 70 71 Element notNullElement = MetaData.getOptionalChild(element, "not-null"); 73 notNull = (notNullElement != null); 74 75 try { 77 getter = classType.getMethod(toGetterName(propertyName), new Class [0]); 78 } catch(Exception e) { 79 throw new DeploymentException("Unable to find getter for property " + 80 propertyName + " on dependent value class " + 81 classType.getName()); 82 } 83 84 propertyType = getter.getReturnType(); 86 87 try { 89 setter = classType.getMethod( 90 toSetterName(propertyName), 91 new Class [] { propertyType } ); 92 } catch(Exception e) { 93 throw new DeploymentException("Unable to find setter for property " + 94 propertyName + " on dependent value class " + 95 classType.getName()); 96 } 97 98 String jdbcString = 100 MetaData.getOptionalChildContent(element, "jdbc-type"); 101 if(jdbcString != null) { 102 jdbcType = JDBCMappingMetaData.getJdbcTypeFromName(jdbcString); 103 104 sqlType = MetaData.getUniqueChildContent(element, "sql-type"); 106 } else { 107 jdbcType = Integer.MIN_VALUE; 108 sqlType = null; 109 } 110 } 111 112 119 public String getPropertyName() { 120 return propertyName; 121 } 122 123 129 public Class getPropertyType() { 130 return propertyType; 131 } 132 133 138 public String getColumnName() { 139 return columnName; 140 } 141 142 148 public int getJDBCType() { 149 return jdbcType; 150 } 151 152 158 public String getSqlType() { 159 return sqlType; 160 } 161 162 166 public boolean isNotNull() { 167 return notNull; 168 } 169 170 176 public Method getGetter() { 177 return getter; 178 } 179 180 186 public Method getSetter() { 187 return setter; 188 } 189 190 private static String toGetterName(String propertyName) { 191 return "get" + upCaseFirstCharacter(propertyName); 192 } 193 194 private static String toSetterName(String propertyName) { 195 return "set" + upCaseFirstCharacter(propertyName); 196 } 197 198 private static String upCaseFirstCharacter(String propertyName) { 199 return Character.toUpperCase(propertyName.charAt(0)) + 200 propertyName.substring(1); 201 } 202 } 203 | Popular Tags |