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  
  * $Id: ImmutableDataType.java 20582 2010-12-09 23:13:19Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transformer.types;
 12  
 
 13  
 import org.mule.api.transformer.DataType;
 14  
 
 15  
 /** A wrapper for a datatype that ensures it cannot be changed.  Get a non-immutable version by calling
 16  
  * cloneDataType().
 17  
   */
 18  
 class ImmutableDataType<T> implements DataType<T>
 19  
 {
 20  
     private DataType<T> theDataType;
 21  
 
 22  
     /**
 23  
      * Wrap a DataType with immutability.
 24  
      */
 25  
     public ImmutableDataType(DataType<T> theDataType)
 26  0
     {
 27  0
         this.theDataType = theDataType;
 28  0
     }
 29  
 
 30  
 
 31  
     // These simply delegate
 32  
     public Class<?> getType()
 33  
     {
 34  0
         return theDataType.getType();
 35  
     }
 36  
 
 37  
     public String getMimeType()
 38  
     {
 39  0
         return theDataType.getMimeType();
 40  
     }
 41  
 
 42  
     public String getEncoding()
 43  
     {
 44  0
         return theDataType.getEncoding();
 45  
     }
 46  
 
 47  
     public boolean isCompatibleWith(DataType dataType)
 48  
     {
 49  0
         return theDataType.isCompatibleWith(dataType);
 50  
     }
 51  
 
 52  
     public DataType cloneDataType()
 53  
     {
 54  0
         return theDataType.cloneDataType();
 55  
     }
 56  
 
 57  
     @Override
 58  
     public String toString()
 59  
     {
 60  0
         return theDataType.toString();    
 61  
     }
 62  
 
 63  
     // These are illegal
 64  
     public void setEncoding(String encoding)
 65  
     {
 66  0
         attemptToMutate();
 67  0
     }
 68  
 
 69  
     public void setMimeType(String mimeType)
 70  
     {
 71  0
         attemptToMutate();
 72  0
     }
 73  
 
 74  
     protected DataType<T> getWrappedDataType()
 75  
     {
 76  0
         if (theDataType instanceof ImmutableDataType)
 77  
         {
 78  0
             return ((ImmutableDataType)theDataType).getWrappedDataType();
 79  
         }
 80  
         else
 81  
         {
 82  0
             return theDataType;
 83  
         }
 84  
     }
 85  
 
 86  
     private void attemptToMutate()
 87  
     {
 88  0
         throw new UnsupportedOperationException("Attempt to change immutable DataType " + theDataType);
 89  
     }
 90  
     
 91  
     @Override
 92  
     public int hashCode()
 93  
     {
 94  0
         return theDataType.hashCode();
 95  
     }
 96  
 }