1 23 24 25 26 31 32 package com.sun.jdo.spi.persistence.support.ejb.ejbqlc; 33 34 import java.lang.reflect.Method ; 35 import java.util.ResourceBundle ; 36 37 import com.sun.jdo.spi.persistence.utility.I18NHelper; 38 39 45 public class ParameterSupport 46 { 47 48 private Class [] parameterTypes; 49 50 54 private String [] parameterEjbNames; 55 56 57 protected final static ResourceBundle msgs = I18NHelper.loadBundle( 58 ParameterSupport.class); 59 60 64 public ParameterSupport(Method method) 65 { 66 this.parameterTypes = 67 (method == null) ? new Class [0] : method.getParameterTypes(); 68 this.parameterEjbNames = new String [this.parameterTypes.length]; 69 } 70 71 78 public Class getParameterType(String ejbqlParamDecl) 79 { 80 return getParameterType(getParamNumber(ejbqlParamDecl)); 81 } 82 83 89 public Class getParameterType(int paramNumber) 90 { 91 return parameterTypes[paramNumber - 1]; 94 } 95 96 104 public String getParameterEjbName(String ejbqlParamDecl) 105 { 106 return getParameterEjbName(getParamNumber(ejbqlParamDecl)); 107 } 108 109 114 public String getParameterEjbName(int paramNumber) 115 { 116 return parameterEjbNames[paramNumber - 1]; 117 } 118 119 128 public void setParameterEjbName(String ejbqlParamDecl, String ejbName) 129 { 130 parameterEjbNames[getParamNumber(ejbqlParamDecl) - 1] = ejbName; 131 } 132 133 137 public String [] getParameterEjbNames() 138 { 139 return parameterEjbNames; 140 } 141 142 149 public String getParameterName(String ejbqlParamDecl) 150 { 151 return getParameterName(getParamNumber(ejbqlParamDecl)); 152 } 153 154 158 public String getParameterName(int paramNumber) 159 { 160 return "_jdoParam" + String.valueOf(paramNumber); 161 } 162 163 167 public int getParameterCount() 168 { 169 return parameterTypes.length; 170 } 171 172 174 178 private int getParamNumber(String ejbqlParamDecl) 179 { 180 int paramNum = 0; 181 try { 182 paramNum = Integer.parseInt(ejbqlParamDecl.substring(1)); 183 } catch(Exception ex) { 184 ErrorMsg.error(I18NHelper.getMessage( 185 msgs, "EXC_InvalidParameterIndex", ejbqlParamDecl, String.valueOf(parameterTypes.length))); 187 } 188 if (paramNum < 1 || paramNum > parameterTypes.length) { 189 ErrorMsg.error(I18NHelper.getMessage( 190 msgs, "EXC_InvalidParameterIndex", ejbqlParamDecl, String.valueOf(parameterTypes.length))); 192 } 193 return paramNum; 194 } 195 } 196 | Popular Tags |