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

org.objectweb.dream.InitializationException Maven / Gradle / Ivy

Go to download

Dream Annotation is an extension of Fraclet Annotation 2.0 to generate code related to activities managed in Dream Components. It adds the following annotations : @DreamComponent, @DreamMonolog and @DreamLifeCycle. This version adds inheritance for the @DreamMonolog annotation.

The newest version!
/**
 * Dream Copyright (C) 2003-2004 INRIA Rhone-Alpes
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 * 
 * This library 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 Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * Contact: [email protected]
 * 
 * Initial developer(s): Matthieu Leclercq 
 * Contributor(s):
 */

package org.objectweb.dream;

import java.io.PrintStream;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.NameController;
import org.objectweb.fractal.api.control.SuperController;

/**
 * Exception thrown by {@link AbstractComponent#initComponent()}.
 */
public class InitializationException extends Exception
{

  private static final long   serialVersionUID = 3257566204846813233L;

  /**
   * The exception that caused this exception. May be null.
   */
  private final Throwable     exception;

  /**
   * The component whose life cycle state is illegal.
   */
  private transient Component component;

  /**
   * Constructs a new {@link InitializationException}exception.
   * 
   * @param exception the cause of this exception. May be null.
   * @param component the component whose life cycle state is illegal.
   * @param message a detailed error message.
   */
  public InitializationException(final Throwable exception,
      final Component component, final String message)
  {
    super(message);
    this.exception = exception;
    this.component = component;
  }

  /**
   * Returns the exception that caused in this exception.
   * 
   * @return the exception that caused this exception. May be null.
   */

  public Throwable getException()
  {
    return exception;
  }

  /**
   * Returns the component whose life cycle state is illegal.
   * 
   * @return the component whose life cycle state is illegal.
   */

  public Component getComponent()
  {
    if (component != null && !(component instanceof Interface))
    {
      try
      {
        return (Component) component.getFcInterface("component");
      }
      catch (NoSuchInterfaceException ignored)
      {
      }
    }
    return component;
  }

  // ---------------------------------------------------------------------------
  // Overriden Exception methods
  // ---------------------------------------------------------------------------

  /**
   * @see Throwable#toString()
   */
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("InitializationException: ");
    buf.append(getMessage());
    if (getComponent() != null)
    {
      buf.append(" (component = ");
      this.toString(getComponent(), buf);
      buf.append(')');
    }
    return buf.toString();
  }

  /**
   * Computes a string representation of the given component.
   *
   * @param component a component.
   * @param buf the buffer to be used to store the result of this method.
   */

  private void toString (
    final Component component,
    final StringBuffer buf)
  {
    try {
      NameController nc =
        (NameController)component.getFcInterface("name-controller");
      try {
        SuperController sc =
          (SuperController)component.getFcInterface("super-controller");
        Component[] superComponents = sc.getFcSuperComponents();
        if (superComponents.length > 0) {
          toString(superComponents[0], buf);
        }
      } catch (NoSuchInterfaceException ignored) {
      }
      buf.append('/');
      buf.append(nc.getFcName());
    } catch (NoSuchInterfaceException e) {
      buf.append(component.toString());
      return;
    }
  }  
  
  /**
   * @see Throwable#printStackTrace(PrintStream)
   */
  public void printStackTrace(final PrintStream s)
  {
    super.printStackTrace(s);
    if (exception != null)
    {
      s.print("Caused by : ");
      exception.printStackTrace(s);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy