/*=============================================================================*
* 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.porttype.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.XmlObjectWrapper;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.eventing.ForwardConsumer;
import org.apache.ws.eventing.ForwardEndConsumer;
import org.apache.ws.eventing.Subscription;
import org.apache.ws.eventing.SubscriptionHome;
import org.apache.ws.eventing.porttype.EventSourcePortType;
import org.apache.ws.pubsub.Filter;
import org.apache.ws.pubsub.FilterFactory;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
import org.xmlsoap.schemas.ws.x2004.x08.eventing.SubscribeDocument;
import org.xmlsoap.schemas.ws.x2004.x08.eventing.SubscribeResponseDocument;
import javax.naming.InitialContext;
import java.rmi.RemoteException;
import java.util.Calendar;
/**
* DOCUMENT_ME
*
* @version $Revision: 1.8 $
* @author $author$
*/
public class EventSourcePortTypeImpl /*extends AbstractResourcePropertiesPortType*/
implements EventSourcePortType
{
private static final Log LOG = LogFactory.getLog( EventSourcePortTypeImpl.class.getName( ) );
/* public EventSourcePortTypeImpl( ResourceContext resourceContext )
{
super( resourceContext );
LOG.info("new EventSourcePortTypeImpl");
}
*/
public SubscribeResponseDocument subscribe( SubscribeDocument body )
throws RemoteException
{
LOG.info( "subscribe" );
try
{
//create Subscription
//System.out.println("get RemoteResourceSubscriptionHome " + RemoteSubscriptionHome.HOME_LOCATION);
SubscriptionHome sH = (SubscriptionHome) new InitialContext( ).lookup( SubscriptionHome.HOME_LOCATION );
//create NotifyTO EPR
EndpointReference notifyto = null;
if ( body.getSubscribe( ).getDelivery( ).getNotifyTo( ) != null )
{
notifyto = new XmlBeansEndpointReference( body.getSubscribe( ).getDelivery( ).getNotifyTo( ) );
}
//create EndTO EPR
EndpointReference endto = null;
if ( body.getSubscribe( ).getEndTo( ) != null )
{
endto = new XmlBeansEndpointReference( body.getSubscribe( ).getEndTo( ) );
}
Filter filter = FilterFactory.createFilter( body.getSubscribe( ).getFilter( ) );
Calendar expires = (Calendar) body.getSubscribe( ).getExpires( );
//getDeliveryMode
java.net.URI delivery = null;
if ( body.getSubscribe( ).getDelivery( ).getMode( ) != null )
{
delivery = new java.net.URI( body.getSubscribe( ).getDelivery( ).getMode( ) );
}
Subscription subscription = sH.create( filter, expires, delivery );
subscription.setNotificationConsumer( new ForwardConsumer( notifyto ) );
subscription.setSubscriptionEndConsumer( new ForwardEndConsumer( endto ) );
//check if topic expression
// if(filter instanceof TopicFilter == true){
// Collection collection = evaluateTopicExpression((TopicFilter)filter);
// SimpleSubscriptionTopicListener simpleSubscriptionTopicListener = new SimpleSubscriptionTopicListener(subscription);
//add listeners
// for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
// Topic topic = (Topic) iterator.next();
// topic.addTopicListener(simpleSubscriptionTopicListener);
// }
// }
//build response
SubscribeResponseDocument responseDom =
SubscribeResponseDocument.Factory.newInstance( );
SubscribeResponseDocument.SubscribeResponse response = responseDom.addNewSubscribeResponse( );
response.setSubscriptionManager( (EndpointReferenceType) ( (XmlObjectWrapper) subscription
.getEndpointReference( ) ).getXmlObject( ) );
//TODO why not ExpirationType???
response.setExpires( new org.apache.xmlbeans.XmlCalendar( subscription.getTerminationTime( ).getTime( ) ) );
return responseDom;
}
catch ( Exception e )
{
//TODO error
e.printStackTrace( );
}
//TODO error
return null;
}
/*
private Collection evaluateTopicExpression(TopicExpression topicExpr)
throws SOAPException { /*
NotificationProducerResource resource = (NotificationProducerResource) getResource();
TopicSpaceSet topicSpaceSet = resource.getTopicSpaceSet();
Collection collection = null;
try {
collection = topicSpaceSet.evaluateExpression(topicExpr);
}
catch (TopicExpressionException e) {
throw new JAXRPCException("An exception occurred during subscription. ", e);
}
return collection;
return null;
}
*/
}