1 16 17 package de.gulden.util.javasource; 18 19 import de.gulden.util.javasource.jjt.Node; 20 import de.gulden.util.javasource.jjt.*; 21 import de.gulden.util.xml.XMLToolbox; 22 import javax.xml.parsers.*; 23 import org.w3c.dom.*; 24 import java.io.*; 25 import java.util.*; 26 27 33 public abstract class MemberExecutable extends Member { 34 35 41 public Vector myParameter; 42 43 46 public Vector myException; 47 48 49 55 protected MemberExecutable(Class c) { 56 super(c); 57 myParameter=new Vector(); 58 myException=new Vector(); 59 } 60 61 62 68 public NamedIterator getParameters() { 69 return new NamedIterator(myParameter); 70 } 71 72 75 public NamedIterator getExceptions() { 76 return new NamedIterator(myException); 77 } 78 79 85 public Element buildXML(Document d) { 86 Element e=super.buildXML(d); 87 NamedIterator it=getParameters(); 88 while (it.hasMore()) { 89 Parameter p=(Parameter)it.next(); 90 e.appendChild(p.buildXML(d)); 91 } 92 it=getExceptions(); 93 while (it.hasMore()) { 94 Exception exc=(Exception )it.next(); 95 e.appendChild(exc.buildXML(d)); 96 } 97 if (code!=null) { 98 e.appendChild(code.buildXML(d)); 99 } 100 return e; 101 } 102 103 109 public void initFromXML(Element element) throws IOException { 110 super.initFromXML(element); 112 113 myParameter.removeAllElements(); 115 NodeList nl=XMLToolbox.getChildren(element,"parameter"); 116 for (int i=0;i<nl.getLength();i++) { 117 Parameter pa=new Parameter(this); 118 pa.initFromXML((Element)nl.item(i)); 119 myParameter.addElement(pa); 120 } 121 122 myException.removeAllElements(); 124 nl=XMLToolbox.getChildren(element,"throws"); 125 for (int i=0;i<nl.getLength();i++) { 126 Exception ex=new Exception (this); 127 ex.initFromXML((Element)nl.item(i)); 128 myException.addElement(ex); 129 } 130 131 Element co=XMLToolbox.getChild(element,"code"); 133 if (co!=null) { 134 code=new Code(); 135 code.initFromXML(co); 136 } 137 else { 138 code=null; 139 } 140 } 141 142 145 public String getParameterSignature() { 146 StringBuffer pb=new StringBuffer (); 147 boolean first=true; 148 for (NamedIterator it=getParameters();it.hasMore();) { 149 Parameter p=(Parameter)it.next(); 150 if (!first) { 151 pb.append(","); 152 } 153 else { 154 first=false; 155 } 156 pb.append(p.getType().getFullTypeName()); 157 } 158 return "("+pb.toString()+")"; 159 } 160 161 164 public String getSignature() { 165 return super.getSignature()+getParameterSignature(); 166 } 167 168 173 void initFromAST(Node rootnode) { 174 super.initFromAST(rootnode); 175 176 Node r=rootnode.getChild(JJT_CODE); 177 if (r!=null) { 178 code=new Code(); 179 code.initFromAST(rootnode); } 181 else { 182 code=null; } 184 185 Node[] nodes; 186 187 myParameter.removeAllElements(); 188 nodes=rootnode.getChildren(JJT_PARAMETER); 189 for (int i=0;i<nodes.length;i++) { 190 Parameter c=new Parameter(this); 191 c.initFromAST(nodes[i]); 192 myParameter.addElement(c); 193 } 194 195 myException.removeAllElements(); 196 Node t=rootnode.getChild(JJT_THROWS); 197 if (t!=null) { 198 nodes=t.getChildren(JJT_NAME); 199 for (int i=0;i<nodes.length;i++) { 200 Exception ex=new Exception (this); 201 ex.initFromAST(nodes[i]); 202 myException.addElement(ex); 203 } 204 } 205 } 206 207 } | Popular Tags |