/*=============================================================================*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*=============================================================================*/
package org.apache.ws.eventing.pubsub;
import org.apache.commons.id.IdentifierUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.eventing.AbstractSubscription;
import org.apache.ws.pubsub.wsaSOAPConnection;
import org.apache.ws.resource.NamespaceVersionHolder;
import org.xmlsoap.schemas.ws.x2004.x08.eventing.RenewDocument;
import org.xmlsoap.schemas.ws.x2004.x08.eventing.UnsubscribeDocument;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import java.util.Calendar;
/**
*
* @author Stefan Lischke
*/
public class Subscription
extends AbstractSubscription
{
private static final Log LOG = LogFactory.getLog( Subscriber.class.getName( ) );
/**
* Creates a new {@link Subscription} object.
*/
public Subscription( )
{
setID( IdentifierUtils.UUID_VERSION_FOUR_GENERATOR.nextIdentifier( ).toString( ) );
this.m_creationTime = Calendar.getInstance( );
LOG.info( "new local Subscription : " + getID( ) );
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public NamespaceVersionHolder getNamespaceSet( )
{
return null; // TODO
}
/**
* DOCUMENT_ME
*
* @param epr DOCUMENT_ME
*/
public void setSubscriptionManager( EndpointReference epr )
{
super.setEpr( epr );
}
/**
* DOCUMENT_ME
*
* @param terminationTime DOCUMENT_ME
*/
public void setTerminationTime( java.util.Calendar terminationTime )
{
//TODO call SubscriptionManager
RenewDocument rdom = RenewDocument.Factory.newInstance( );
RenewDocument.Renew r = rdom.addNewRenew( );
r.setExpires( terminationTime );
try
{
//now call
wsaSOAPConnection sconn = wsaSOAPConnection.newInstance( );
MessageFactory mf = MessageFactory.newInstance( );
SOAPMessage soapm = mf.createMessage( );
//put XMLbean into SOAPBody
soapm.getSOAPBody( ).addDocument( (org.w3c.dom.Document) rdom.newDomNode( ) );
sconn.call( soapm,
getEndpointReference( ) );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public java.util.Calendar getTerminationTime( )
{
//TODO maybe call GetStatus to get Termination time
return m_terminationTime;
}
/**
* DOCUMENT_ME
*/
public void destroy( )
{
try
{
this.rH.remove( getID( ) );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
/**
* DOCUMENT_ME
*/
public void init( )
{
System.out.println( "local init" );
}
/**
* DOCUMENT_ME
*
* @param xml DOCUMENT_ME
*/
public void notify( String xml )
{
getNotificationConsumer( ).notify( this, xml );
}
/**
* DOCUMENT_ME
*/
public void unsubscribe( )
{
UnsubscribeDocument usdom = UnsubscribeDocument.Factory.newInstance( );
usdom.addNewUnsubscribe( );
try
{
//now call
wsaSOAPConnection sconn = wsaSOAPConnection.newInstance( );
MessageFactory mf = MessageFactory.newInstance( );
SOAPMessage soapm = mf.createMessage( );
//put XMLbean into SOAPBody
soapm.getSOAPBody( ).addDocument( (org.w3c.dom.Document) usdom.newDomNode( ) );
sconn.call( soapm,
getEndpointReference( ) );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
}