1 18 19 package org.objectweb.jac.core.parsers.xml; 20 21 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.core.ConfigMethod; 24 import org.w3c.dom.*; 25 26 public class MethodElementInterpreter { 27 static Logger logger = Logger.getLogger("xml"); 28 29 public MethodElementInterpreter() { 30 } 31 32 public ConfigMethod interpret(Element methodElement, Class targetClass) 33 throws Exception 34 { 35 logger.debug("interpreting method "+methodElement.getAttribute("name")); 36 NodeList argElements = methodElement.getElementsByTagName("arg"); 37 int argCount = argElements.getLength(); 38 Object [] values = new Object [argCount]; 40 41 for ( int argIndex=0; argIndex<argCount; argIndex++ ) { 42 Element argElement = (Element)argElements.item( argIndex ); 43 values[argIndex] = interpretArgument(argElement); 44 } 45 46 return new ConfigMethod(methodElement.getAttribute("name"), values); 47 } 48 49 protected Object interpretArgument(Element argElement) { 50 if (argElement.getAttribute("type").equals("java.lang.reflect.Array")) { 51 return interpretArray(argElement); 52 } else { 53 return argElement.getAttribute("value"); 54 } 55 } 56 57 58 protected Object [] interpretArray(Element argElement) 59 { 60 NodeList itemElements = argElement.getElementsByTagName("item"); 61 int itemCount = itemElements.getLength(); 62 Object [] array = new Object [itemCount]; 63 for (int i=0; i<itemCount; i++) { 64 Element itemElement = (Element)itemElements.item(i); 65 array[i] = interpretArgument(itemElement); 66 } 67 return array; 68 } 69 } 70 | Popular Tags |