Package org.apache.interop.wcdisplay

Source Code of org.apache.interop.wcdisplay.DisplayAppConnection

/*
* Created on Jun 7, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.apache.interop.wcdisplay;

import java.util.Observer;

import javax.xml.namespace.QName;

import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.addressing.v2004_08_10.AddressingConstants;
import org.apache.ws.muws.interop.client.FaultException;
import org.apache.ws.muws.interop.client.ResourceStub;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.impl.values.XmlIntImpl;
import org.wsdmdemo.service.weatherStation.impl.TemperatureMetricTypeImpl;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.impl.EndpointReferenceTypeImpl;

/**
* @author wire
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DisplayAppConnection {
  private static final QName weatherStationReferenceQname= new QName("http://wsdmdemo.org/service/weather-client-config","WeatherStationReference");
  private static final QName weatherStationRefreshIntervalQname= new QName("http://wsdmdemo.org/service/weather-client-config","WeatherDataRefreshInterval");
  private static final QName weatherStationNameQname= new QName("http://wsdmdemo.org/service/weather-station", "Name", "tns");
  private static final QName weatherStationTempQname= new QName("http://wsdmdemo.org/service/weather-station","Temperature");
  private static final QName weatherStationPricepQname= new QName("http://wsdmdemo.org/service/weather-station","Price");
  private static final QName weatherStationStatusQname= new QName("http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd", "OperationalStatus", "muws-p2-xs");

  private EndpointReference m_eprConfig;
  private ResourceStub m_ResourceConfig;
  private ResourceStub m_ws;
  private Observer m_messageObserver;
 
  private String status;
  private int temperature;
  private String stationName;

  /**
   * @throws XmlException
   *
   */
  public DisplayAppConnection(Observer obs,EndpointReference epr) throws XmlException {
    super();
   
    m_eprConfig = epr;
    m_ResourceConfig = new ResourceStub(m_eprConfig);
    m_ResourceConfig.addObserver(obs);
    m_messageObserver=obs;
  }
 
  int getDelay() throws XmlException, FaultException {
    XmlObject[] refreshDocArry = m_ResourceConfig.getResourceProperty(weatherStationRefreshIntervalQname);
    XmlIntImpl refreshDoc = (XmlIntImpl)refreshDocArry[0];
    return refreshDoc.getIntValue()*1000;
  }

 
  private EndpointReference getEpr(String URL, String Rid) throws XmlException{
    XmlBeansEndpointReference x=new XmlBeansEndpointReference(URL,AddressingConstants.NSURI_ADDRESSING_SCHEMA);
    x.setReferenceProperties(new XmlObject[]{(XmlObject)XmlObject.Factory.parse("<svr:ResourceIdentifier xmlns:svr=\"http://wsdmdemo.org/service/weather-client-config\">"+Rid+"</svr:ResourceIdentifier>")});   
    return x;   

  }

  /**
   *
   */
  public void deleteObservers() {
    m_ResourceConfig.deleteObservers();
    m_ws.deleteObservers();
  }

  /**
   * Updates the Ws Epr by consulting with the WcConfig Resource.
   * @throws FaultException
   *
   */
  public void updateWsEpr() throws FaultException {
    XmlObject[] refreshDocArry = m_ResourceConfig.getResourceProperty(weatherStationReferenceQname);
    EndpointReferenceTypeImpl refreshDoc = (EndpointReferenceTypeImpl)refreshDocArry[0];
   
    if(m_ws!=null){
      m_ws.deleteObserver(m_messageObserver);     
    }
    m_ws = new ResourceStub(new XmlBeansEndpointReference(refreshDoc));
    m_ws.addObserver(m_messageObserver);
   
  }

  public String getStationName() throws FaultException {
    XmlObject[] nameArry=m_ws.getResourceProperty(weatherStationNameQname);

    if(nameArry.length>0){
      XmlObject x=nameArry[0];
      String value=x.newCursor().getTextValue();
      return value;
    }

    return null;
  }
  public String getStatus() throws FaultException {
    XmlObject[] statArry=m_ws.getResourceProperty(weatherStationStatusQname);
    if(statArry.length>0){
      XmlObject x=statArry[0];
      String value=x.newCursor().getTextValue();
      return value;
    }
    return null;
  }
  public int getTemperature() throws FaultException {
    XmlObject[] tempArry=m_ws.getResourceProperty(weatherStationTempQname);
    if(tempArry.length>0){
      TemperatureMetricTypeImpl x=(TemperatureMetricTypeImpl)tempArry[0];
     
      String value=x.newCursor().getTextValue();
      return new Long(Math.round(x.doubleValue())).intValue();
    }
    return -1;
  }

  public String getPrice() throws FaultException{
    XmlObject[] priceArry=m_ws.getResourceProperty(weatherStationPricepQname);
    if(priceArry.length>0){
      XmlObject x=priceArry[0];
      String value=x.newCursor().getTextValue();
      return value;
    }
    return null;
  }
}
TOP

Related Classes of org.apache.interop.wcdisplay.DisplayAppConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.