Package org.apache.muse.ws.resource.sg.impl

Source Code of org.apache.muse.ws.resource.sg.impl.AddResponse

/*=============================================================================*
*  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.resource.sg.impl;

import java.text.ParseException;
import java.util.Date;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

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.ext.faults.InvalidMessageFormatFault;
import org.apache.muse.ws.resource.remote.WsResourceClient;
import org.apache.muse.ws.resource.sg.WssgConstants;
import org.apache.muse.util.xml.XmlSerializable;
import org.apache.muse.util.xml.XmlUtils;

/**
*
* AddResponse is a serializer/deserializer for the WS-ServiceGroup Add
* operation's response content.
*
* @author Dan Jemiolo (danj)
*
*/

public class AddResponse implements XmlSerializable
{
    //
    // Used to look up all exception messages
    //
    private static Messages _MESSAGES = MessagesFactory.get(AddResponse.class);
   
    private Date _currentTime = new Date();
   
    private EndpointReference _entryEPR = null;
   
    private Date _terminationTime = null;
   
    public AddResponse(Element xml)
        throws InvalidMessageFormatFault
    {
        if (xml == null)
            throw new NullPointerException(_MESSAGES.get("NullElement"));
       
        Element eprXML = XmlUtils.getElement(xml, WssgConstants.SG_ENTRY_REFERENCE_QNAME);

        if (eprXML == null)
            throw new InvalidMessageFormatFault(_MESSAGES.get("NoEntryEPR"));
       
        try
        {
            _entryEPR = new EndpointReference(eprXML);
        }
       
        catch (SoapFault error)
        {
            throw new InvalidMessageFormatFault(error);
        }
       
        Element currentXML = XmlUtils.getElement(xml, WssgConstants.CURRENT_TIME_QNAME);
        Element terminationXML = XmlUtils.getElement(xml, WssgConstants.TERMINATION_TIME_QNAME);
       
        try
        {
            _currentTime = XmlUtils.getDate(currentXML);
            _terminationTime = XmlUtils.getDate(terminationXML);
        }
       
        catch (ParseException error)
        {
            throw new InvalidMessageFormatFault(error);
        }
    }
   
    public AddResponse(EndpointReference entryEPR)
    {
        this(entryEPR, null);
    }
   
    public AddResponse(EndpointReference entryEPR, Date terminationTime)
    {
        _entryEPR = entryEPR;
        _terminationTime = terminationTime;
    }
   
    public Date getCurrentTime()
    {
        return _currentTime;
    }
   
    public WsResourceClient getEntryClient()
    {
        return new WsResourceClient(_entryEPR);
    }
   
    public Date getTerminationTime()
    {
        return _terminationTime;
    }

    public Element toXML()
    {
        return toXML(XmlUtils.EMPTY_DOC);
    }

    public Element toXML(Document doc)
    {
        if (doc == null)
            throw new NullPointerException(_MESSAGES.get("NullDocument"));
       
        Element root = XmlUtils.createElement(doc, WssgConstants.ADD_RESPONSE_QNAME);
       
        Element eprXML = _entryEPR.toXML(doc);
        XmlUtils.setElement(root, WssgConstants.SG_ENTRY_REFERENCE_QNAME, eprXML);
       
        XmlUtils.setElement(root, WssgConstants.CURRENT_TIME_QNAME, getCurrentTime());
        XmlUtils.setElement(root, WssgConstants.TERMINATION_TIME_QNAME, getTerminationTime());
               
        return root;
    }
}
TOP

Related Classes of org.apache.muse.ws.resource.sg.impl.AddResponse

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.