All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xins.client.XINSCallConfig Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
/*
 * $Id: XINSCallConfig.java,v 1.14 2006/08/28 09:12:31 agoubard Exp $
 *
 * Copyright 2003-2006 Orange Nederland Breedband B.V.
 * See the COPYRIGHT file for redistribution and use restrictions.
 */
package org.xins.client;

import org.xins.common.MandatoryArgumentChecker;
import org.xins.common.http.HTTPCallConfig;
import org.xins.common.http.HTTPMethod;
import org.xins.common.service.CallConfig;
import org.xins.common.text.FastStringBuffer;
import org.xins.common.text.TextUtils;

/**
 * Call configuration for the XINS service caller. The HTTP method and the
 * can be configured. By default it is set to POST.
 *
 * @version $Revision: 1.14 $ $Date: 2006/08/28 09:12:31 $
 * @author Ernst de Haan
 *
 * @since XINS 1.1.0
 */
public final class XINSCallConfig extends CallConfig {

   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   /**
    * The number of instances of this class. Initially zero.
    */
   private static int INSTANCE_COUNT;

   /**
    * Lock object for field INSTANCE_COUNT.
    */
   private static Object INSTANCE_COUNT_LOCK = new Object();


   //-------------------------------------------------------------------------
   // Constructors
   //-------------------------------------------------------------------------

   /**
    * Constructs a new XINSCallConfig object.
    */
   public XINSCallConfig() {

      // First determine instance number
      synchronized (INSTANCE_COUNT_LOCK) {
         _instanceNumber = ++INSTANCE_COUNT;
      }

      // Construct an underlying HTTPCallConfig
      _httpCallConfig = new HTTPCallConfig();

      // Configure the User-Agent header
      String userAgent = "XINS/Java Client Framework " + Library.getVersion();
      _httpCallConfig.setUserAgent(userAgent);

      // NOTE: HTTPCallConfig already defaults to HTTP POST
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   /**
    * The 1-based sequence number of this instance. Since this number is
    * 1-based, the first instance of this class will have instance number 1
    * assigned to it.
    */
   private final int _instanceNumber;

   /**
    * The underlying HTTP call config. Cannot be null.
    */
   private HTTPCallConfig _httpCallConfig;


   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Returns an HTTPCallConfig object that corresponds with this
    * XINS call configuration object.
    *
    * @return
    *    an {@link HTTPCallConfig} object, never null.
    */
   HTTPCallConfig getHTTPCallConfig() {
      return _httpCallConfig;
   }

   /**
    * Returns the HTTP method associated with this configuration.
    *
    * @return
    *    the HTTP method, never null.
    */
   public HTTPMethod getHTTPMethod() {
      return _httpCallConfig.getMethod();
   }

   /**
    * Sets the HTTP method associated with this configuration.
    *
    * @param method
    *    the HTTP method to be associated with this configuration, cannot be
    *    null.
    *
    * @throws IllegalArgumentException
    *    if method == null.
    */
   public void setHTTPMethod(HTTPMethod method)
   throws IllegalArgumentException {

      // Check preconditions
      MandatoryArgumentChecker.check("method", method);

      // Store the setting in the HTTP call configuration
      _httpCallConfig.setMethod(method);
   }

   /**
    * Describes this configuration.
    *
    * @return
    *    the description of this configuration, should never be
    *    null, should never be empty and should never start or
    *    end with whitespace characters.
    */
   public String describe() {

      boolean    failOverAllowed;
      HTTPMethod method;
      synchronized (getLock()) {
         failOverAllowed = isFailOverAllowed();
         method          = _httpCallConfig.getMethod();
      }

      FastStringBuffer buffer = new FastStringBuffer(51);
      buffer.append("XINS call config #");
      buffer.append(_instanceNumber);
      buffer.append(" [failOverAllowed=");
      buffer.append(failOverAllowed);
      buffer.append("; method=");
      buffer.append(TextUtils.quote(method.toString()));
      buffer.append(']');

      return buffer.toString();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy