View Javadoc

1   /*
2    * $Id: DataType.java 22391 2011-07-12 12:00:48Z dirk.olmes $
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  package org.mule.api.transformer;
11  
12  import org.mule.transformer.types.DataTypeFactory;
13  
14  import java.io.Serializable;
15  
16  /**
17   * Defines a Java type associated with additional information about the data.  This may be a mime 
18   * type for the type or for collections, the collection item type can be stored with the collection 
19   * type.
20   *
21   * @since 3.0.0
22   */
23  public interface DataType<T> extends Serializable, Cloneable
24  {
25      public static final String ANY_MIME_TYPE = "*/*";
26  
27      /**
28       * The object type of the source object to transform.
29       *
30       * @return the class object of the source object. This must not be null
31       */
32      Class<?> getType();
33  
34      /**
35       * The mime type of the the source object to transform.
36       *
37       * @return the mime type of the source object. This may be null if the mime type is not known, or if the mime type is
38       *         not needed
39       */
40      String getMimeType();
41  
42      /**
43       * The encoding for the object to transform
44       */
45      String getEncoding();
46  
47      /**
48       * The encoding for the object to transform
49       */
50      void setEncoding(String encoding);
51  
52      /**
53       * The mime type of the the source object to transform.
54       *
55       * @param mimeType the mime type of the source object. This may be null if the mime type is not known, or if the mime type is
56       *                 not needed
57       */
58      void setMimeType(String mimeType);
59  
60      /**
61       * Used to determine if this data type is compatible with the data type passed in.  This checks to see if the mime types are
62       * equal and whether the Java types are assignable
63       *
64       * @param dataType the dataType object to compare with
65       * @return true if the mime types are the same and this type can be assigned to the dataType.type.
66       */
67      boolean isCompatibleWith(DataType dataType);
68  
69      /**
70       * Create an exact copy of this datatype
71       */
72      DataType cloneDataType();
73  
74      DataType<byte[]> BYTE_ARRAY_DATA_TYPE = DataTypeFactory.createImmutable(byte[].class);
75  
76      DataType<String> STRING_DATA_TYPE = DataTypeFactory.createImmutable(String.class);
77  }