Class AbstractParser
- All Implemented Interfaces:
Parser
- Direct Known Subclasses:
MathTransformParser
Formatter.
Like the latter, a parser is constructed with a given set of symbols.
Parsers also need a set of factories to be used for instantiating the parsed objects.
In current version, parsers are not intended to be subclassed outside this package.
Parsers are not synchronized. It is recommended to create separate parser instances for each thread. If many threads access the same parser instance concurrently, it must be synchronized externally.
- Since:
- 0.6
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DateFormatThe object to use for parsing dates, created when first needed.(package private) final LocaleThe locale for formatting error messages if parsing fails, ornullfor system default.private final StringThe symbol for scientific notation, ornullif none.(package private) static final intA mode for theElement.pullElement(int, String...)method meaning that only the first element should be checked.(package private) final Map<String,StoredTree> Reference to theWKTFormat.fragmentsmap, or an empty map if none.Keyword of unknown elements.(package private) static final intA mode for theElement.pullElement(int, String...)method meaning that an exception shall be thrown if no element has a name matching one of the requested names.private final NumberFormatThe object to use for parsing numbers.(package private) static final intA mode for theElement.pullElement(int, String...)method meaning that the requested element is optional but not necessarily first.(package private) final SymbolsThe symbols to use for parsing WKT.private UnitFormatThe object to use for parsing unit symbols, created when first needed.private WarningsThe warning (other thanignoredElements) that occurred during the parsing. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractParser(Symbols symbols, Map<String, StoredTree> fragments, NumberFormat numberFormat, DateFormat dateFormat, UnitFormat unitFormat, Locale errorLocale) Constructs a parser using the specified set of symbols. -
Method Summary
Modifier and TypeMethodDescription(package private) abstract ObjectbuildFromTree(Element element) Parses the next element in the specified Well Know Text (WKT) tree.final ObjectcreateFromWKT(String wkt) Creates the object from a WKT string and logs the warnings if any.(package private) ObjectcreateFromWKT(String text, ParsePosition position) Parses a Well-Know Text from specified position as a geodetic object.(package private) static intendOfFragmentName(String text, int position) Returns the index after the end of the fragment name starting at the given index.(package private) final WarningsgetAndClearWarnings(Object result) Returns the warnings, ornullif none.(package private) StringReturns the name of the method invoked fromgetPublicFacade().(package private) abstract StringReturns the name of the class providing the publicly-accessiblecreateFromWKT(String)method.(package private) final voidLogs the given record for a warning that occurred during parsing.(package private) final DateparseDate(String text, ParsePosition position) Parses the date at the given position.(package private) final NumberparseNumber(String text, ParsePosition position) Parses the number at the given position.(package private) final javax.measure.Unit<?>Parses the given unit name or symbol.(package private) final ElementtextToTree(String wkt, ParsePosition position) Parses the Well Know Text from specified position as a tree ofElements.(package private) final voidReports a non-fatal warning that occurred while parsing a WKT.(package private) final voidwarning(Element parent, Element element, org.opengis.util.InternationalString message, Exception ex) Reports a non-fatal warning that occurred while parsing a WKT.
-
Field Details
-
FIRST
static final int FIRSTA mode for theElement.pullElement(int, String...)method meaning that only the first element should be checked. If the name of the first element does not match one of the specified names, thenpullElement(…)returnsnull.- See Also:
-
OPTIONAL
static final int OPTIONALA mode for theElement.pullElement(int, String...)method meaning that the requested element is optional but not necessarily first. If no element has a name matching one of the requested names, thenpullElement(…)returnsnull.- See Also:
-
MANDATORY
static final int MANDATORYA mode for theElement.pullElement(int, String...)method meaning that an exception shall be thrown if no element has a name matching one of the requested names.- See Also:
-
errorLocale
The locale for formatting error messages if parsing fails, ornullfor system default. This is not the locale for parsing number or date values. The locale for numbers and dates is contained insymbols. -
symbols
The symbols to use for parsing WKT. -
exponentSymbol
The symbol for scientific notation, ornullif none. This is usually"E"(note the upper case), but could also be something like"×10^". -
numberFormat
The object to use for parsing numbers. -
dateFormat
The object to use for parsing dates, created when first needed. -
unitFormat
The object to use for parsing unit symbols, created when first needed. -
fragments
Reference to theWKTFormat.fragmentsmap, or an empty map if none. Shall be used in read-only mode; never write through this reference. -
ignoredElements
Keyword of unknown elements. The ISO 19162 specification requires that we ignore unknown elements, but we will nevertheless report them as warnings. The meaning of this map is:- Keys: keyword of ignored elements. Note that a key may be null.
- Values: keywords of all elements containing an element identified by the above-cited key. This list is used for helping the users to locate the ignored elements.
Warningswill copy its content only when first needed.- See Also:
-
warnings
The warning (other thanignoredElements) that occurred during the parsing. Created when first needed and reset tonullwhen a new parsing start. Warnings are reported whengetAndClearWarnings(Object)is invoked.
-
-
Constructor Details
-
AbstractParser
AbstractParser(Symbols symbols, Map<String, StoredTree> fragments, NumberFormat numberFormat, DateFormat dateFormat, UnitFormat unitFormat, Locale errorLocale) Constructs a parser using the specified set of symbols.- Parameters:
symbols- the set of symbols to use.fragments- reference to theWKTFormat.fragmentsmap, or an empty map if none.numberFormat- the number format provided byWKTFormat, ornullfor a default format.dateFormat- the date format provided byWKTFormat, ornullfor a default format.unitFormat- the unit format provided byWKTFormat, ornullfor a default format.errorLocale- the locale for error messages (not for parsing), ornullfor the system default.
-
-
Method Details
-
getPublicFacade
Returns the name of the class providing the publicly-accessiblecreateFromWKT(String)method. This information is used for logging purposes only. Values can be:"org.apache.sis.io.wkt.WKTFormat""org.apache.sis.referencing.factory.GeodeticObjectFactory""org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory"
-
getFacadeMethod
String getFacadeMethod()Returns the name of the method invoked fromgetPublicFacade(). This information is used for logging purposes only. Another possible value is"parse". -
log
Logs the given record for a warning that occurred during parsing. This is used when we cannot use thewarning methods, or when the information is not worth to report as a warning. -
createFromWKT
Creates the object from a WKT string and logs the warnings if any. This method is for implementation ofcreateFromWKT(String)method in SIS factories only. Callers should ensure thatwktis non-null and non-empty (this method does not verify).- Specified by:
createFromWKTin interfaceParser- Parameters:
wkt- object encoded in Well-Known Text format (version 1 or 2).- Returns:
- the result of parsing the given text.
- Throws:
org.opengis.util.FactoryException- if the object creation failed.- See Also:
-
createFromWKT
Parses a Well-Know Text from specified position as a geodetic object. Caller should invokegetAndClearWarnings(Object)in afinallyblock after this method and should decide what to do with remaining character at the end of the string.If this method is invoked from
WKTFormat, thenWKTFormat.clear()should be invoked before this method for making sure that noWarningsinstance is referencingignoredElements.- Parameters:
text- the Well-Known Text (WKT) to parse.position- index of the first character to parse (on input) or after last parsed character (on output).- Returns:
- the parsed object.
- Throws:
ParseException- if the string cannot be parsed.
-
endOfFragmentName
Returns the index after the end of the fragment name starting at the given index. Current implementation assumes that the fragment name is a Unicode identifier, except for the first character which is not required to be an identifier start. -
textToTree
Parses the Well Know Text from specified position as a tree ofElements. This tree can be given tobuildFromTree(Element)for producing a geodetic object.- Parameters:
wkt- the Well-Known Text to be parsed.position- before parsing, provides index of the first character to parse in thewktstring. After parsing completion, provides index after the last character parsed.- Returns:
- the parsed object as a tree of
Elements. - Throws:
ParseException- if the string cannot be parsed.- See Also:
-
buildFromTree
Parses the next element in the specified Well Know Text (WKT) tree. Subclasses will typically get the name of the first element and delegate to a specialized method such asparseAxis(…),parseEllipsoid(…),parseTimeDatum(…), etc.Callers should clear
ignoredElementsbefore to invoke this method. Cleaningwarningscan be done for safety but should not be necessary.- Parameters:
element- the element to be parsed.- Returns:
- the parsed object.
- Throws:
ParseException- if the element cannot be parsed.
-
parseNumber
Parses the number at the given position. This is a helper method forElementonly. -
parseDate
Parses the date at the given position. This is a helper method forElementonly.The WKT 2 format expects dates formatted according the ISO 9075-2 standard.
-
parseUnit
Parses the given unit name or symbol. Contrarily to otherparseFoo()methods, this method has noParsePositionand expects the given string to be the full unit symbol.- Throws:
javax.measure.format.ParserException
-
warning
final void warning(Element parent, Element element, org.opengis.util.InternationalString message, Exception ex) Reports a non-fatal warning that occurred while parsing a WKT.- Parameters:
parent- the parent element, ornullif unknown.element- the element that we cannot parse, ornullif unknown.message- the message. Can benullonly ifexis non-null.ex- the non-fatal exception that occurred while parsing the element, ornull.
-
warning
final void warning(Element parent, String element, org.opengis.util.InternationalString message, Exception ex) Reports a non-fatal warning that occurred while parsing a WKT.- Parameters:
parent- the parent element, ornullif unknown.element- the name of the element that we cannot parse, ornullif unknown.message- the message. Can benullonly ifexis non-null.ex- the non-fatal exception that occurred while parsing the element, ornull.
-
getAndClearWarnings
Returns the warnings, ornullif none. This method clears the warnings after the call.The returned object is valid only until a new parsing starts. If a longer lifetime is desired, then the caller must invokes
Warnings.publish().- Parameters:
result- the object that resulted from the parsing operation, ornull.- Returns:
- the warnings, or
nullif none.
-