package com.yihu.jw.internet.wsapi;

import java.rmi.RemoteException;

public class WsapiProxy implements Wsapi {
  private String _endpoint = null;
  private Wsapi wsapi = null;
  
  public WsapiProxy() {
    _initWsapiProxy();
  }
  
  public WsapiProxy(String endpoint) {
    _endpoint = endpoint;
    _initWsapiProxy();
  }
  
  private void _initWsapiProxy() {
    try {
      wsapi = (new WsapiServiceLocator()).getwsapiPort();
      if (wsapi != null) {
        if (_endpoint != null)
          ((javax.xml.rpc.Stub)wsapi)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
        else
          _endpoint = (String)((javax.xml.rpc.Stub)wsapi)._getProperty("javax.xml.rpc.service.endpoint.address");
      }
      
    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }
  
  public String getEndpoint() {
    return _endpoint;
  }
  
  public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (wsapi != null)
      ((javax.xml.rpc.Stub)wsapi)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    
  }
  
  public Wsapi getWsapi() {
    if (wsapi == null)
      _initWsapiProxy();
    return wsapi;
  }
  
  public String invoke(String arg0, String arg1, String arg2, String arg3, String arg4) throws RemoteException {
    if (wsapi == null)
      _initWsapiProxy();
    return wsapi.invoke(arg0, arg1, arg2, arg3, arg4);
  }

  public boolean vaildTokenPass(String arg0, String arg1) throws RemoteException, ControllerException, NoSuchPaddingException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException{
    if (wsapi == null)
      _initWsapiProxy();
    return wsapi.vaildTokenPass(arg0, arg1);
  }


}