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 SnippetMethod 41 extends AbstractSnippet 42 implements IXmlSource , IXmlJdomSource , IXmlConstants { 43 44 45 48 private HashMap innerParams; 49 50 53 private Snippets innerMethodsCalled; 54 55 63 public SnippetMethod(String name, 64 String accessModifier, 65 HashMap parameters, 66 Snippets methodsCalled) { 67 68 super.innerName=name; 69 super.innerAccess=accessModifier; 70 71 if (parameters==null) { 73 this.innerParams = new HashMap (); 74 } else { 75 this.innerParams = parameters; 76 } 77 78 if (parameters==null) { 80 this.innerMethodsCalled = new Snippets(); 81 } else { 82 this.innerMethodsCalled = methodsCalled; 83 } 84 } 85 86 87 91 public String toString(){ 92 93 StringBuffer stringDescription = new StringBuffer (); 95 96 stringDescription.append(super.toString()); 98 99 stringDescription.append("("); 100 101 int counter=0; 103 Object tmpObject; 104 105 while (counter>-1){ 106 tmpObject=innerParams.get(String.valueOf(counter)); 107 if (tmpObject==null) { 108 counter=-1; 109 } else { 110 counter++; 111 stringDescription.append(tmpObject); 112 stringDescription.append(":"); 113 } 114 115 } 116 117 118 stringDescription.append(")"); 119 120 121 123 return stringDescription.toString(); 124 } 125 126 127 131 public String toXml() { 132 133 return super.toXml(getNodes()); 134 135 } 136 137 138 142 public Element getNodes(){ 143 144 int counter=0; 146 Object tmpObject; 147 String tmpString; 148 Element paramTag = new Element(ELEMENT_PARAM); 149 Element methodRoot = new Element(ELEMENT_METHOD); 150 151 methodRoot.setAttribute(ATTRIBUTE_NAME,super.innerName); 153 methodRoot.setAttribute(ATTRIBUTE_ACCESS,super.innerAccess); 154 155 while (counter>-1){ 157 tmpObject=innerParams.get(String.valueOf(counter)); 158 if (tmpObject==null) { 159 counter=-1; 160 } else { 161 counter++; 162 163 tmpString=(String )tmpObject; 165 paramTag = new Element(ELEMENT_PARAM); 166 paramTag.setAttribute(ATTRIBUTE_NAME,tmpString); 167 168 methodRoot.addContent(paramTag); 170 171 } 172 173 } 174 175 methodRoot = innerMethodsCalled.addNodesTo(methodRoot); 177 178 return methodRoot; 179 } 180 181 182 183 } 184 | Popular Tags |