01: /*
02: * Created on 29.07.2005
03: *
04: * To change the template for this generated file go to
05: * Window - Preferences - Java - Code Generation - Code and Comments
06: */
07: package de.schlund.pfixcore.webservice.fault;
08:
09: import java.io.Serializable;
10: import java.util.HashMap;
11: import java.util.Iterator;
12:
13: public abstract class FaultHandler implements Serializable {
14:
15: HashMap<String, String> params = new HashMap<String, String>();
16:
17: protected FaultHandler() {
18: }
19:
20: public void addParam(String name, String value) {
21: params.put(name, value);
22: }
23:
24: public void setParams(HashMap<String, String> params) {
25: this .params = params;
26: }
27:
28: public HashMap<String, String> getParams() {
29: return params;
30: }
31:
32: public String getParam(String name) {
33: if (params == null)
34: return null;
35: return params.get(name);
36: }
37:
38: public String paramsToString() {
39: if (params == null)
40: return "[]";
41: else {
42: StringBuffer sb = new StringBuffer();
43: sb.append("[");
44: Iterator<String> it = params.keySet().iterator();
45: while (it.hasNext()) {
46: String key = it.next();
47: String val = params.get(key);
48: sb.append("(" + key + "=" + val + ")");
49: }
50: sb.append("]");
51: return sb.toString();
52: }
53: }
54:
55: public abstract void init();
56:
57: public abstract void handleFault(Fault fault);
58:
59: @Override
60: public boolean equals(Object obj) {
61: if (obj instanceof FaultHandler) {
62: FaultHandler ref = (FaultHandler) obj;
63: if (!getClass().equals(ref.getClass()))
64: return false;
65: if (params == null ^ ref.getParams() == null)
66: return false;
67: Iterator<String> it = params.keySet().iterator();
68: while (it.hasNext()) {
69: String name = it.next();
70: String val = params.get(name);
71: String refVal = ref.getParam(name);
72: if (refVal == null || !(val.equals(refVal)))
73: return false;
74: }
75: it = ref.getParams().keySet().iterator();
76: while (it.hasNext()) {
77: String name = it.next();
78: String val = params.get(name);
79: if (val == null)
80: return false;
81: }
82: return true;
83: }
84: return false;
85: }
86:
87: }
|