package tutorial.sample30;

import javax.xml.namespace.QName;
import javax.xml.rpc.soap.SOAPFaultException;

import weblogic.webservice.context.WebServiceContext;
import weblogic.webservice.context.WebServiceSession;
import weblogic.webservice.context.ContextNotFoundException;

public class HelloWorldService{

  public int helloStatefulWorld(){

    WebServiceSession session;

    try{
      session = WebServiceContext.currentContext().getSession();
    }catch( ContextNotFoundException e ){

      throw new SOAPFaultException( 
          new QName( "http://tutorial/sample30/fault", "ContextNotFound" ),
          "current context was not found",
          null, null );
    }

    Integer count = (Integer)session.getAttribute( "count" );

    if( count == null ){
      count = new Integer( 0 );
    }

    session.setAttribute( "count", new Integer( count.intValue() + 1 ) );
    return count.intValue();
  }
}

