01: // Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
02: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
03: // Released under the terms of the GNU General Public License version 2 or later.
04: package fit;
05:
06: import fit.exception.*;
07:
08: public class FixtureClass {
09: private Class klass;
10:
11: public FixtureClass(Class klass) {
12: this .klass = klass;
13: }
14:
15: public Fixture newInstance() throws IllegalAccessException {
16: // Instantiate according to policies?
17: // Example: policy #1 -- has default constructor
18: // ...
19:
20: String fixtureClassName = klass.getName();
21:
22: try {
23: Object fixtureAsObject = klass.newInstance();
24:
25: if (fixtureAsObject instanceof Fixture) {
26: return (Fixture) fixtureAsObject;
27: } else {
28: throw new ClassIsNotFixtureException(fixtureClassName);
29: }
30: } catch (IllegalAccessException unhandled) {
31: // TODO: Handle constructor not public?
32: throw unhandled;
33: } catch (InstantiationException e) {
34: // TODO: Handle interface/abstract class case?
35: throw new NoDefaultConstructorFixtureException(
36: fixtureClassName);
37: }
38: }
39: }
|