/*******************************************************************************
* =============================================================================
* 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.dm.muws.adv.impl;
import org.w3c.dom.Element;
import org.apache.muse.core.Resource;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
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.dm.muws.MuwsConstants;
import org.apache.muse.ws.dm.muws.events.WefConstants;
import org.apache.muse.ws.resource.sg.Entry;
import org.apache.muse.ws.resource.sg.ServiceGroup;
import org.apache.muse.ws.resource.sg.WssgConstants;
/**
*
* @author Dan Jemiolo (danj)
* @author Joel Hawkins
*
*/
public class ServiceGroupEntryAdvertisement extends SimpleAdvertisement
{
private static Messages _MESSAGES = MessagesFactory.get(ServiceGroupEntryAdvertisement.class);
public void initialize()
throws SoapFault
{
super.initialize();
//
// make sure the owner resource type IS a service group
//
Resource resource = getResource();
if (!resource.hasCapability(WssgConstants.SERVICE_GROUP_URI))
{
Object[] filler = { resource.getContextPath(), resource.getCapabilityURIs() };
throw new RuntimeException(_MESSAGES.get("NoServiceGroupCapability", filler));
}
}
public void resourceAdded(EndpointReference epr, Resource resource) throws SoapFault
{
Entry entry = (Entry)resource.getCapability(WssgConstants.ENTRY_URI);
//
// resource is not a service group entry
//
if (entry == null)
return;
//
// if the resource the service group that owns the entry, send a message
//
if (isAdvertised(entry.getServiceGroupEPR()))
{
Element payload = XmlUtils.createElement(MuwsConstants.MANAGEABILITY_EPR_QNAME, epr.toXML());
sendMessage(epr, MuwsConstants.ADV_ME_CREATION_TOPIC, WefConstants.CREATE_SITUATION_QNAME, payload);
}
}
public void resourceRemoved(EndpointReference epr) throws SoapFault
{
ServiceGroup serviceGroup = (ServiceGroup)getResource().getCapability(WssgConstants.SERVICE_GROUP_URI);
if (serviceGroup.getEntry(epr) != null)
{
Element payload = XmlUtils.createElement(MuwsConstants.DESTROY_NOTIFICATION_QNAME);
sendMessage(epr, MuwsConstants.ADV_ME_DESTRUCTION_TOPIC, WefConstants.DESTROY_SITUATION_QNAME, payload);
}
}
}