Package org.apache.muse.ws.notification.impl

Source Code of org.apache.muse.ws.notification.impl.NotificationProducerFilePersistence

/*=============================================================================*
*  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 java.io.File;
import java.io.IOException;

import org.w3c.dom.Element;

import org.apache.muse.core.AbstractFilePersistence;
import org.apache.muse.core.Resource;
import org.apache.muse.util.xml.XmlUtils;
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.NotificationProducerPersistence;
import org.apache.muse.ws.notification.SubscriptionManager;
import org.apache.muse.ws.notification.WsnConstants;
import org.apache.muse.ws.resource.WsResource;

/**
*
* NotificationProducerFilePersistence is an implementation of file-based
* persistence of subscription resource data. It stores data about current
* subscription resources on disk and then re-loads them after an application
* restarts. This allows the producer resource to continue functioning as it was
* before the restart without the application having to notify all subscribers
* and have them re-subscribe.
*
* @author Dan Jemiolo (danj)
*
*/

public class NotificationProducerFilePersistence
    extends AbstractFilePersistence implements NotificationProducerPersistence
{
    private NotificationProducer _producer = null;
   
    protected void createResourceFile(EndpointReference epr, Resource resource, File resourceFile)
        throws SoapFault
    {
        //
        // write subscription ws-rp doc to file
        //
        SubscriptionManager sub = (SubscriptionManager)resource.getCapability(WsnConstants.SUBSCRIPTION_MGR_URI);
        Element subXML = sub.toXML();
       
        try
        {
            XmlUtils.toFile(subXML, resourceFile);
        }
       
        catch (IOException error)
        {
            throw new SoapFault(error);
        }
    }
   
    protected String getFilePrefix()
    {
        return "subscription-";
    }

    public NotificationProducer getNotificationProducer()
    {
        return _producer;
    }
   
    protected Resource reloadResource(String contextPath, Element resourceXML)
        throws SoapFault
    {
        //
        // get the EPR of the entry resource so we can look it up
        //
        Element subEprXML = XmlUtils.getElement(resourceXML, WsnConstants.SUBSCRIPTION_EPR_QNAME);
        EndpointReference subEPR = new EndpointReference(subEprXML);
       
        //
        // get properties of the subscription so we can add them back to
        // the resource instance
        //
        Element consumerEprXML = XmlUtils.getElement(resourceXML, WsnConstants.CONSUMER_QNAME);
        EndpointReference consumerEPR = new EndpointReference(consumerEprXML);
       
        Element producerEprXML = XmlUtils.getElement(resourceXML, WsnConstants.PRODUCER_QNAME);
        EndpointReference producerEPR = new EndpointReference(producerEprXML);
       
        Element filterXML = XmlUtils.getElement(resourceXML, WsnConstants.FILTER_QNAME);
        Filter filter = FilterFactory.getInstance().newInstance(filterXML, null);
       
        //
        // find the subscription resource, use the SubscriptionManager capability
        // to set property values
        //
        WsResource subResource = (WsResource)getResourceManager().getResource(subEPR);
        SubscriptionManager sub = (SubscriptionManager)subResource.getCapability(WsnConstants.SUBSCRIPTION_MGR_URI);
       
        sub.setConsumerReference(consumerEPR);
        sub.setProducerReference(producerEPR);
        sub.setFilter(filter);
       
        getNotificationProducer().addSubscription(subResource);
       
        return subResource;
    }
   
    public void resourceAdded(EndpointReference epr, Resource resource)
        throws SoapFault
    {
        createResourceFile(epr, resource);
    }

    public void resourceRemoved(EndpointReference epr)
        throws SoapFault
    {
        destroyResourceFile(epr);
    }

    public void setNotificationProducer(NotificationProducer producer)
    {
        _producer = producer;
    }
}
TOP

Related Classes of org.apache.muse.ws.notification.impl.NotificationProducerFilePersistence

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.