public final class SentenceFactory extends Object
Custom parsers may be implemented and registered in factory as follows:
Sentence
interface
(e.g. com.acme.XYZSentence
).SentenceParser
,
(e.g. com.acme.XYZParser
).SentenceParser
to
read and write sentence data.XYZParser
with String
parameter, i.e. the sentence to be parsed. Pass this parameter to
SentenceParser.SentenceParser(String, String)
with expected sentence
type (e.g. "XYZ"
).TalkerId
parameter. Pass this
parameter to SentenceParser.SentenceParser(TalkerId, String, int)
with sentence type and number of data fields.XYZParser
in SentenceFactory
by using
the registerParser(String, Class)
method.createParser(String)
or
createParser(TalkerId, String)
to obtain an instance
of your parser. In addition, SentenceReader
will dispatch instances of XYZSentence
when "XYZ" sentences are
read from data source.Modifier and Type | Method and Description |
---|---|
Sentence |
createParser(String nmea)
Creates a parser for specified NMEA 0183 sentence String.
|
Sentence |
createParser(TalkerId talker,
SentenceId type)
Creates a parser for specified talker and sentence type.
|
Sentence |
createParser(TalkerId talker,
String type)
Creates a parser for specified talker and sentence type.
|
static SentenceFactory |
getInstance()
Returns the singleton instance of
SentenceFactory . |
boolean |
hasParser(String type)
Tells if the factory is able to create parser for specified sentence
type.
|
List<String> |
listParsers()
Returns a list of currently parseable sentence types.
|
void |
registerParser(String type,
Class<? extends SentenceParser> parser)
Register a sentence parser to factory.
|
void |
reset()
Resets the factory in it's initial state, i.e. restores and removes all
parsers the have been either removed or added.
|
void |
unregisterParser(Class<? extends SentenceParser> parser)
Unregisters a parser class, regardless of sentence type(s) it is
registered for.
|
public Sentence createParser(String nmea)
Sentence.getSentenceId()
method.nmea
- NMEA 0183 sentence StringIllegalArgumentException
- If there is no parser registered for the
given sentence typeIllegalStateException
- If parser is found, but it does not
implement expected constructors or is otherwise unusable.public Sentence createParser(TalkerId talker, SentenceId type)
talker
- Sentence talker idtype
- Sentence typeIllegalArgumentException
- If talker id is null or if there is no
parser registered for given sentence type.IllegalStateException
- If parser instantiation fails.public Sentence createParser(TalkerId talker, String type)
talker
- Talker ID to use in parsertype
- Type of the parser to createIllegalArgumentException
- If talker id is null or if there is no
parser registered for given sentence type.IllegalStateException
- If parser is found, but it does not
implement expected constructors or is otherwise unusable.public boolean hasParser(String type)
SentenceId
enum values should result returning
true
at all times.type
- Sentence type id, e.g. "GLL" or "GGA".public List<String> listParsers()
public void registerParser(String type, Class<? extends SentenceParser> parser)
createParser(String)
method can be used to obtain instances of
registered parser.
Sentences supported by the library are registered automatically, but they can be overridden simply be registering a new parser implementation for chosen sentence type. That is, each sentence type can have only one parser registered at a time.
type
- Sentence type id, e.g. "GGA" or "GLL".parser
- Class of parser implementation for given type
.public void unregisterParser(Class<? extends SentenceParser> parser)
parser
- Parser implementation class for type
.registerParser(String, Class)
public static SentenceFactory getInstance()
SentenceFactory
.public void reset()
Copyright (C) 2010-2017 Java Marine API authors. All Rights Reserved.