1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transformer.types; |
8 | |
|
9 | |
import org.mule.api.transformer.DataType; |
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
class ImmutableDataType<T> implements DataType<T> |
15 | |
{ |
16 | |
private DataType<T> theDataType; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
public ImmutableDataType(DataType<T> theDataType) |
22 | 0 | { |
23 | 0 | this.theDataType = theDataType; |
24 | 0 | } |
25 | |
|
26 | |
|
27 | |
|
28 | |
public Class<?> getType() |
29 | |
{ |
30 | 0 | return theDataType.getType(); |
31 | |
} |
32 | |
|
33 | |
public String getMimeType() |
34 | |
{ |
35 | 0 | return theDataType.getMimeType(); |
36 | |
} |
37 | |
|
38 | |
public String getEncoding() |
39 | |
{ |
40 | 0 | return theDataType.getEncoding(); |
41 | |
} |
42 | |
|
43 | |
public boolean isCompatibleWith(DataType dataType) |
44 | |
{ |
45 | 0 | return theDataType.isCompatibleWith(dataType); |
46 | |
} |
47 | |
|
48 | |
public DataType cloneDataType() |
49 | |
{ |
50 | 0 | return theDataType.cloneDataType(); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public String toString() |
55 | |
{ |
56 | 0 | return theDataType.toString(); |
57 | |
} |
58 | |
|
59 | |
|
60 | |
public void setEncoding(String encoding) |
61 | |
{ |
62 | 0 | attemptToMutate(); |
63 | 0 | } |
64 | |
|
65 | |
public void setMimeType(String mimeType) |
66 | |
{ |
67 | 0 | attemptToMutate(); |
68 | 0 | } |
69 | |
|
70 | |
protected DataType<T> getWrappedDataType() |
71 | |
{ |
72 | 0 | if (theDataType instanceof ImmutableDataType) |
73 | |
{ |
74 | 0 | return ((ImmutableDataType)theDataType).getWrappedDataType(); |
75 | |
} |
76 | |
else |
77 | |
{ |
78 | 0 | return theDataType; |
79 | |
} |
80 | |
} |
81 | |
|
82 | |
private void attemptToMutate() |
83 | |
{ |
84 | 0 | throw new UnsupportedOperationException("Attempt to change immutable DataType " + theDataType); |
85 | |
} |
86 | |
|
87 | |
@Override |
88 | |
public int hashCode() |
89 | |
{ |
90 | 0 | return theDataType.hashCode(); |
91 | |
} |
92 | |
} |