/*=============================================================================*
* 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.notification.base.v2004_06.impl;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.addressing.v2003_03.AddressingConstants;
import org.apache.ws.notification.base.WsnNamespaceVersionHolder;
import org.apache.ws.notification.base.impl.AbstractSubscription;
import org.apache.ws.notification.base.service.subscriptionManager.ProducerReferenceDocument;
import org.apache.ws.notification.base.service.subscriptionManager.SubscriptionManagerRPDocument;
import org.apache.ws.notification.base.v2004_06.callback.ConsumerReferenceResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.callback.PreconditionResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.callback.SelectorResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.callback.SubscriptionPolicyResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.callback.TopicExpressionResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.callback.UseNotifyResourcePropertyCallback;
import org.apache.ws.notification.base.v2004_06.porttype.SubscriptionManagerPortType;
import org.apache.ws.notification.topics.expression.TopicExpression;
import org.apache.ws.pubsub.SubscriptionEndConsumer;
import org.apache.ws.resource.NamespaceVersionHolder;
import org.apache.ws.resource.lifetime.callback.CurrentTimeCallback;
import org.apache.ws.resource.lifetime.v2004_06.porttype.ScheduledResourceTerminationPortType;
import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.ResourcePropertySet;
import org.apache.ws.resource.properties.ResourcePropertySetMetaData;
import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySetMetaData;
import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.CreationTimeDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.CurrentTimeDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.TerminationTimeDocument;
import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
import javax.xml.namespace.QName;
/**
* The subscription resource that is exposed via the builtin 2004/06
* SubscriptionManager service.
*
* @author Ian Springer
*/
public class SubscriptionResource
extends AbstractSubscription
{
private static final WsnNamespaceVersionHolder WSN_2004_06_NAMESPACE_SET =
new org.apache.ws.notification.base.v2004_06.impl.WsnNamespaceVersionHolderImpl( );
private static final QName[] READ_ONLY_PROP_NAMES =
{
ScheduledResourceTerminationPortType.PROP_QNAME_CURRENT_TIME,
ScheduledResourceTerminationPortType.PROP_QNAME_TERMINATION_TIME,
SubscriptionManagerPortType.PROP_QNAME_CREATION_TIME,
SubscriptionManagerPortType.PROP_QNAME_PRODUCER_REFERENCE
};
/**
* Creates a new {@link SubscriptionResource} object.
*
* @param producerRef DOCUMENT_ME
* @param consumerRef DOCUMENT_ME
* @param topicExpr DOCUMENT_ME
*/
public SubscriptionResource( EndpointReference producerRef,
EndpointReference consumerRef,
TopicExpression topicExpr )
{
super( producerRef, consumerRef, topicExpr );
}
/**
* @see org.apache.ws.resource.Resource#getNamespaceSet()
*/
public NamespaceVersionHolder getNamespaceSet( )
{
return WSN_2004_06_NAMESPACE_SET;
}
/**
* Get the subscriptionEnd consumer associated with this subscription.
*
* @return the subscriptionEnd consumer
*/
public SubscriptionEndConsumer getSubscriptionEndConsumer( )
{
return null; // there's no such thing as a subscription end consumer in WSN, so just return null
}
/**
* @see org.apache.ws.resource.Resource#init()
*/
public void init( )
{
SubscriptionManagerRPDocument propsDoc = SubscriptionManagerRPDocument.Factory.newInstance( );
ResourcePropertySetMetaData propSetMetaData =
new XmlBeansResourcePropertySetMetaData( propsDoc.schemaType( ), READ_ONLY_PROP_NAMES );
ResourcePropertySet propSet = new XmlBeansResourcePropertySet( propsDoc, propSetMetaData );
setResourcePropertySet( propSet );
// wsrlw:ScheduledResourceTermination props
ResourceProperty prop =
propSet.get( ScheduledResourceTerminationPortType.PROP_QNAME_CURRENT_TIME );
CurrentTimeDocument currTimeDoc = CurrentTimeDocument.Factory.newInstance( );
currTimeDoc.setCurrentTime( getCurrentTime( ) );
prop.setCallback( new CurrentTimeCallback( ) );
prop.add( currTimeDoc );
prop = propSet.get( ScheduledResourceTerminationPortType.PROP_QNAME_TERMINATION_TIME );
TerminationTimeDocument termTimeDoc = TerminationTimeDocument.Factory.newInstance( );
termTimeDoc.setTerminationTime( getTerminationTime( ) );
prop.add( termTimeDoc );
// wsntw:SubscriptionManager props
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_CONSUMER_REFERENCE );
prop.setCallback( new ConsumerReferenceResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_TOPIC_EXPRESSION );
prop.setCallback( new TopicExpressionResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_USE_NOTIFY );
prop.setCallback( new UseNotifyResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_PRECONDITION );
prop.setCallback( new PreconditionResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_SELECTOR );
prop.setCallback( new SelectorResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_SUBSCRIPTION_POLICY );
prop.setCallback( new SubscriptionPolicyResourcePropertyCallback( this ) );
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_CREATION_TIME );
CreationTimeDocument creationTimeDoc = CreationTimeDocument.Factory.newInstance( );
creationTimeDoc.setCreationTime( getCreationTime( ) );
prop.add( creationTimeDoc );
// custom prop 'ProducerReference'
prop = propSet.get( SubscriptionManagerPortType.PROP_QNAME_PRODUCER_REFERENCE );
ProducerReferenceDocument producerRefDoc = ProducerReferenceDocument.Factory.newInstance( );
producerRefDoc.setProducerReference( (EndpointReferenceType) ( (XmlBeansEndpointReference) getProducerReference( ) )
.getXmlObject( AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
prop.add( producerRefDoc );
}
}