All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.databene.edifatto.EdiFormatSymbols Maven / Gradle / Ivy

Go to download

'Edifatto' is an open source software library for parsing, generating and verifying EDIFACT and X12 documents written by Volker Bergmann.

The newest version!
/*
 * Copyright (C) 2013-2015 Volker Bergmann ([email protected]).
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.databene.edifatto;

import java.io.Serializable;

import org.databene.commons.Assert;

/**
 * Provides separator symbols for EDIFACT and X12 parsing and formatting.
 * Created: 14.10.2013 14:59:08
 * @since 1.0
 * @author Volker Bergmann
 */

public class EdiFormatSymbols implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private static final char DEFAULT_DECIMAL_NOTATION = '.';
	private static final char DEFAULT_ESCAPE_CHAR = '?';
	
	private static final char EDIFACT_COMPONENT_SEPARATOR = ':';
	private static final char EDIFACT_ELEMENT_SEPARATOR   = '+';
	private static final char EDIFACT_SEGMENT_SEPARATOR   = '\'';
	
	private static final char X12_SEGMENT_SEPARATOR   = '~';
	private static final char X12_ELEMENT_SEPARATOR   = '*';
	private static final char X12_COMPONENT_SEPARATOR = '>';
	
	public static final EdiFormatSymbols EDIFACT = new EdiFormatSymbols(
			EDIFACT_COMPONENT_SEPARATOR, 
			EDIFACT_ELEMENT_SEPARATOR, 
			DEFAULT_DECIMAL_NOTATION,
			DEFAULT_ESCAPE_CHAR,
			' ',
			EDIFACT_SEGMENT_SEPARATOR);
	
	public static final EdiFormatSymbols X12 = new EdiFormatSymbols(
			X12_COMPONENT_SEPARATOR, 
			X12_ELEMENT_SEPARATOR, 
			DEFAULT_DECIMAL_NOTATION, 
			DEFAULT_ESCAPE_CHAR,
			' ', 
			X12_SEGMENT_SEPARATOR);
	
	public final char componentSeparator;
	public final char elementSeparator;
	public final char decimalNotation;
	public final char escapeChar;
	public final char reserved;
	public final char segmentSeparator;
	
	public EdiFormatSymbols(char componentSeparator, char elementSeparator, char decimalNotation, char escapeChar, 
			char reserved, char segmentSeparator) {
		this.componentSeparator = componentSeparator;
		this.elementSeparator = elementSeparator;
		this.decimalNotation = decimalNotation;
		this.escapeChar = escapeChar;
		this.reserved = reserved;
		this.segmentSeparator = segmentSeparator;
	}
	
	@Override
	public String toString() {
		return "" + componentSeparator + elementSeparator + decimalNotation + escapeChar + reserved + segmentSeparator;
	}
	
	public static EdiFormatSymbols valueOf(String spec) {
		Assert.notNull(spec, "Edifact format specification");
		Assert.length(spec, 6);
		return new EdiFormatSymbols(spec.charAt(0), spec.charAt(1), spec.charAt(2), 
				spec.charAt(3), spec.charAt(4), spec.charAt(5));
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy