View Javadoc

1   /*
2   Wotonomy: OpenStep design patterns for pure Java applications.
3   Copyright (C) 2001 Michael Powers
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, see http://www.gnu.org
17  */
18  
19  package net.wotonomy.control;
20  
21  /***
22  * EOFaultHandler defines the contract for objects that can
23  * create and populate faults.  In wotonomy, this interface is
24  * currently only a marker interface.
25  *
26  * @author michael@mpowers.net
27  * @author $Author: cgruber $
28  * @version $Revision: 893 $
29  */
30  public abstract class EOFaultHandler {
31  
32  	protected Class _targetClass;
33  
34  	public EOFaultHandler() {
35  		super();
36  	}
37  
38  	public static EOFaultHandler handlerForFault(Object obj) {
39  		if (!(obj instanceof EOFaulting))
40  			throw new IllegalArgumentException("Object must implement EOFaulting");
41  		return ((EOFaulting)obj).faultHandler();
42  	}
43  
44  	public static boolean isFault(Object obj) {
45  		if (obj == null)
46  			return false;
47  		boolean isit = (obj instanceof EOFaulting);
48  		if (isit)
49  			isit = ((EOFaulting)obj).isFault();
50  		return isit;
51  	}
52  
53  	public static void makeObjectIntoFault(Object obj, EOFaultHandler handler) {
54  		if (!(obj instanceof EOFaulting))
55  			throw new IllegalArgumentException("Object must implement EOFaulting");
56  		((EOFaulting)obj).turnIntoFault(handler);
57  	}
58  
59  	public static void clearFault(Object obj) {
60  		if (!(obj instanceof EOFaulting))
61  			throw new IllegalArgumentException("Object must implement EOFaulting");
62  		((EOFaulting)obj).clearFault();
63  	}
64  
65  	public Class targetClass() {
66  		return _targetClass;
67  	}
68  
69  	public Object createFaultForDeferredFault(Object fault, EOEnterpriseObject source) {
70  		return fault;
71  	}
72  
73  	public String descriptionForObject(Object obj) {
74  		if (obj == null)
75  			return "<null>";
76  		return obj.toString();
77  	}
78  
79  	public String eoShallowDescription(Object obj) {
80  		return null;
81  	}
82  
83  	public abstract void completeInitializationOfObject(Object obj);
84  
85  	public abstract void faultWillFire(Object obj);
86  
87  }
88  
89  /*
90   * $Log$
91   * Revision 1.1  2006/02/16 13:19:57  cgruber
92   * Check in all sources in eclipse-friendly maven-enabled packages.
93   *
94   * Revision 1.2  2003/08/19 01:53:12  chochos
95   * EOObjectStore had some incompatible return types (Object instead of EOEnterpriseObject, in fault methods mostly). It's internally consistent but I hope it doesn't break anything based on this, even though fault methods mostly throw exceptions for now.
96   *
97   * Revision 1.1  2001/11/13 04:13:59  mpowers
98   * Added interfaces needed to begin work on EOCustomObject.
99   *
100  */
101     
102