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