View Javadoc

1   /*
2    * $Id: DataTypeConverter.java 19026 2010-08-16 07:30:47Z 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.module.ibeans.spi.support;
11  
12  import org.mule.api.transformer.DataType;
13  import org.mule.transformer.types.CollectionDataType;
14  import org.mule.transformer.types.DataTypeFactory;
15  
16  import javax.activation.MimeTypeParseException;
17  
18  import org.ibeans.api.channel.MimeType;
19  
20  /**
21   * Both Mule and iBeans define a DataType model for associating Java types with other info such as mime type and encoding
22   * This classes provides a couple of functions to convert between the two models
23   */
24  public class DataTypeConverter
25  {
26      public static org.ibeans.api.DataType convertMuleToIBeans(DataType muleDT) throws MimeTypeParseException
27      {
28      //Both Mule and iBeans have DataType implementations, need to wrap the Mule DataType to work with iBeans
29          if(muleDT instanceof CollectionDataType)
30          {
31              CollectionDataType dt = (CollectionDataType)muleDT;
32              return org.ibeans.impl.support.datatype.DataTypeFactory.create(dt.getType(), dt.getItemType(), new MimeType(dt.getMimeType()));
33          }
34          else
35          {
36              return org.ibeans.impl.support.datatype.DataTypeFactory.create(muleDT.getType(), new MimeType(muleDT.getMimeType()));
37          }
38  
39      }
40  
41      public static DataType convertIBeansToMule(org.ibeans.api.DataType ibeansDT) throws MimeTypeParseException
42      {
43      //Both Mule and iBeans have DataType implementations, need to wrap the Mule DataType to work with iBeans
44          if(ibeansDT instanceof org.ibeans.impl.support.datatype.CollectionDataType)
45          {
46              org.ibeans.impl.support.datatype.CollectionDataType dt = (org.ibeans.impl.support.datatype.CollectionDataType)ibeansDT;
47              return DataTypeFactory.create(dt.getType(), dt.getItemType(), dt.getMimeType());
48          }
49          else
50          {
51              return DataTypeFactory.create(ibeansDT.getType(), ibeansDT.getMimeType());
52          }
53  
54      }
55  }