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.impl; 12 13 import com.legstar.coxb.CobolElement; 14 import com.legstar.coxb.ICobolComplexBinding; 15 import com.legstar.coxb.ICobolZonedDecimalBinding; 16 import com.legstar.coxb.CobolElementVisitor; 17 import com.legstar.coxb.host.HostException; 18 19 /** 20 * This class implements the behavior of a zoned decimal cobol element bound to 21 * a JAXB BigDecimal property. 22 * 23 * @author Fady Moussallam 24 * 25 */ 26 public class CZonedDecimalBinding 27 extends AbstractNumericBinding 28 implements ICobolZonedDecimalBinding { 29 30 /** 31 * Constructor for a cobol element to java binding. 32 * 33 * @param name the identifier for this binding 34 * @param jaxbName the name of the bound java property 35 * @param jaxbType the type of the bound java property 36 * @param cobolAnnotations the cobol annotations for this element 37 * @param parentBinding a reference to the parent binding 38 */ 39 public CZonedDecimalBinding( 40 final String name, 41 final String jaxbName, 42 final Class < ? > jaxbType, 43 final CobolElement cobolAnnotations, 44 final ICobolComplexBinding parentBinding) { 45 super(name, jaxbName, jaxbType, cobolAnnotations, parentBinding); 46 } 47 48 /** {@inheritDoc} */ 49 public void accept(final CobolElementVisitor cev) 50 throws HostException { 51 cev.visit(this); 52 } 53 54 /** {@inheritDoc} */ 55 public int calcByteLength() { 56 return calcZonedDecimalByteLength(getTotalDigits(), isSignSeparate()); 57 } 58 59 /** 60 * Calculates the host byte length for a S9(n)V(m) DISPLAY. 61 * Every digit is encoded in one byte. Decimal sign is virtual and does 62 * not occupy a byte. The sign shares the last digit byte unless it is 63 * separate. 64 * @param totalDigits the number of digits (including fraction digits) 65 * @param isSignSeparate true if sign is separate 66 * @return the host byte length for a zoned decimal 67 */ 68 public static int calcZonedDecimalByteLength( 69 final int totalDigits, final boolean isSignSeparate) { 70 return (isSignSeparate) ? totalDigits + 1 : totalDigits; 71 } 72 }