/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.resource.sg.impl;
import java.lang.reflect.Method;
import java.util.Date;
import org.w3c.dom.Element;
import org.apache.muse.core.routing.MessageHandler;
import org.apache.muse.util.ReflectUtils;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.ws.addressing.EndpointReference;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.resource.WsResource;
import org.apache.muse.ws.resource.basefaults.BaseFault;
import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
import org.apache.muse.ws.resource.sg.ServiceGroup;
import org.apache.muse.ws.resource.sg.ServiceGroupRegistration;
import org.apache.muse.ws.resource.sg.WssgConstants;
import org.apache.muse.ws.resource.sg.faults.AddRefusedFault;
import org.apache.muse.ws.resource.sg.faults.ContentCreationFailedFault;
import org.apache.muse.ws.resource.sg.faults.UnsupportedMemberInterfaceFault;
/**
*
* SimpleServiceGroupRegistration is Muse's default implementation of the
* WS-RF ServiceGroupRegistration capability - it simply forwards all
* wsrf-sg:Add requests to the ServiceGroup.addEntry() method.
*
* @author Dan Jemiolo (danj)
*
*/
public class SimpleServiceGroupRegistration
extends AbstractWsResourceCapability implements ServiceGroupRegistration
{
//
// Used to look up all exception messages
//
private static Messages _MESSAGES = MessagesFactory.get(SimpleServiceGroupRegistration.class);
//
// the WS-SG capability we're forwarding to
//
private ServiceGroup _sg = null;
public EndpointReference add(EndpointReference memberEPR,
Element content,
Date terminationTime)
throws AddRefusedFault,
ContentCreationFailedFault,
UnsupportedMemberInterfaceFault,
BaseFault
{
WsResource entry = getServiceGroup().addEntry(memberEPR, content, terminationTime);
return entry.getEndpointReference();
}
protected MessageHandler createAddHandler()
{
MessageHandler handler = new AddHandler();
Method method = ReflectUtils.getFirstMethod(getClass(), "add");
handler.setMethod(method);
return handler;
}
protected ServiceGroup getServiceGroup()
{
return _sg;
}
public void initialize()
throws SoapFault
{
super.initialize();
_sg = (ServiceGroup)getWsResource().getCapability(WssgConstants.SERVICE_GROUP_URI);
//
// make sure the SG capability is used - otherwise we have no one
// to handle the add operation!
//
if (_sg == null)
{
Object[] filler = { getWsResource().getContextPath(), WssgConstants.SERVICE_GROUP_URI };
throw new IllegalStateException(_MESSAGES.get("NoServiceGroupCapability", filler));
}
setMessageHandler(createAddHandler());
}
}