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 {
23 this.theDataType = theDataType;
24 }
25
26
27
28 public Class<?> getType()
29 {
30 return theDataType.getType();
31 }
32
33 public String getMimeType()
34 {
35 return theDataType.getMimeType();
36 }
37
38 public String getEncoding()
39 {
40 return theDataType.getEncoding();
41 }
42
43 public boolean isCompatibleWith(DataType dataType)
44 {
45 return theDataType.isCompatibleWith(dataType);
46 }
47
48 public DataType cloneDataType()
49 {
50 return theDataType.cloneDataType();
51 }
52
53 @Override
54 public String toString()
55 {
56 return theDataType.toString();
57 }
58
59
60 public void setEncoding(String encoding)
61 {
62 attemptToMutate();
63 }
64
65 public void setMimeType(String mimeType)
66 {
67 attemptToMutate();
68 }
69
70 protected DataType<T> getWrappedDataType()
71 {
72 if (theDataType instanceof ImmutableDataType)
73 {
74 return ((ImmutableDataType)theDataType).getWrappedDataType();
75 }
76 else
77 {
78 return theDataType;
79 }
80 }
81
82 private void attemptToMutate()
83 {
84 throw new UnsupportedOperationException("Attempt to change immutable DataType " + theDataType);
85 }
86
87 @Override
88 public int hashCode()
89 {
90 return theDataType.hashCode();
91 }
92 }