/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.servlet;

import java.io.IOException;
import org.apache.log4j.Logger;
import com.silverwrist.dynamo.HttpStatusCode;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.*;

class SubObjectSelfRenderControl implements SelfRenderControl
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private TextRenderControl m_inner;
  private SubObjectTextRenderControl m_subobj = null;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  SubObjectSelfRenderControl(TextRenderControl inner)
  {
    m_inner = inner;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface ServiceProvider
   *--------------------------------------------------------------------------------
   */

  /**
   * Queries this object for a specified service.
   *
   * @param klass The class of the object that should be returned as a service.
   * @return A service object.  The service object is guaranteed to be of the class
   *         specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
   *         yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
   *         is true.
   * @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
   *            the specified class.
   */
  public Object queryService(Class klass)
  {
    return m_inner.queryService(klass);

  } // end queryService

  /**
   * Queries this object for a specified service.
   *
   * @param klass The class of the object that should be returned as a service.
   * @param serviceid ID for the service to be requested, to further discriminate between requests.
   * @return A service object.  The service object is guaranteed to be of the class
   *         specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
   *         yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
   *         is true.
   * @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
   *            the specified class.
   */
  public Object queryService(Class klass, String serviceid)
  {
    return m_inner.queryService(klass,serviceid);

  } // end queryService

  /*--------------------------------------------------------------------------------
   * Implementations from interface SelfRenderControl
   *--------------------------------------------------------------------------------
   */

  public void status(HttpStatusCode code) throws RenderingException
  {
    throw new RenderingException(SubObjectSelfRenderControl.class,"ServletBaseMessages",
				 "selfRender.noStatus");

  } // end status

  public void redirect(String location) throws RenderingException
  {
    throw new RenderingException(SubObjectSelfRenderControl.class,"ServletBaseMessages",
				 "selfRender.noRedirect");

  } // end redirect

  public void error(HttpStatusCode code) throws RenderingException
  {
    throw new RenderingException(SubObjectSelfRenderControl.class,"ServletBaseMessages",
				 "selfRender.noSetErr");

  } // end error

  public void error(HttpStatusCode code, String message) throws IOException, RenderingException
  {
    throw new RenderingException(SubObjectSelfRenderControl.class,"ServletBaseMessages",
				 "selfRender.noSetErr");

  } // end error

  public TextRenderControl getTextRender()
  {
    if (m_subobj==null)
      m_subobj = new SubObjectTextRenderControl(m_inner);
    return m_subobj;

  } // end getTextRender

  public BinaryRenderControl getBinaryRender() throws RenderingException
  {
    throw new RenderingException(SubObjectSelfRenderControl.class,"ServletBaseMessages","binaryInsideText");

  } // end getBinaryRender

} // end class SubObjectSelfRenderControl
