📄 ddffielddefinition.java
字号:
} return pszReturn; } /** * Given a string that contains a coded size symbol, expand it * out. */ protected String expandFormat(String pszSrc) { StringBuffer szDest = new StringBuffer(); int iSrc = 0; int nRepeat = 0; while (iSrc < pszSrc.length()) { /* * This is presumably an extra level of brackets around * some binary stuff related to rescaning which we don't * care to do (see 6.4.3.3 of the standard. We just strip * off the extra layer of brackets */ if ((iSrc == 0 || pszSrc.charAt(iSrc - 1) == ',') && pszSrc.charAt(iSrc) == '(') { String pszContents = extractSubstring(pszSrc + iSrc); String pszExpandedContents = expandFormat(pszContents); szDest.append(pszExpandedContents); iSrc = iSrc + pszContents.length() + 2; } else if ((iSrc == 0 || pszSrc.charAt(iSrc - 1) == ',') /* * this * is a * repeated * subclause */ && Character.isDigit(pszSrc.charAt(iSrc))) { int orig_iSrc = iSrc; // skip over repeat count. for (; Character.isDigit(pszSrc.charAt(iSrc)); iSrc++) { } String nRepeatString = pszSrc.substring(orig_iSrc, iSrc); nRepeat = Integer.parseInt(nRepeatString); String pszContents = extractSubstring(pszSrc.substring(iSrc)); String pszExpandedContents = expandFormat(pszContents); for (int i = 0; i < nRepeat; i++) { szDest.append(pszExpandedContents); if (i < nRepeat - 1) { szDest.append(","); } } if (iSrc == '(') { iSrc += pszContents.length() + 2; } else { iSrc += pszContents.length(); } } else { szDest.append(pszSrc.charAt(iSrc++)); } } return szDest.toString(); } /** * This method parses the format string partially, and then * applies a subfield format string to each subfield object. It in * turn does final parsing of the subfield formats. */ protected boolean applyFormats(String _formatControls) { String pszFormatList; Vector papszFormatItems; /* -------------------------------------------------------------------- */ /* Verify that the format string is contained within brackets. */ /* -------------------------------------------------------------------- */ if (_formatControls.length() < 2 || !_formatControls.startsWith("(") || !_formatControls.endsWith(")")) { Debug.error("DDFFieldDefinition: Format controls for " + pszTag + " field missing brackets {" + _formatControls + "} : length = " + _formatControls.length() + ", starts with {" + _formatControls.charAt(0) + "}, ends with {" + _formatControls.charAt(_formatControls.length() - 1) + "}"); return false; } /* -------------------------------------------------------------------- */ /* Duplicate the string, and strip off the brackets. */ /* -------------------------------------------------------------------- */ pszFormatList = expandFormat(_formatControls); if (Debug.debugging("iso8211")) { Debug.output("DDFFieldDefinition.applyFormats{" + _formatControls + "} expanded to {" + pszFormatList + "} "); } /* -------------------------------------------------------------------- */ /* Tokenize based on commas. */ /* -------------------------------------------------------------------- */ papszFormatItems = PropUtils.parseMarkers(pszFormatList, ","); /* -------------------------------------------------------------------- */ /* Apply the format items to subfields. */ /* -------------------------------------------------------------------- */ int iFormatItem = 0; for (Iterator it = papszFormatItems.iterator(); it.hasNext(); iFormatItem++) { String pszPastPrefix = (String) it.next(); int pppIndex = 0; // Skip over digits... for (; Character.isDigit(pszPastPrefix.charAt(pppIndex)); pppIndex++) { } pszPastPrefix = pszPastPrefix.substring(pppIndex); /////////////////////////////////////////////////////////////// // Did we get too many formats for the subfields created // by names? This may be legal by the 8211 specification, // but // isn't encountered in any formats we care about so we // just // blow. if (iFormatItem > paoSubfieldDefns.size()) { Debug.error("DDFFieldDefinition: Got more formats than subfields for field " + pszTag); break; } if (!((DDFSubfieldDefinition) paoSubfieldDefns.elementAt(iFormatItem)).setFormat(pszPastPrefix)) { Debug.output("DDFFieldDefinition had problem setting format for " + pszPastPrefix); return false; } } /* -------------------------------------------------------------------- */ /* Verify that we got enough formats, cleanup and return. */ /* -------------------------------------------------------------------- */ if (iFormatItem < paoSubfieldDefns.size()) { Debug.error("DDFFieldDefinition: Got fewer formats than subfields for field " + pszTag + " got (" + iFormatItem + ", should have " + paoSubfieldDefns.size() + ")"); return false; } /* -------------------------------------------------------------------- */ /* If all the fields are fixed width, then we are fixed width */ /* too. This is important for repeating fields. */ /* -------------------------------------------------------------------- */ nFixedWidth = 0; for (int i = 0; i < paoSubfieldDefns.size(); i++) { DDFSubfieldDefinition ddfsd = (DDFSubfieldDefinition) paoSubfieldDefns.elementAt(i); if (ddfsd.getWidth() == 0) { nFixedWidth = 0; break; } else { nFixedWidth += ddfsd.getWidth(); } } return true; } /** * Find a subfield definition by it's mnemonic tag. * * @param pszMnemonic The name of the field. * * @return The subfield pointer, or null if there isn't any such * subfield. */ public DDFSubfieldDefinition findSubfieldDefn(String pszMnemonic) { if (paoSubfieldDefns != null) { for (Iterator it = paoSubfieldDefns.iterator(); pszMnemonic != null && it.hasNext();) { DDFSubfieldDefinition ddfsd = (DDFSubfieldDefinition) it.next(); if (pszMnemonic.equalsIgnoreCase(ddfsd.getName())) { return ddfsd; } } } return null; } /** * Fetch a subfield by index. * * @param i The index subfield index. (Between 0 and * GetSubfieldCount()-1) * @return The subfield pointer, or null if the index is out of * range. */ public DDFSubfieldDefinition getSubfieldDefn(int i) { if (paoSubfieldDefns == null || i < 0 || i >= paoSubfieldDefns.size()) { return null; } return (DDFSubfieldDefinition) paoSubfieldDefns.elementAt(i); } public static class DataStructCode { public final static DataStructCode ELEMENTARY = new DataStructCode('0', "elementary"); public final static DataStructCode VECTOR = new DataStructCode('1', "vector"); public final static DataStructCode ARRAY = new DataStructCode('2', "array"); public final static DataStructCode CONCATENATED = new DataStructCode('3', "concatenated"); char code = '0'; String prettyName; public DataStructCode(char structCode, String name) { code = structCode; prettyName = name; } public char getCode() { return code; } public String toString() { return prettyName; } public static DataStructCode get(char c) { if (c == CONCATENATED.getCode()) return CONCATENATED; if (c == VECTOR.getCode()) return VECTOR; if (c == ARRAY.getCode()) return ARRAY; if (c == ELEMENTARY.getCode()) return ELEMENTARY; if (Debug.debugging("iso8211")) { Debug.output("DDFFieldDefinition tested for unknown code: " + c); } return ELEMENTARY; } } public static class DataTypeCode { public final static DataTypeCode CHAR_STRING = new DataTypeCode('0', "character string"); public final static DataTypeCode IMPLICIT_POINT = new DataTypeCode('1', "implicit point"); public final static DataTypeCode EXPLICIT_POINT = new DataTypeCode('2', "explicit point"); public final static DataTypeCode EXPLICIT_POINT_SCALED = new DataTypeCode('3', "explicit point scaled"); public final static DataTypeCode CHAR_BIT_STRING = new DataTypeCode('4', "character bit string"); public final static DataTypeCode BIT_STRING = new DataTypeCode('5', "bit string"); public final static DataTypeCode MIXED_DATA_TYPE = new DataTypeCode('6', "mixed data type"); char code = '0'; String prettyName; public DataTypeCode(char structCode, String desc) { code = structCode; prettyName = desc; } public char getCode() { return code; } public String toString() { return prettyName; } public static DataTypeCode get(char c) { if (c == IMPLICIT_POINT.getCode()) return IMPLICIT_POINT; if (c == EXPLICIT_POINT.getCode()) return EXPLICIT_POINT; if (c == EXPLICIT_POINT_SCALED.getCode()) return EXPLICIT_POINT_SCALED; if (c == CHAR_BIT_STRING.getCode()) return CHAR_BIT_STRING; if (c == BIT_STRING.getCode()) return BIT_STRING; if (c == MIXED_DATA_TYPE.getCode()) return MIXED_DATA_TYPE; if (c == CHAR_STRING.getCode()) return CHAR_STRING; if (Debug.debugging("iso8211")) { Debug.output("DDFFieldDefinition tested for unknown data type code: " + c); } return CHAR_STRING; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -