/*=============================================================================*
* 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.callback;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.addressing.v2003_03.AddressingConstants;
import org.apache.ws.notification.base.Subscription;
import org.apache.ws.notification.base.v2004_06.porttype.SubscriptionManagerPortType;
import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.SetResourcePropertyCallback;
import org.apache.ws.resource.properties.impl.CallbackFailedException;
import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.ConsumerReferenceDocument;
import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
import javax.xml.namespace.QName;
/**
* A callback for the ConsumerReference resource property from the WS-BaseNotification
* SubscriptionManager portType.
*
* @author Ian Springer
*/
public class ConsumerReferenceResourcePropertyCallback
implements SetResourcePropertyCallback
{
private Subscription m_subscription;
/**
* Creates a new {@link ConsumerReferenceResourcePropertyCallback} object.
*
* @param subscription DOCUMENT_ME
*/
public ConsumerReferenceResourcePropertyCallback( Subscription subscription )
{
m_subscription = subscription;
}
/**
* DOCUMENT_ME
*
* @param propQName DOCUMENT_ME
*
* @throws CallbackFailedException DOCUMENT_ME
* @throws IllegalStateException DOCUMENT_ME
*/
public void deleteProperty( QName propQName )
throws CallbackFailedException
{
throw new IllegalStateException( "This property cannot be deleted due to schema constraints." );
}
/**
* DOCUMENT_ME
*
* @param propElems DOCUMENT_ME
*
* @throws CallbackFailedException DOCUMENT_ME
* @throws IllegalStateException DOCUMENT_ME
*/
public void insertProperty( Object[] propElems )
throws CallbackFailedException
{
throw new IllegalStateException( "This property cannot be inserted into due to schema constraints." );
}
/**
* DOCUMENT_ME
*
* @param prop DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws CallbackFailedException DOCUMENT_ME
* @throws IllegalArgumentException DOCUMENT_ME
*/
public ResourceProperty refreshProperty( ResourceProperty prop )
throws CallbackFailedException
{
QName propName = prop.getMetaData( ).getName( );
if ( !propName.equals( SubscriptionManagerPortType.PROP_QNAME_CONSUMER_REFERENCE ) )
{
throw new IllegalArgumentException( "Unsupported property: " + propName );
}
if ( prop.isEmpty( ) )
{
ConsumerReferenceDocument consumerRefDoc = ConsumerReferenceDocument.Factory.newInstance( );
consumerRefDoc.addNewConsumerReference( );
prop.add( consumerRefDoc );
}
EndpointReferenceType consumerRef = (EndpointReferenceType) prop.get( 0 );
EndpointReferenceType newConsumerRef =
(EndpointReferenceType) ( (XmlBeansEndpointReference) m_subscription.getConsumerReference( ) )
.getXmlObject( AddressingConstants.NSURI_ADDRESSING_SCHEMA );
consumerRef.set( newConsumerRef );
return prop;
}
/**
* DOCUMENT_ME
*
* @param propElems DOCUMENT_ME
*
* @throws CallbackFailedException DOCUMENT_ME
*/
public void updateProperty( Object[] propElems )
throws CallbackFailedException
{
EndpointReferenceType consumerRef = (EndpointReferenceType) propElems[0];
m_subscription.setConsumerReference( new XmlBeansEndpointReference( consumerRef ) );
}
}