View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   /**
9    * 
10   */
11  package it.imolinfo.jbi4cics.messageformat;
12  
13  import it.imolinfo.jbi4cics.messageformat.commarea.CommareaBeanMappingDescriptor;
14  import it.imolinfo.jbi4cics.messageformat.commarea.CommareaFormatter;
15  import it.imolinfo.jbi4cics.messageformat.jdbc.JdbcBeanMappingDescriptor;
16  import it.imolinfo.jbi4cics.messageformat.jdbc.JdbcFormatter;
17  import it.imolinfo.jbi4cics.messageformat.jdbc.JdbcStatementDescriptor;
18  import it.imolinfo.jbi4cics.service.ServiceContext;
19  
20  /**
21   * @author raffaele
22   *
23   */
24  public class MessageFormatterFactory {
25    private static CommareaFormatter commareaFormatter=new CommareaFormatter();
26    private static JdbcFormatter jdbcFormatter=new JdbcFormatter();
27    private static ToStringMessageFormatter toStringMessageFormatter=new ToStringMessageFormatter();
28    private static NoOpMessageFormatter noOpMessageFormatter=new NoOpMessageFormatter();
29    
30    /**
31     * void constructor.
32     */
33      public MessageFormatterFactory(){
34      }
35    
36  	public static MessageFormatter createMessageFormatter(ServiceContext serviceContext, boolean input){
37      MappingDescriptor mappingDescriptor=null;
38      if (input) {
39        mappingDescriptor=serviceContext.getInputMappingDescriptor();
40      }
41      else {
42        mappingDescriptor=serviceContext.getOutputMappingDescriptor();
43      }
44      if (mappingDescriptor instanceof CommareaBeanMappingDescriptor) {
45        return commareaFormatter;
46      }
47      if (mappingDescriptor instanceof JdbcBeanMappingDescriptor) {
48        return jdbcFormatter;
49      }
50      if (mappingDescriptor instanceof JdbcStatementDescriptor) {
51        return jdbcFormatter;
52      }
53      if (mappingDescriptor instanceof NoOpMappingDescriptor) {
54        return noOpMessageFormatter;
55      }    
56  		return toStringMessageFormatter;
57  	}
58  }