/*
 * Copyright (c) 2001, University of Washington, Department of
 * Computer Science and Engineering.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 *
 * 3. Neither name of the University of Washington, Department of
 * Computer Science and Engineering nor the names of its contributors
 * may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package one.world.app;

import one.world.core.Component;
import one.world.core.ComponentDescriptor;
import one.world.core.Environment;
import one.world.core.Event;
import one.world.core.EventHandler;
import one.world.core.ExportedDescriptor;
import one.world.core.ImportedDescriptor;

import one.world.util.AbstractHandler;

/**
 * XXX --- Modify code that is marked with XXX
 *
 * <p><b>Imported and Exported Event Handlers</b></p>
 *
 * <p>Exported event handlers:<dl>
 *    <dt>one</dt>
 *    <dd> XXX
 *        </dd>
 *    <dt>three</dt>
 *    <dd> XXX
 *        </dd>
 * </dl></p>
 *
 * <p>Imported event handlers:<dl>
 *    <dt>two</dt>
 *    <dd> XXX
 *        </dd>
 * </dl></p>
 *
 * @version  $Revision$
 * @author   XXX
 */
public final class Sample extends Component {

  // =======================================================================
  //                           The one handler
  // =======================================================================

  /** The one exported event handler. */
  final class OneHandler extends AbstractHandler {

    /** Handle the specified event. */
    protected boolean handle1(Event e) {

      // XXX

      return false;
    }
  }


  // =======================================================================
  //                           The three handler
  // =======================================================================

  /** The three exported event handler. */
  final class ThreeHandler extends AbstractHandler {

    /** Handle the specified event. */
    protected boolean handle1(Event e) {

      // XXX

      return false;
    }
  }


  // =======================================================================
  //                           Descriptors
  // =======================================================================

  /** The component descriptor. */
  private static final ComponentDescriptor SELF =
    new ComponentDescriptor("one.world.app.Sample",
                            "A simple sample component",
                            true);

  /** The exported event handler descriptor for the one handler. */
  private static final ExportedDescriptor ONE =
    new ExportedDescriptor("one",
                           "An exported event handler",
                           null,   // XXX
                           null,   // XXX
                           true);

  /** The exported event handler descriptor for the three handler. */
  private static final ExportedDescriptor THREE =
    new ExportedDescriptor("three",
                           "Another exported event handler",
                           null,   // XXX
                           null,   // XXX
                           false);

  /** The imported event handler descriptor for the two handler. */
  private static final ImportedDescriptor TWO =
    new ImportedDescriptor("two",
                           "An imported event handler",
                           null,   // XXX
                           null,   // XXX
                           false,
                           true);


  // =======================================================================
  //                           Instance fields
  // =======================================================================

  /**
   * The one exported event handler.
   *
   * @serial  Must not be <code>null</code>.
   */
  private final EventHandler       one;

  /**
   * The three exported event handler.
   *
   * @serial  Must not be <code>null</code>.
   */
  private final EventHandler       three;

  /**
   * The two imported event handler.
   *
   * @serial  Must not be <code>null</code>.
   */
  private final Component.Importer two;


  // =======================================================================
  //                           Constructor
  // =======================================================================

  /**
   * Create a new instance of <code>Sample</code>.
   *
   * @param  env  The environment for the new instance.
   */
  public Sample(Environment env) {
    super(env);
    one = declareExported(ONE, new OneHandler());
    three = declareExported(THREE, new ThreeHandler());
    two = declareImported(TWO);
  }


  // =======================================================================
  //                           Component support
  // =======================================================================

  /** Get the component descriptor. */
  public ComponentDescriptor getDescriptor() {
    return (ComponentDescriptor)SELF.copy();
  }

}

