1 19 20 package org.netbeans.modules.websvc.registry.nodes; 21 22 import org.netbeans.modules.websvc.api.registry.WebServiceMethod; 23 import org.openide.nodes.PropertySupport.ReadOnly; 24 import org.openide.nodes.Sheet; 25 import org.openide.nodes.*; 26 import org.openide.nodes.Node.Cookie; 27 import org.openide.nodes.PropertySupport.Reflection; 28 import org.openide.nodes.Sheet.Set; 29 import org.openide.util.HelpCtx; 30 import org.openide.util.NbBundle; 31 import org.openide.util.actions.SystemAction; 32 import org.openide.util.Utilities; 33 34 import org.netbeans.modules.websvc.registry.actions.TestWebServiceMethodAction; 35 import org.netbeans.modules.websvc.registry.util.Util; 36 37 import com.sun.xml.rpc.processor.model.Operation; 38 import com.sun.xml.rpc.processor.model.Port; 39 import com.sun.xml.rpc.processor.model.java.JavaMethod; 40 import com.sun.xml.rpc.processor.model.java.JavaType; 41 import com.sun.xml.rpc.processor.model.java.JavaParameter; 42 43 import java.awt.Image ; 44 import java.util.Iterator ; 45 import javax.swing.Action ; 46 47 55 public class WebServiceMethodNode extends AbstractNode implements WebServiceMethod { 56 57 private JavaMethod javaMethod; 58 private Port port; 59 60 public WebServiceMethodNode() { 61 this(null,null); 62 } 63 64 public Object getJavaMethod() { 65 return javaMethod; 66 } 67 public WebServiceMethodNode(Port inPort, Operation inOperation) { 69 super(Children.LEAF); 70 72 77 78 port = inPort; 79 if(null == inOperation) { 80 return; 81 } 82 javaMethod = inOperation.getJavaMethod(); 83 setName(javaMethod.getName()); 84 setIconBaseWithExtension("org/netbeans/modules/websvc/registry/resources/methodicon.png"); 85 86 89 String signature = javaMethod.getReturnType().getFormalName() + " " + javaMethod.getName() + "("; 90 Iterator parameterIterator = javaMethod.getParameters(); 91 JavaParameter currentParam = null; 92 while(parameterIterator.hasNext()) { 93 currentParam = (JavaParameter)parameterIterator.next(); 94 String parameterType = Util.getParameterType(inPort, currentParam); 95 signature += parameterType + " " + currentParam.getName(); 96 if(parameterIterator.hasNext()) { 97 signature += ", "; 98 } 99 } 100 signature += ")"; 101 102 setShortDescription(signature); 103 112 118 getCookieSet().add(this); 119 } 120 121 128 public Action[] getActions(boolean context) { 129 return new SystemAction[] { 130 SystemAction.get(TestWebServiceMethodAction.class) 131 }; 132 } 133 134 public Action getPreferredAction() { 135 return SystemAction.get(TestWebServiceMethodAction.class); 136 } 137 138 public HelpCtx getHelpCtx() { 139 return HelpCtx.DEFAULT_HELP; 140 } 143 144 152 153 157 protected Sheet createSheet() { 158 Sheet sheet = super.createSheet(); 159 Set ss = sheet.get("data"); 161 if (ss == null) { 162 ss = new Set(); 163 ss.setName("data"); ss.setDisplayName(NbBundle.getMessage(WebServiceMethodNode.class, "METHOD_INFO")); 165 ss.setShortDescription(NbBundle.getMessage(WebServiceMethodNode.class, "METHOD_INFO")); 166 sheet.put(ss); 167 } 168 169 try { 170 Reflection p; 171 172 p = new Reflection(javaMethod, String .class, "getName", null); p.setName("name"); p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_NAME")); 175 p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_NAME")); 176 ss.put(p); 177 String signature = javaMethod.getReturnType().getRealName() + " " + 178 javaMethod.getName() + "("; 179 180 Iterator tempIterator = javaMethod.getParameters(); 181 JavaParameter currentparam = null; 182 while(tempIterator.hasNext()) { 183 currentparam = (JavaParameter)tempIterator.next(); 184 signature += currentparam.getType().getRealName() + " " + currentparam.getName(); 185 if(tempIterator.hasNext()) { 186 signature += ", "; 187 } 188 } 189 190 signature += ")"; 191 192 Iterator excpIterator = javaMethod.getExceptions(); 193 if(excpIterator.hasNext()) { 194 signature += " throws"; 195 while(excpIterator.hasNext()) { 196 String currentExcp = (String )excpIterator.next(); 197 signature += " " + currentExcp; 198 if(excpIterator.hasNext()) { 199 signature += ","; 200 } 201 } 202 203 204 } 205 206 p = new Reflection(signature, String .class, "toString", null); p.setName("signature"); p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_SIGNATURE")); 209 p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_SIGNATURE")); 210 ss.put(p); 211 212 p = new Reflection(javaMethod.getReturnType(), String .class, "getRealName", null); p.setName("returntype"); p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_RETURNTYPE")); 215 p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_RETURNTYPE")); 216 ss.put(p); 217 218 Set paramSet = sheet.get("parameters"); if (paramSet == null) { 220 paramSet = new Sheet.Set(); 221 paramSet.setName("parameters"); paramSet.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMDIVIDER")); paramSet.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMDIVIDER")); sheet.put(paramSet); 225 } 226 Iterator paramIterator = javaMethod.getParameters(); 227 if(paramIterator.hasNext()) { 228 p = new Reflection(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMTYPE"), 229 String .class, 230 "toString", 231 null); p.setName("paramdivider2"); p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMNAME")); 234 p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMNAME") + 235 "-" + NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMTYPE")); 236 paramSet.put(p); 237 238 239 JavaParameter currentParameter = null; 240 for(int ii=0;paramIterator.hasNext();ii++) { 241 currentParameter = (JavaParameter)paramIterator.next(); 242 if(currentParameter.getType().isHolder()) { 243 p = new Reflection(Util.getParameterType(port,currentParameter), String .class, "toString", null); } else { 245 p = new Reflection(currentParameter.getType(), String .class, "getRealName", null); } 247 p.setName("paramname" + ii); p.setDisplayName(currentParameter.getName()); 249 p.setShortDescription(currentParameter.getName() + "-" + 250 currentParameter.getType().getRealName()); 251 paramSet.put(p); 252 } 253 } 254 Set exceptionSet = sheet.get("exceptions"); if (exceptionSet == null) { 256 exceptionSet = new Sheet.Set(); 257 exceptionSet.setName("exceptions"); exceptionSet.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_EXCEPTIONDIVIDER")); exceptionSet.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_EXCEPTIONDIVIDER")); sheet.put(exceptionSet); 261 } 262 263 Iterator exceptionIterator = javaMethod.getExceptions(); 264 String currentException = null; 265 for(int ii=0;exceptionIterator.hasNext();ii++) { 266 currentException = (String )exceptionIterator.next(); 267 p = new Reflection(currentException, String .class, "toString", null); p.setName("exception" + ii); p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMTYPE")); 270 p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "METHOD_PARAMTYPE")); 271 exceptionSet.put(p); 272 } 273 } catch (NoSuchMethodException nsme) { 274 nsme.printStackTrace(); 275 } 276 277 return sheet; 278 } 279 280 302 303 319 320 356 357 367 368 } 369 | Popular Tags |