Code Search for Developers
 
 
  

FixtureLoader.java from MASE: Agile Software Engineering at Krugle


Show FixtureLoader.java syntax highlighted

// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.
// Copyright (C) 2003,2004 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the GNU General Public License version 2 or
// later.
package fit;

import java.util.*;

import fit.exception.*;



// REFACTOR The fixture path is really the only part of this
// class that needs to be globally accessible.
public class FixtureLoader
{
  private static FixtureLoader instance;

  public static FixtureLoader instance()
  {
    if (instance == null)
    {
      instance = new FixtureLoader();
    }

    return instance;
  }

  public Set fixturePathElements = new HashSet()
  {
    {
      add("fit");
    }
  };

  public Fixture disgraceThenLoad(String tableName) throws Throwable
  {
    FixtureName fixtureName = new FixtureName(tableName);
    Fixture fixture = instantiateFirstValidFixtureClass(fixtureName);
    addPackageToFixturePath(fixture);
    return fixture;
  }

  private void addPackageToFixturePath(Fixture fixture)
  {
    Package fixturePackage = fixture.getClass().getPackage();
    if (fixturePackage != null)
        addPackageToPath(fixturePackage.getName());
  }

  public void addPackageToPath(String name)
  {
    fixturePathElements.add(name);
  }

  private Fixture instantiateFixture(String fixtureName) throws Throwable
  {
    Class classForFixture = loadFixtureClass(fixtureName);
    FixtureClass fixtureClass = new FixtureClass(classForFixture);
    return fixtureClass.newInstance();
  }

  private Class loadFixtureClass(String fixtureName)
  {
    try
    {
      return Class.forName(fixtureName);
    }
    catch (ClassNotFoundException deadEnd)
    {
      if (deadEnd.getMessage().equals(fixtureName))
        throw new NoSuchFixtureException(fixtureName);
      else
        throw new CouldNotLoadComponentFitFailureException(
            deadEnd.getMessage(), fixtureName);
    }
  }

  private Fixture instantiateFirstValidFixtureClass(FixtureName fixtureName)
      throws Throwable
  {
    for (Iterator i = fixtureName.getPotentialFixtureClassNames(
        fixturePathElements).iterator(); i.hasNext();)
    {
      String each = (String) i.next();
      try
      {
        return instantiateFixture(each);
      }
      catch (NoSuchFixtureException ignoreAndTryTheNextCandidate)
      {
      }
    }

    throw new NoSuchFixtureException(fixtureName.toString());
  }
}



See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  exception/
    AmbiguousActionException.java
    AmbiguousNameFailureException.java
    BooleanMethodFitFailureException.java
    ClassIsNotFixtureException.java
    CouldNotLoadComponentFitFailureException.java
    CouldNotParseFitFailureException.java
    CycleException.java
    ExtraCellsFailureException.java
    FitFailureException.java
    FitFailureExceptionWithHelp.java
    FitMatcherException.java
    FitParseException.java
    FixtureException.java
    IgnoredException.java
    MissingCellsFailureException.java
    MissingFieldFitFailureException.java
    MissingMethodException.java
    MissingRowFailureException.java
    NestedTableExpected.java
    NoDefaultConstructorFixtureException.java
    NoSuchFieldFitFailureException.java
    NoSuchFixtureException.java
    NoSuchMethodFitFailureException.java
    RowWrongWidthException.java
    VoidMethodFitFailureException.java
  ActionFixture.java
  Binding.java
  ColumnFixture.java
  Comment.java
  Counts.java
  FileRunner.java
  FitMatcher.java
  Fixture.java
  FixtureClass.java
  FixtureListener.java
  FixtureLoader.java
  FixtureName.java
  GracefulNamer.java
  ImportFixture.java
  NullFixtureListener.java
  Parse.java
  PrimitiveFixture.java
  RowFixture.java
  ScientificDouble.java
  SummaryFixture.java
  TestRunner.java
  TimedActionFixture.java
  TypeAdapter.java
  WikiRunner.java