1 2 3 package net.firstpartners.nounit.snippet; 4 5 28 29 import java.util.HashMap ; 30 31 import net.firstpartners.nounit.snippet.xml.IXmlConstants; 32 import net.firstpartners.nounit.snippet.xml.IXmlJdomSource; 33 import net.firstpartners.nounit.snippet.xml.IXmlSource; 34 35 import org.jdom.Element; 36 37 40 public class SnippetCalls extends AbstractSnippet implements IXmlSource, IXmlJdomSource, IXmlConstants { 41 42 43 46 private HashMap innerParams; 47 48 51 private String innerClassCalled; 52 53 56 private String innerMethodCalled; 57 58 59 66 public SnippetCalls(String classCalled, String methodCalled, HashMap parameters) { 67 68 this.innerClassCalled=classCalled; 69 this.innerMethodCalled=methodCalled; 70 71 if (parameters==null) { 73 this.innerParams = new HashMap (); 74 } else { 75 this.innerParams = parameters; 76 } 77 } 78 79 80 84 public String toString(){ 85 86 StringBuffer stringDescription = new StringBuffer (); 88 89 stringDescription.append("Calls:\n"); 90 stringDescription.append(this.innerClassCalled); 91 stringDescription.append("\n"); 92 stringDescription.append(this.innerMethodCalled); 93 stringDescription.append("\n"); 94 95 stringDescription.append("("); 96 97 int counter=0; 99 Object tmpObject; 100 101 while (counter>-1){ 102 tmpObject=innerParams.get(String.valueOf(counter)); 103 if (tmpObject==null) { 104 counter=-1; 105 } else { 106 counter++; 107 stringDescription.append(tmpObject); 108 stringDescription.append(":"); 109 } 110 111 } 112 113 114 stringDescription.append(")"); 115 116 117 119 return stringDescription.toString(); 120 } 121 122 123 127 public String toXml() { 128 129 return super.toXml(getNodes()); 130 131 } 132 133 134 138 public Element getNodes(){ 139 140 int counter=0; 142 Object tmpObject; 143 String tmpString; 144 Element calledRoot = new Element(ELEMENT_CALLS); 145 Element paramTag; 146 147 calledRoot.setAttribute(ATTRIBUTE_CLASS,this.innerClassCalled); 149 150 calledRoot.setAttribute(ATTRIBUTE_METHOD,this.innerMethodCalled); 152 153 155 while (counter>-1){ 156 tmpObject=innerParams.get(String.valueOf(counter)); 157 if (tmpObject==null) { 158 counter=-1; 159 } else { 160 counter++; 161 162 tmpString=(String )tmpObject; 164 paramTag = new Element(ELEMENT_PARAM); 165 paramTag.setAttribute(ATTRIBUTE_NAME,tmpString); 166 167 calledRoot.addContent(paramTag); 169 170 } 171 172 } 173 174 175 return calledRoot; 176 } 177 178 179 180 } 181 | Popular Tags |