|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.marineapi.nmea.parser.SentenceFactory
public final class SentenceFactory
Factory for creating sentence parsers.
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.
Method Summary | |
---|---|
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. |
void |
registerParser(String type,
Class<? extends SentenceParser> parser)
Register a sentence parser to factory. |
void |
unregisterParser(Class<? extends SentenceParser> parser)
Unregisters a parser class, regardless of sentence type(s) it is registered for. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public Sentence createParser(String nmea)
Sentence.getSentenceId()
method.
nmea
- NMEA 0183 sentence String
IllegalArgumentException
- If there is no parser registered for the
given sentence type
IllegalStateException
- 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 type
IllegalArgumentException
- 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 create
IllegalArgumentException
- 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 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
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |