Chinaunix首页 | 论坛 | 博客
  • 博客访问: 500297
  • 博文数量: 1496
  • 博客积分: 79800
  • 博客等级: 大将
  • 技术积分: 9940
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 13:22
文章分类

全部博文(1496)

文章存档

2011年(1)

2008年(1495)

我的朋友

分类:

2008-09-09 13:30:24


  1 建立Eclipse插件
  
  File->New->Project->Plug-in development的Plug-in project->Next,填写Project名,Next, 填写内容,Next,选择Create plug-in using one of the templates,选择Hello,World,Finish。
  
  在视图可看到plugin.xml,在里加上运行调用Web Service所需jar包。内容如下:
  
  
  
  
  
    
  id="colimas_plugin"
  
  name="Colimas_plugin Plug-in"
  
  version="1.0.0"
  
  provider-name="nova"
  
  class="colimas_plugin.Colimas_pluginPlugin">
  
  
  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  

  
  
  
  
  
  
  
  

  
    
  point="org.eclipse.ui.actionSets">
  
   - Code Style - Code Templates
  
  */package com.nova.colimas.plugin.eclipse;
  
  import org.apache.axis.client.Call;
  
  import org.apache.axis.client.Service;
  
  import javax.xml.namespace.QName;import java.io.*;
  
  /**
  
  *@author tyrone
  
  *
  
  * TODO To change the template for this generated type comment go to
  
  * Window - Preferences - - Code Style - Code Templates
  
  */
  
  public class SendFileClient { private Call call;
  
  /**
  
  * The constructor.
  
  */
  
  public SendFileClient() {
  
  try{
  
  Service service=
  
  new Service();
  
  call  = (Call) service.createCall();
  
  }catch(Exception ex){  System.out.println(ex.getMessage());
  
  } } public void saveFile(){ try {  String endpoint =  "http://localhost:8080/axis/services/DocumentFileManagement";
  
  System.out.println("start web service");
  
  call.setTargetEndpointAddress( new java.net.URL(endpoint) );
  
  call.setOperationName(new QName("", "saveFile"));
  
  File fp=new File("D:\\MyProject\\colimas\\colimas_plugin\\lib\\mail.jar");
  
  BufferedInputStream in=new BufferedInputStream(new FileInputStream(fp));
  
  int len=in.available();
  
  byte[] contents=new byte[len];
  
  in.read(contents,0,len);
  
  System.out.println("begin run");
  
  //开始调用Web Service:DocumentFileManagement的saveFile方法
  
  String ret = (String) call.invoke( new Object[] {fp.getName(),contents} );
  
  in.close();
  
  } catch (Exception e) {  System.err.println("error"+e.toString());
  
  }
  
  }
  
  }
  
  3 修改Action类的run方法
  
  Action类的run方法里的内容是Eclipse插件真正要做到事
  
  package colimas_plugin.actions;import org.eclipse.jface.action.IAction;
  
  import org.eclipse.jface.viewers.ISelection;
  
  import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.IWorkbenchWindowActionDelegate;
  
  import org.eclipse.jface.dialogs.MessageDialog;
  
  import com.nova.colimas.plugin.eclipse.*;
  
  /**
  
  * Our sample action implements workbench action delegate.
  
  * The action proxy will be created by the workbench and
  
  * shown in the UI. When the user tries to use the action,
  
  * this delegate will be created and execution will be
  
  * delegated to it. * @see IWorkbenchWindowActionDelegate
  
  */public class SampleAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window;
  
  /**
  
  * The constructor.
  
  */ public SampleAction() { }
  
  /**
  
  * The action has been activated. The argument of the
  
  * method represents the 'real' action sitting
  
  * in the workbench UI.
  
  * @see IWorkbenchWindowActionDelegate#run
  
  */ public void run(IAction action) { SendFileClient client=new SendFileClient();
  
  client.saveFile();
  
  MessageDialog.openInformation(  window.getShell(),
  
  "Colimas_plugin Plug-in",  "Colimas Connected");
  
  } /** * Selection in the workbench has been changed. We
  
  * can change the state of the 'real' action here
  
  * if we want, but this can only happen after
  
  * the delegate has been created.
  
  * @see IWorkbenchWindowActionDelegate#selectionChanged
  
  */ public void selectionChanged(IAction action, ISelection selection) { }
  
  /**
  
  * We can use this method to dispose of any system
  
  * resources we previously allocated.
  
  * @see IWorkbenchWindowActionDelegate#dispose
  
  */ public void dispose() { }
  
  /**
  
  * We will cache window object in order to
  
  * be able to provide parent shell for the message dialog.
  
  * @see IWorkbenchWindowActionDelegate#init
  
  */ public void init(IWorkbenchWindow window) { this.window = window;
  
  }
  
  4 调试
  
  首先启动Axis,然后选择Eclipse的Run菜单的Run As -〉Run time workbench。
  
  这样会启动另一个Eclipse workbench,在这个workbench里你会看到toolbar里新增了一个按钮,
  
  点击按钮就会调用Webservice并返回控制台结果。
【责编:admin】

--------------------next---------------------

阅读(136) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~