1 package org.csc.phynixx.common.cast;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class ImplementorWrapper<Y extends IImplementor> implements IImplementor {
31
32 private Y editable = null;
33
34 protected ImplementorWrapper(final Y editable) {
35 super();
36 this.editable = editable;
37 }
38
39 protected Y getWrapped() {
40 return this.editable;
41 }
42
43
44
45
46
47 public <X> X cast(final Class<X> iface) {
48 if (iface == null) {
49 throw new IllegalArgumentException("Parameter 'cls' muss angegeben werden");
50 }
51
52 final Class<?> clazz = this.getClass();
53 if (iface.isAssignableFrom(clazz)) {
54 return iface.cast(this);
55 } else {
56 if (this.editable == null) {
57 throw new IllegalStateException("Delegate ist nicht definiert");
58 }
59 return this.editable.cast(iface);
60 }
61 }
62
63 public <X> boolean isImplementationOf(final Class<X> cls) {
64 if (cls == null) {
65 throw new IllegalArgumentException(
66 "Parameter 'cls' muss angegeben werden");
67 }
68 if (cls.isAssignableFrom(this.getClass())) {
69 return true;
70 } else {
71 if (this.editable == null) {
72 throw new IllegalStateException("Delegate ist nicht definiert");
73 }
74 return this.editable.isImplementationOf(cls);
75 }
76 }
77
78 }