RequestMessage.java :  » XML » alttext » nl » dedicon » converter » service » Java Open Source

Java Open Source » XML » alttext 
alttext » nl » dedicon » converter » service » RequestMessage.java
/*
 * Copyright (C) 2010 Dedicon <http://dedicon.nl>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Linking altText statically or dynamically with other modules 
is making a combined work based on altText. Thus, the terms and 
conditions of the GNU General Public License cover
the whole combination.  In addition, as a special exception, 
the copyright holders of altText give you permission to
combine altText program with free software programs or libraries 
that are released under the GNU LGPL or the Common Public License version 1.0. 
You may copy and distribute such a system following the terms 
of the GNU GPL for altText and the licenses of the other code
concerned, provided that you include the source code of that other 
code when and as the GNU GPL requires distribution of source code.

Note that people who make modified versions of altText are not obligated to 
grant this special exception for their modified versions; it is their 
choice whether to do so. The GNU General Public License gives permission 
to release a modified version without this exception; this exception 
also makes it possible to release a modified version which carries
forward this exception.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Author : Javier Asensio Cubero capitan{.}cambio{@}gmail{.}com
 */
package nl.dedicon.converter.service;

import java.util.HashMap;
import java.util.Set;
import java.util.logging.Logger;

import javax.xml.parsers.ParserConfigurationException;

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

import nl.dedicon.converter.core.xml.XmlDocument;

// TODO: Auto-generated Javadoc
/**
 * The Class RequestMessage defines a request message.
 */
public class RequestMessage extends ProtocolMessage {
  
  /** The logger. */
  private Logger logger = Logger.getLogger("nl.dedicon.converter.service");

  /** The m params. */
  private HashMap<String, String> mParams= new HashMap<String, String>();
  
  /* (non-Javadoc)
   * @see nl.dedicon.converter.service.ProtocolMessage#getXml()
   */
  @Override
  public XmlDocument getXml() {
    XmlDocument ret = new XmlDocument();
    try {
      ret.emptyDocument();
    } catch (ParserConfigurationException e) {
      
    }
    Document doc = ret.getDocument();
    Element message = doc.createElement("message");
    Element response = doc.createElement("request");
    
    String buildingInfo="";
    if (this.mId != null) {
      response.setAttribute("id", this.mId);
    } else {
      logger.warning("No id for the reply, setting an empty value");
      response.setAttribute("id", "");
    }
    if(this.mType!=null)
      response.setAttribute("type", this.mType);
    else{
      logger.warning("No id for the response, setting an empty value");
      response.setAttribute("type", "err");
    }
    response.setAttribute("time", this.mDate);
    
    for (String key:this.mParams.keySet()){
      Element param = doc.createElement("param");
      param.setAttribute("name", key);
      param.setAttribute("value", this.mParams.get(key));
      response.appendChild(param);
    }
  
    message.appendChild(response);
    doc.appendChild(message);
    return ret;
    
  }
  
  /**
   * Adds the param.
   * 
   * @param key the key
   * @param value the value
   */
  public void addParam(String key,String value){
    this.mParams.put(key, value);
  }
  
  /**
   * Gets the param keys.
   * 
   * @return the param keys
   */
  public Set<String> getParamKeys(){
    return this.mParams.keySet();
  }
  
  /**
   * Gets the param.
   * 
   * @param name the name
   * 
   * @return the param
   */
  public String getParam(String name){
    String ret=  this.mParams.get(name);
    return (ret==null)?"":ret;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.