/*=============================================================================*
* Copyright 2006 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.muse.ws.notification.impl;
import org.apache.muse.core.ResourceManager;
import org.apache.muse.ws.addressing.EndpointReference;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.notification.Filter;
import org.apache.muse.ws.notification.NotificationProducer;
import org.apache.muse.ws.notification.PullPoint;
import org.apache.muse.ws.notification.PullPointCreation;
import org.apache.muse.ws.notification.WsnConstants;
import org.apache.muse.ws.notification.faults.UnableToCreatePullPointFault;
import org.apache.muse.ws.resource.WsResource;
import org.apache.muse.ws.resource.basefaults.BaseFault;
import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
/**
*
* SimplePullPointCreation is Muse's default implementation of the
* WS-Notification PullPointCreation port type.
* <br><br>
* Resources that implement this port type should be deployed with the
* {@linkplain PullPoint PullPoint} type as well; the pullpoint resources
* cannot be managed without this endpoint.
*
* @author Dan Jemiolo (danj)
*
*/
public class SimplePullPointCreation
extends AbstractWsResourceCapability implements PullPointCreation
{
//
// context path of the pullpoint resource type
//
private String _pullPointPath = null;
public EndpointReference createPullPoint()
throws UnableToCreatePullPointFault
{
ResourceManager manager = getResource().getResourceManager();
//
// create the resource to represent the pullpoint
//
String endpoint = getPullPointContextPath();
WsResource pullPoint = null;
try
{
pullPoint = (WsResource)manager.createResource(endpoint);
}
catch (SoapFault error)
{
throw new UnableToCreatePullPointFault(error);
}
EndpointReference epr = pullPoint.getEndpointReference();
PullPoint pullPointCap = (PullPoint)pullPoint.getCapability(WsnConstants.PULL_POINT_URI);
Filter filter = pullPointCap.getFilter();
//
// create subscription that will send messages to the pullpoint
//
NotificationProducer wsn = (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
WsResource sub = null;
try
{
sub = wsn.subscribe(epr, filter, null, null);
}
catch (BaseFault error)
{
throw new UnableToCreatePullPointFault(error);
}
pullPointCap.setSubscription(sub);
//
// initialize pullpoint to complete creation process
//
try
{
pullPoint.initialize();
manager.addResource(epr, pullPoint);
}
catch (SoapFault error)
{
throw new UnableToCreatePullPointFault(error);
}
return epr;
}
protected String getPullPointContextPath()
{
return _pullPointPath;
}
public void initialize() throws SoapFault
{
super.initialize();
//
// find pullpoint resource type so we can create instances of it
// in createPullPoint()
//
ResourceManager manager = getResource().getResourceManager();
_pullPointPath = manager.getResourceContextPath(PullPoint.class);
if (_pullPointPath == null)
throw new RuntimeException("No PullPoint endpoint deployed");
}
}