View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2015 LegSem.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the GNU Lesser Public License v2.1
5    * which accompanies this distribution, and is available at
6    * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
7    * 
8    * Contributors:
9    *     LegSem - initial API and implementation
10   ******************************************************************************/
11  package com.legstar.coxb.convert.simple;
12  
13  import com.legstar.coxb.CobolContext;
14  import com.legstar.coxb.ICobolBinding;
15  import com.legstar.coxb.convert.CobolConversionException;
16  import com.legstar.coxb.host.HostException;
17  
18  /**
19   * An abstract class representing simple cobol version methods.
20   *
21   * @author Fady Moussallam
22   * 
23   */
24  public abstract class CobolSimpleConverter {
25  
26      /** Cobol compiler parameters. */
27      private CobolContext mCobolContext;
28  
29      /**
30       * @param cobolContext the Cobol compiler parameters in effect
31       */
32      public CobolSimpleConverter(final CobolContext cobolContext) {
33          mCobolContext = cobolContext;
34      }
35  
36      /**
37       * @return Returns the CobolContext.
38       */
39      public CobolContext getCobolContext() {
40          return mCobolContext;
41      }
42  
43      /**
44       * @param cobolContext The CobolContext to set.
45       */
46      public void setCobolContext(final CobolContext cobolContext) {
47          mCobolContext = cobolContext;
48      }
49  
50      /**
51       * Formats a meaningful error message to help track conversion errors.
52       * @param ce the faulty binding element 
53       * @param e the conversion exception
54       * @throws HostException the resulting host exception
55       */
56      public void throwHostException(
57              final ICobolBinding ce, 
58              final CobolConversionException e)
59      throws HostException {
60          throw (new HostException("ConversionException for element:"
61                  + ce.getBindingName()
62                  + " Cobol name:" + ce.getCobolName()
63                  + " Reason:" + e.getMessage()));
64  
65      }
66  }