/**
 * $Id: XmlResponseFactory.java,v 1.2 2005/09/13 09:51:45 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 */

package vkc.ws.axis.response;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

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

import vkc.util.StringUtils;

public final class XmlResponseFactory {

	private XmlResponseFactory() {
	}
	
	/**
	 * Methode erzeugt ein Fehler-Dokument als Antwort des Webservice
	 */
	public static final Document createErrorResponseDocument( String msg )
	throws ParserConfigurationException {

		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();

		Document responseDoc = documentBuilder.newDocument();

		Element responseElement = responseDoc.createElement( "response" );
		responseDoc.appendChild( responseElement );

		Element statusElement = responseDoc.createElement( "state" );
		statusElement.setAttribute( "value", "error" );
		responseElement.appendChild( statusElement );

		Element contentElement = responseDoc.createElement( "content" );
		responseElement.appendChild( contentElement );

		contentElement.appendChild( responseDoc.createTextNode( StringUtils.normalize( msg ) ) );

		return responseDoc;
	}

	/**
	 * Methode erzeugt ein Dokument als Antwort des Webservice.
	 */
	public static final Document createResponseDocument()
	throws ParserConfigurationException {

		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();

		Document responseDoc = documentBuilder.newDocument();

		Element responseElement = responseDoc.createElement( "response" );
		responseDoc.appendChild( responseElement );

		Element statusElement = responseDoc.createElement( "state" );
		statusElement.setAttribute( "value", "ok" );
		responseElement.appendChild( statusElement );

		Element contentElement = responseDoc.createElement( "content" );
		responseElement.appendChild( contentElement );

		return responseDoc;
	}	
}
