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.ICobolNationalBinding; 16 import com.legstar.coxb.CobolElementVisitor; 17 import com.legstar.coxb.host.HostException; 18 import com.legstar.coxb.util.PictureUtil; 19 20 /** 21 * This class implements the behavior of a national cobol element bound to 22 * a JAXB String property. 23 * 24 * @author Fady Moussallam 25 * 26 */ 27 public class CNationalBinding extends AbstractAlphaNumericBinding 28 implements ICobolNationalBinding { 29 30 /** 31 * Constructor for a cobol element to java binding. 32 * 33 * @param bindingName 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 CNationalBinding( 40 final String bindingName, 41 final String jaxbName, 42 final Class < ? > jaxbType, 43 final CobolElement cobolAnnotations, 44 final ICobolComplexBinding parentBinding) { 45 super(bindingName, 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 calcNationalByteLength(getPicture()); 57 } 58 59 /** 60 * Calculates the host byte length for a PIC N(n). 61 * @param picture the picture clause 62 * @return the host byte length for a PIC N(n) 63 */ 64 public static int calcNationalByteLength(final String picture) { 65 return 2 * PictureUtil.getSymbolsNumber('N', picture); 66 } 67 68 }