📄 ddffielddefinition.java
字号:
/****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ******************************************************************************/package com.bbn.openmap.dataAccess.iso8211;import com.bbn.openmap.layer.vpf.MutableInt;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import java.util.Iterator;import java.util.Vector;/** * Information from the DDR defining one field. Note that just because * a field is defined for a DDFModule doesn't mean that it actually * occurs on any records in the module. DDFFieldDefns are normally * just significant as containers of the DDFSubfieldDefinitions. */public class DDFFieldDefinition implements DDFConstants { protected DDFModule poModule; protected String pszTag; protected String _fieldName; protected String _arrayDescr; protected String _formatControls; protected boolean bRepeatingSubfields; protected int nFixedWidth; // zero if variable. protected DataStructCode _data_struct_code; protected DataTypeCode _data_type_code; protected Vector paoSubfieldDefns; /** * Fetch a pointer to the field name (tag). * * @return this is an internal copy and shouldn't be freed. */ public String getName() { return pszTag; } /** * Fetch a longer descriptio of this field. * * @return this is an internal copy and shouldn't be freed. */ public String getDescription() { return _fieldName; } /** * Get the number of subfields. */ public int getSubfieldCount() { if (paoSubfieldDefns != null) { return paoSubfieldDefns.size(); } return 0; } /** * Get the width of this field. This function isn't normally used * by applications. * * @return The width of the field in bytes, or zero if the field * is not apparently of a fixed width. */ public int getFixedWidth() { return nFixedWidth; } /** * Fetch repeating flag. * * @return true if the field is marked as repeating. */ public boolean isRepeating() { return bRepeatingSubfields; } /** this is just for an S-57 hack for swedish data */ public void setRepeating(boolean val) { bRepeatingSubfields = val; } /** ********************************************************************* */ /* DDFFieldDefn() */ /** ********************************************************************* */ public DDFFieldDefinition() { poModule = null; pszTag = null; _fieldName = null; _arrayDescr = null; _formatControls = null; paoSubfieldDefns = null; bRepeatingSubfields = false; } public DDFFieldDefinition(DDFModule poModuleIn, String pszTagIn, byte[] pachFieldArea) { initialize(poModuleIn, pszTagIn, pachFieldArea); } /** * Initialize the field definition from the information in the DDR * record. This is called by DDFModule.open(). * * @param poModuleIn DDFModule reprsenting file being read. * @param pszTagIn the name of this field. * @param pachFieldArea the data bytes in the file representing * the field from the header. */ public boolean initialize(DDFModule poModuleIn, String pszTagIn, byte[] pachFieldArea) { /// pachFieldArea needs to be specified better. It's an /// offset into a character array, and we need to know what // it /// is to scope it better in Java. int iFDOffset = poModuleIn._fieldControlLength; poModule = poModuleIn; pszTag = pszTagIn; /* -------------------------------------------------------------------- */ /* Set the data struct and type codes. */ /* -------------------------------------------------------------------- */ _data_struct_code = DataStructCode.get((char) pachFieldArea[0]); _data_type_code = DataTypeCode.get((char) pachFieldArea[1]); if (Debug.debugging("iso8211")) { Debug.output("DDFFieldDefinition.initialize(" + pszTagIn + "):\n\t\t data_struct_code = " + _data_struct_code + "\n\t\t data_type_code = " + _data_type_code + "\n\t\t iFDOffset = " + iFDOffset); } /* -------------------------------------------------------------------- */ /* Capture the field name, description (sub field names), and */ /* format statements. */ /* -------------------------------------------------------------------- */ byte[] tempData = new byte[pachFieldArea.length - iFDOffset]; System.arraycopy(pachFieldArea, iFDOffset, tempData, 0, pachFieldArea.length - iFDOffset); MutableInt nCharsConsumed = new MutableInt(); _fieldName = DDFUtils.fetchVariable(tempData, tempData.length, DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR, nCharsConsumed); if (Debug.debugging("iso8211")) { Debug.output("DDFFieldDefinition.initialize(" + pszTagIn + "): created field name " + _fieldName); } iFDOffset += nCharsConsumed.value; tempData = new byte[pachFieldArea.length - iFDOffset]; System.arraycopy(pachFieldArea, iFDOffset, tempData, 0, pachFieldArea.length - iFDOffset); _arrayDescr = DDFUtils.fetchVariable(tempData, tempData.length, DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR, nCharsConsumed); iFDOffset += nCharsConsumed.value; tempData = new byte[pachFieldArea.length - iFDOffset]; System.arraycopy(pachFieldArea, iFDOffset, tempData, 0, pachFieldArea.length - iFDOffset); _formatControls = DDFUtils.fetchVariable(tempData, tempData.length, DDF_UNIT_TERMINATOR, DDF_FIELD_TERMINATOR, nCharsConsumed); /* -------------------------------------------------------------------- */ /* Parse the subfield info. */ /* -------------------------------------------------------------------- */ if (_data_struct_code != DataStructCode.ELEMENTARY) { if (!buildSubfieldDefns(_arrayDescr)) { return false; } if (!applyFormats(_formatControls)) { return false; } } return true; } /** * Write out field definition info. * * A variety of information about this field definition, and all * its subfields are written out too. */ public String toString() { StringBuffer buf = new StringBuffer(" DDFFieldDefn:\n"); buf.append(" Tag = " + pszTag + "\n"); buf.append(" _fieldName = " + _fieldName + "\n"); buf.append(" _arrayDescr = " + _arrayDescr + "\n"); buf.append(" _formatControls = " + _formatControls + "\n"); buf.append(" _data_struct_code = " + _data_struct_code + "\n"); buf.append(" _data_type_code = " + _data_type_code + "\n"); if (paoSubfieldDefns != null) { for (Iterator it = paoSubfieldDefns.iterator(); it.hasNext();) { buf.append((DDFSubfieldDefinition) it.next()); } } return buf.toString(); } /** * Based on the list contained in the string, build a set of * subfield definitions. */ protected boolean buildSubfieldDefns(String pszSublist) { if (pszSublist.charAt(0) == '*') { bRepeatingSubfields = true; pszSublist = pszSublist.substring(1); } Vector papszSubfieldNames = PropUtils.parseMarkers(pszSublist, "!"); paoSubfieldDefns = new Vector(); for (Iterator it = papszSubfieldNames.iterator(); it.hasNext();) { DDFSubfieldDefinition ddfsd = new DDFSubfieldDefinition(); ddfsd.setName((String) it.next()); paoSubfieldDefns.add(ddfsd); } return true; } /** * Extract a substring terminated by a comma (or end of string). * Commas in brackets are ignored as terminated with bracket * nesting understood gracefully. If the returned string would * being and end with a bracket then strip off the brackets. * <P> * Given a string like "(A,3(B,C),D),X,Y)" return "A,3(B,C),D". * Give a string like "3A,2C" return "3A". */ protected String extractSubstring(String pszSrc) { int nBracket = 0; int i; String pszReturn; for (i = 0; i < pszSrc.length() && (nBracket > 0 || pszSrc.charAt(i) != ','); i++) { if (pszSrc.charAt(i) == '(') { nBracket++; } else if (pszSrc.charAt(i) == ')') { nBracket--; } } if (pszSrc.charAt(0) == '(') { pszReturn = pszSrc.substring(1, i - 2); } else { pszReturn = pszSrc.substring(0, i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -