001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.attributes;
021:
022: import java.util.*; //import javax.xml.parsers.*;
023:
024: import org.w3c.dom.*;
025:
026: public class AttributeDomProcessor {
027:
028: Document domDoc;
029: ArrayList attributes;
030: private ArrayList keys;
031: private SootAttribute current;
032:
033: /**
034: * Method AttributeDomProcessor.
035: * @param domDoc
036: */
037: public AttributeDomProcessor(Document domDoc) {
038: setDomDoc(domDoc);
039: }
040:
041: /**
042: * Method processAttributesDom.
043: */
044: public void processAttributesDom() {
045: processNode(getDomDoc());
046:
047: }
048:
049: private void processNode(Node node) {
050:
051: if (node.getNodeType() == Node.DOCUMENT_NODE) {
052: NodeList children = node.getChildNodes();
053: if (children != null) {
054: setAttributes(new ArrayList());
055: for (int i = 0; i < children.getLength(); i++) {
056: processNode(children.item(i));
057: }
058: }
059:
060: } else if (node.getNodeType() == Node.ELEMENT_NODE) {
061: if (node.getNodeName().equals("attribute")) {
062:
063: current = new SootAttribute();
064: NodeList children = node.getChildNodes();
065: for (int i = 0; i < children.getLength(); i++) {
066: processAttributeNode(current, children.item(i));
067: }
068: getAttributes().add(current);
069: } else if (node.getNodeName().equals("key")) {
070: if (keys == null) {
071: keys = new ArrayList();
072: }
073: NamedNodeMap map = node.getAttributes();
074: AnalysisKey key = new AnalysisKey();
075: key.setRed((new Integer(map.getNamedItem("red")
076: .getNodeValue())).intValue());
077: key.setGreen((new Integer(map.getNamedItem("green")
078: .getNodeValue())).intValue());
079: key.setBlue((new Integer(map.getNamedItem("blue")
080: .getNodeValue())).intValue());
081: key.setKey(map.getNamedItem("key").getNodeValue());
082: key.setType(map.getNamedItem("aType").getNodeValue());
083: keys.add(key);
084: } else {
085: NodeList children = node.getChildNodes();
086: for (int i = 0; i < children.getLength(); i++) {
087: processNode(children.item(i));
088: }
089: }
090:
091: }
092:
093: }
094:
095: private void processAttributeNode(SootAttribute current, Node node) {
096:
097: if (node.getNodeType() == Node.ELEMENT_NODE) {
098: if (node.getNodeName().equals("link")) {
099: NamedNodeMap map = node.getAttributes();
100: LinkAttribute la = new LinkAttribute();
101:
102: la.setLabel(map.getNamedItem("label").getNodeValue());
103: la.setJavaLink((new Integer(map.getNamedItem("srcLink")
104: .getNodeValue()).intValue()));
105: la.setJimpleLink((new Integer(map.getNamedItem(
106: "jmpLink").getNodeValue()).intValue()));
107: la.setClassName(map.getNamedItem("clssNm")
108: .getNodeValue());
109: la.setType(map.getNamedItem("aType").getNodeValue());
110: current.addLinkAttr(la);
111: } else if (node.getNodeName().equals("color")) {
112: NamedNodeMap map = node.getAttributes();
113: int r = (new Integer(map.getNamedItem("r")
114: .getNodeValue())).intValue();
115: int g = (new Integer(map.getNamedItem("g")
116: .getNodeValue())).intValue();
117: int b = (new Integer(map.getNamedItem("b")
118: .getNodeValue())).intValue();
119: int fgInt = (new Integer(map.getNamedItem("fg")
120: .getNodeValue())).intValue();
121: boolean fg = false;
122: if (fgInt == 1) {
123: fg = true;
124: }
125: ColorAttribute ca = new ColorAttribute(r, g, b, fg);
126: ca.type(map.getNamedItem("aType").getNodeValue());
127: current.addColorAttr(ca);//.setColor(ca);
128: } else if (node.getNodeName().equals("srcPos")) {
129: NamedNodeMap map = node.getAttributes();
130: int sline = (new Integer(map.getNamedItem("sline")
131: .getNodeValue())).intValue();
132: int eline = (new Integer(map.getNamedItem("eline")
133: .getNodeValue())).intValue();
134: int spos = (new Integer(map.getNamedItem("spos")
135: .getNodeValue())).intValue();
136: int epos = (new Integer(map.getNamedItem("epos")
137: .getNodeValue())).intValue();
138:
139: current.setJavaStartLn(sline);
140: current.setJavaEndLn(eline);
141: current.setJavaStartPos(spos);
142: current.setJavaEndPos(epos);
143: } else if (node.getNodeName().equals("jmpPos")) {
144: NamedNodeMap map = node.getAttributes();
145: int sline = (new Integer(map.getNamedItem("sline")
146: .getNodeValue())).intValue();
147: int eline = (new Integer(map.getNamedItem("eline")
148: .getNodeValue())).intValue();
149: int spos = (new Integer(map.getNamedItem("spos")
150: .getNodeValue())).intValue();
151: int epos = (new Integer(map.getNamedItem("epos")
152: .getNodeValue())).intValue();
153:
154: current.setJimpleStartLn(sline);
155: current.setJimpleEndLn(eline);
156: current.setJimpleStartPos(spos);
157: current.setJimpleEndPos(epos);
158: } else if (node.getNodeName().equals("text")) {
159: NamedNodeMap map = node.getAttributes();
160: TextAttribute ta = new TextAttribute();
161: ta.setInfo(map.getNamedItem("info").getNodeValue());
162: ta.setType(map.getNamedItem("aType").getNodeValue());
163: current.addTextAttr(ta);
164: } else {
165: NodeList children = node.getChildNodes();
166: for (int i = 0; i < children.getLength(); i++) {
167: processAttributeNode(current, children.item(i));
168: }
169: }
170: } else if (node.getNodeType() == Node.TEXT_NODE) {
171: String type = node.getParentNode().getNodeName();
172: }
173: }
174:
175: /**
176: * Returns the domDoc.
177: * @return Document
178: */
179: public Document getDomDoc() {
180: return domDoc;
181: }
182:
183: /**
184: * Sets the domDoc.
185: * @param domDoc The domDoc to set
186: */
187: public void setDomDoc(Document domDoc) {
188: this .domDoc = domDoc;
189: }
190:
191: /**
192: * Returns the attributes.
193: * @return Vector
194: */
195: public ArrayList getAttributes() {
196: return attributes;
197: }
198:
199: /**
200: * Returns the current.
201: * @return SootAttribute
202: */
203: public SootAttribute getCurrent() {
204: return current;
205: }
206:
207: /**
208: * Sets the attributes.
209: * @param attributes The attributes to set
210: */
211: public void setAttributes(ArrayList attributes) {
212: this .attributes = attributes;
213: }
214:
215: /**
216: * Sets the current.
217: * @param current The current to set
218: */
219: public void setCurrent(SootAttribute current) {
220: this .current = current;
221: }
222:
223: /**
224: * @return
225: */
226: public ArrayList getKeys() {
227: return keys;
228: }
229:
230: /**
231: * @param list
232: */
233: public void setKeys(ArrayList list) {
234: keys = list;
235: }
236:
237: }
|