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