public class MetadataModel extends Object implements EventHandler
MetadataParser.parse(EventHandler)
),
but it can be used to programmatically create a BFS metadata file and
then write it out to a file (see print(Writer)
).
The model can contain multiple sections, each one with multiple entries. A section has a name, but it doesn't have to be unique. An entry is either a key/value pair or a key/array of values. There may be multiple entries with the same key in a section.
Modifier and Type | Class and Description |
---|---|
static class |
MetadataModel.Section
Holds information about a section.
|
static class |
MetadataModel.SectionEntry
Holds information about a section entry.
|
Modifier and Type | Field and Description |
---|---|
private MetadataModel.Section |
currentSection |
private MetadataModel.Section |
files |
private List<MetadataModel.Section> |
sections |
private String |
subtype |
Constructor and Description |
---|
MetadataModel()
Create a new metadata model.
|
Modifier and Type | Method and Description |
---|---|
void |
addFile(String key,
String name)
Add an entry to the 'files' section.
|
MetadataModel.Section |
addSection(String name)
Adds a new section to the model.
|
String |
getFile(int index)
Get the file entry with a given index.
|
String |
getFile(String key)
Get the file entry for a given key.
|
int |
getFileCount()
Get the number of entries in the 'files' section.
|
MetadataModel.Section |
getSection(int index)
Get the section at a given index.
|
MetadataModel.Section |
getSection(String name)
Get the first section with a given name.
|
int |
getSectionCount()
Get the number of sections.
|
String |
getSubtype()
Get the BFS subtype.
|
String |
getValue(String section,
String key)
Utility method for getting the value of the first entry
in the first section that matches the given section and
key name.
|
String[] |
getValues(String section,
String key)
Utility method for getting the values of the first entry
in the first section that matches the given section and
key name.
|
void |
handleEvent(EventType eventType,
Object eventData,
BfsParser parser)
The method is called by the parser when it has found something
interesting in a BFS file.
|
void |
print(Writer out)
Utility method for printing the contents of this model object
to a stream.
|
void |
setSubtype(String subtype)
Set the subtype of the BFS.
|
private String subtype
private List<MetadataModel.Section> sections
private MetadataModel.Section files
private MetadataModel.Section currentSection
public void handleEvent(EventType eventType, Object eventData, BfsParser parser)
EventHandler
It is recommended that event handlers ignore event types they don't know about.
handleEvent
in interface EventHandler
eventType
- The type of event. See the parser documentation
for more information about the event types it generateseventData
- The data that is associated with the eventparser
- The parser that is resposible for parsing the filepublic void print(Writer out)
out
- The output stream to write topublic void setSubtype(String subtype)
public String getSubtype()
public int getSectionCount()
public MetadataModel.Section addSection(String name)
name
- The name of the sectionpublic MetadataModel.Section getSection(int index)
index
- The index, a value between 0 and getSectionCount()
-1ArrayIndexOutOfBoundsException
- If the index is outside the
allowed rangepublic MetadataModel.Section getSection(String name)
name
- The name of the section to findpublic void addFile(String key, String name)
key
- The entry keyname
- The filename (not verified)public int getFileCount()
public String getFile(int index)
index
- The index, a value between 0 and getFileCount()
- 1public String getFile(String key)
key
- The key to look forpublic String getValue(String section, String key)
section
- The name of the sectionkey
- The key of the entrypublic String[] getValues(String section, String key)
section
- The name of the sectionkey
- The key of the entry