1 9 package org.jboss.portal.setup.impl.dl.dbloader; 10 11 import org.jboss.portal.setup.PortalSetupException; 12 13 import org.jboss.portal.setup.util.PropertyConverter; 14 15 import java.util.List ; 16 import java.util.StringTokenizer ; 17 import java.util.ArrayList ; 18 19 20 26 public class ValueRowMetaData 27 { 28 private List m_values = new ArrayList (); 29 30 public ValueRowMetaData(String values, List columns) throws PortalSetupException 31 { 32 if (null != values) 33 { 34 StringTokenizer strTk = new StringTokenizer (values, ",", false); 35 int i = 0; 36 while (strTk.hasMoreTokens()) 37 { 38 39 Object value = null; 40 String token = strTk.nextToken(); 41 if (token != null) 42 { 43 token = token.trim(); 44 int indexFirst = token.indexOf("'"); 46 int indexLast = token.lastIndexOf("'"); 47 48 if (indexFirst == -1 && indexLast == -1) 49 { 50 if (isFunction(token)) 52 { 53 value = new SqlFunctionMetaData(token); 55 } 56 else 57 { 58 value = resolveValue(token, (ColumnMetaData)columns.get(i)); 60 } 61 } 62 else 63 { 64 String stippedValueStr = token.substring(indexFirst + 1, indexLast); 65 value = resolveValue(stippedValueStr, (ColumnMetaData)columns.get(i)); 66 67 } 68 69 m_values.add(value); 70 i++; 71 } 72 } 73 } 74 else 75 { 76 throw new PortalSetupException("Value row cannot be null"); 77 } 78 } 79 80 private Object resolveValue(String oldValue, ColumnMetaData column) throws PortalSetupException 81 { 82 Object value = null; 83 Class javaClass = null; 84 try 85 { 86 javaClass = Class.forName(column.getJavaType()); 87 88 89 } 90 catch (ClassNotFoundException cnfe) 91 { 92 throw new PortalSetupException("Invalid java type specified", cnfe); 93 } 94 try 95 { 96 97 value = PropertyConverter.convertToValue(oldValue, javaClass); 98 99 } 100 catch (IllegalArgumentException iae) 101 { 102 throw new PortalSetupException("Fail to convert a string value = '" + oldValue + "' to java object of class '" + 103 column.getJavaType() + "'.", iae); 104 } 105 return value; 106 } 107 108 public List getValues() 109 { 110 return m_values; 111 } 112 113 private boolean isFunction(String strValue) 114 { 115 boolean retVal = false; 116 int index = strValue.indexOf("("); 117 if (index > 0) 118 { 119 String funcName = strValue.substring(0, index); 120 retVal = true; 121 } 124 return retVal; 125 } 126 127 128 } 129 | Popular Tags |