KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > parsers > xml > MethodElementInterpreter


1 /*
2   Copyright (C) 2002 Zachary Medico
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

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 JavaDoc targetClass)
33         throws Exception JavaDoc
34     {
35         logger.debug("interpreting method "+methodElement.getAttribute("name"));
36         NodeList argElements = methodElement.getElementsByTagName("arg");
37         int argCount = argElements.getLength();
38         // Class[] types = new Class[argCount];
39
Object JavaDoc[] values = new Object JavaDoc[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 JavaDoc 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     /* handle Array arguments */
58     protected Object JavaDoc[] interpretArray(Element argElement)
59     {
60         NodeList itemElements = argElement.getElementsByTagName("item");
61         int itemCount = itemElements.getLength();
62         Object JavaDoc[] array = new Object JavaDoc[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