1 19 20 package org.netbeans.modules.j2ee.sun.validation.impl; 21 22 import java.lang.reflect.Method ; 23 import java.text.MessageFormat ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 27 28 import org.netbeans.modules.schema2beans.BaseBean; 29 import org.netbeans.modules.schema2beans.BaseProperty; 30 31 import org.netbeans.modules.j2ee.sun.validation.Constants; 32 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader; 33 import org.netbeans.modules.j2ee.sun.validation.util.Utils; 34 import org.netbeans.modules.j2ee.sun.validation.Validatee; 35 36 41 42 public class ValidateeImpl implements Validatee { 43 44 private BaseBean baseBean = null; 45 46 private Utils utils = null; 47 48 49 public ValidateeImpl(Object baseBean){ 50 this.baseBean = (BaseBean)baseBean; 51 utils = new Utils(); 52 } 53 54 55 public ArrayList getElementNames(){ 56 ArrayList elements = new ArrayList (); 57 BaseProperty[] baseProperty = baseBean.listProperties(); 58 int size = baseProperty.length; 59 for(int i=0; i<size; i++){ 60 elements.add(baseProperty[i].getName()); 61 } 70 return elements; 71 } 72 73 74 public ArrayList getElementDtdNames(){ 75 ArrayList elements = new ArrayList (); 76 BaseProperty[] baseProperty = baseBean.listProperties(); 77 int size = baseProperty.length; 78 for(int i=0; i<size; i++){ 79 elements.add(baseProperty[i].getDtdName()); 80 } 86 return elements; 87 } 88 89 90 public boolean isIndexed(String elementName){ 91 BaseProperty baseProperty = baseBean.getProperty(elementName); 92 boolean returnValue = false; 93 if(null != baseProperty) { 94 returnValue = baseProperty.isIndexed(); 95 } else { 96 String format = 97 BundleReader.getValue("Error_does_not_exists"); Object [] arguments = 99 new Object []{"Property", elementName}; String message = MessageFormat.format(format, arguments); 101 assert false : message; 102 } 103 return returnValue; 104 } 105 106 107 public int getElementCardinal(String elementName){ 108 BaseProperty baseProperty = baseBean.getProperty(elementName); 109 int returnValue = -1; 110 if(null != baseProperty) { 111 returnValue = baseProperty.getInstanceType(); 112 } else { 113 String format = 114 BundleReader.getValue("Error_does_not_exists"); Object [] arguments = 116 new Object []{"Property", elementName}; String message = MessageFormat.format(format, arguments); 118 assert false : message; 119 } 120 return returnValue; 121 } 122 123 124 public int getCardinal(){ 125 String name = baseBean.name(); 126 BaseBean parent = baseBean.parent(); 127 BaseProperty baseProperty = parent.getProperty(name); 128 return baseProperty.getInstanceType(); 129 } 130 131 132 public boolean isBeanElement(String elementName){ 133 BaseProperty baseProperty = baseBean.getProperty(elementName); 134 boolean returnValue = false; 135 if(null != baseProperty) { 136 returnValue = baseProperty.isBean(); 137 } else { 138 String format = 139 BundleReader.getValue("Error_does_not_exists"); Object [] arguments = 141 new Object []{"Property", elementName}; String message = MessageFormat.format(format, arguments); 143 assert false : message; 144 } 145 return returnValue; 146 } 147 148 149 public String getXPath(){ 150 156 BaseBean bean = baseBean; 157 BaseBean parentBean = null; 158 String xpath = bean.dtdName(); 159 boolean root = isRootElement(bean); 161 parentBean = bean.parent(); 162 while(!root){ 163 xpath = parentBean.dtdName() + Constants.XPATH_DELIMITER + xpath; 164 bean = parentBean; 165 parentBean = bean.parent(); 166 root = isRootElement(bean); 168 } 169 xpath = Constants.XPATH_DELIMITER + xpath; 170 return xpath; 171 } 172 173 174 public String getIndexedXPath() { 175 BaseBean bean = baseBean; 176 BaseBean parentBean = null; 177 String xpath = bean.dtdName(); 178 int index = getIndex(baseBean); 179 if(index != -1){ 180 xpath = utils.getIndexedName(xpath, index); 181 } 182 183 boolean root = isRootElement(bean); 184 parentBean = bean.parent(); 185 186 String name = null; 187 while(!root){ 188 name = parentBean.dtdName(); 189 index = getIndex(parentBean); 190 if(index != -1) { 191 name = utils.getIndexedName(name, index); 192 } 193 xpath = name + Constants.XPATH_DELIMITER + xpath; 194 bean = parentBean; 195 parentBean = bean.parent(); 196 root = isRootElement(bean); 197 } 198 xpath = Constants.XPATH_DELIMITER + xpath; 199 return xpath; 200 } 201 202 203 boolean isRootElement(BaseBean bean){ 204 BaseBean parent = bean.parent(); 205 boolean root; 206 if(parent.name().equals(bean.name())){ 207 root = true; 208 } else { 209 root = false; 210 } 211 return root; 212 } 213 214 215 int getIndex(BaseBean baseBean){ 216 int index = -1; 217 boolean root = isRootElement(baseBean); 218 if(!root){ 219 String name = baseBean.name(); 220 BaseBean parent = baseBean.parent(); 221 if(parent != null) { 222 index = parent.indexOf(name, baseBean); 223 } 224 } 225 return index; 226 } 227 228 229 public Object getElement(String elementName, int index) { 230 return utils.getElement(elementName, index, baseBean); 231 } 232 233 public Object getElement(String elementName) { 234 return utils.getElement(elementName, baseBean); 235 } 236 237 public Object [] getElements(String elementName) { 238 return utils.getElements(elementName, baseBean); 239 } 240 241 public Method getMethod(String methodName) { 242 return utils.getMethod(utils.getClass(baseBean), methodName); 243 } 244 245 public Object invoke(Method method) { 246 return utils.invoke(baseBean, method); 247 } 248 } 249 | Popular Tags |