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  package it.imolinfo.jbi4cics.commareaparser;
11  
12  import it.imolinfo.jbi4cics.exception.ParseException;
13  import it.imolinfo.jbi4cics.typemapping.cobol.CobolType;
14  import it.imolinfo.jbi4cics.typemapping.cobol.CobolTypeDescriptor;
15  
16  /**
17   * this class is required by the parser and is used to store information about
18   * the picure part of cobol tipe definition.
19   *
20   * @author raffaele
21   */
22  public class PictureDefinition {
23  
24    /**
25     * the constant NUMERIC means that cobol type is numeric.
26     */
27    public static final int NUMERIC = 0;
28  
29    /**
30     * the constant STRING means that cobol type is a string.
31     */
32    public static final int STRING = 1;
33  
34    /**
35     * the type of this PictureDefinition.
36     * Possible type are @see NUMERIC and @see STRING
37     */
38    private int type;
39  
40    /**
41     * the string length in case of string.
42     */
43    private int stringLength;
44  
45    /**
46     * the integer part length in case of numeric.
47     */
48    private int integerLength;
49  
50    /**
51     * the decimal part length in case of numeric decimal.
52     */
53    private int decimalLength;
54  
55    private boolean signed;
56  
57    private boolean signPlus;
58  
59    public PictureDefinition() {
60    }
61  
62    /**
63     * @return Returns the decimalLength.
64     */
65    public int getDecimalLength() {
66      return decimalLength;
67    }
68  
69    /**
70     * @param decimalLength
71     *          The decimalLength to set.
72     */
73    public void setDecimalLength(int decimalLength) {
74      this.decimalLength = decimalLength;
75    }
76  
77    /**
78     * @return Returns the integerLength.
79     */
80    public int getIntegerLength() {
81      return integerLength;
82    }
83  
84    /**
85     * @param integerLength
86     *          The integerLength to set.
87     */
88    public void setIntegerLength(int integerLength) {
89      this.integerLength = integerLength;
90    }
91  
92    /**
93     * @return Returns the stringLength.
94     */
95    public int getStringLength() {
96      return stringLength;
97    }
98  
99    /**
100    * @param stringLength
101    *          The stringLength to set.
102    */
103   public void setStringLength(int stringLength) {
104     this.stringLength = stringLength;
105   }
106 
107   /**
108    * @return Returns the type.
109    */
110   public int getType() {
111     return type;
112   }
113 
114   /**
115    * @param type
116    *          The type to set.
117    */
118   public final void setType(final int type) {
119     this.type = type;
120   }
121 
122   public void populate(CobolTypeDescriptor cobolTypeDescriptor)
123           throws ParseException {
124     switch (type) {
125       case NUMERIC:
126         cobolTypeDescriptor.setType(CobolType.ZONED);
127         cobolTypeDescriptor.setDecimalPartLength(decimalLength);
128         cobolTypeDescriptor.setIntegerPartLength(integerLength);
129         cobolTypeDescriptor.setSigned(signed);
130         if (signPlus) {
131           cobolTypeDescriptor.setZonedSignFormat(
132                   CobolTypeDescriptor.SIGN_FORMAT_LEADING_SEPARATE);
133         }
134         break;
135 
136       case STRING:
137         cobolTypeDescriptor.setType(CobolType.STRING);
138         cobolTypeDescriptor.setStringLength(stringLength);
139         cobolTypeDescriptor.setPadCharacter(" ");
140         cobolTypeDescriptor.setJustification(
141                 CobolTypeDescriptor.STRING_JUSTIFICATION_LEFT);
142         break;
143 
144       default:
145         throw new ParseException("CIC000002_Unrecognized_type",
146                 new Object[] {type});
147     }
148   }
149 
150   /**
151    * @return Returns the signed.
152    */
153   public boolean isSigned() {
154     return signed;
155   }
156 
157   /**
158    * @param signed
159    *          The signed to set.
160    */
161   public void setSigned(boolean signed) {
162     this.signed = signed;
163   }
164 
165   /**
166    * @return Returns the signPlus.
167    */
168   public boolean isSignPlus() {
169     return signPlus;
170   }
171 
172   /**
173    * @param signPlus
174    *          The signPlus to set.
175    */
176   public void setSignPlus(boolean signPlus) {
177     this.signPlus = signPlus;
178   }
179 }