Coverage Report - org.mule.transformer.types.ImmutableDataType
 
Classes in this File Line Coverage Branch Coverage Complexity
ImmutableDataType
0%
0/18
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transformer.types;
 8  
 
 9  
 import org.mule.api.transformer.DataType;
 10  
 
 11  
 /** A wrapper for a datatype that ensures it cannot be changed.  Get a non-immutable version by calling
 12  
  * cloneDataType().
 13  
   */
 14  
 class ImmutableDataType<T> implements DataType<T>
 15  
 {
 16  
     private DataType<T> theDataType;
 17  
 
 18  
     /**
 19  
      * Wrap a DataType with immutability.
 20  
      */
 21  
     public ImmutableDataType(DataType<T> theDataType)
 22  0
     {
 23  0
         this.theDataType = theDataType;
 24  0
     }
 25  
 
 26  
 
 27  
     // These simply delegate
 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  
     // These are illegal
 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  
 }