Package net.sf.basedb.util.bfs
Class MetadataModel
- java.lang.Object
-
- net.sf.basedb.util.bfs.MetadataModel
-
- All Implemented Interfaces:
EventHandler
public class MetadataModel extends Object implements EventHandler
A model container of the contents of a BFS metadata file. This class is primarily intended to be used when parsing a BFS metadata file (seeMetadataParser.parse(EventHandler)
), but it can be used to programmatically create a BFS metadata file and then write it out to a file (seeprint(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.
- Version:
- 2.15
- Author:
- Nicklas
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetadataModel.Section
Holds information about a section.static class
MetadataModel.SectionEntry
Holds information about a section entry.
-
Field Summary
Fields Modifier and Type Field Description private MetadataModel.Section
currentSection
private MetadataModel.Section
files
private List<MetadataModel.Section>
sections
private String
subtype
-
Constructor Summary
Constructors Constructor Description MetadataModel()
Create a new metadata model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
subtype
private String subtype
-
sections
private List<MetadataModel.Section> sections
-
files
private MetadataModel.Section files
-
currentSection
private MetadataModel.Section currentSection
-
-
Method Detail
-
handleEvent
public void handleEvent(EventType eventType, Object eventData, BfsParser parser)
Description copied from interface:EventHandler
The method is called by the parser when it has found something interesting in a BFS file. See the respective parser documentation for documentation about the events that it generates. There is usually some kind of information associated with the event. This information is sent to the event handler as an object. The parser should document what kind of information it sends so that event handler implementation can react and use the information.It is recommended that event handlers ignore event types they don't know about.
- Specified by:
handleEvent
in interfaceEventHandler
- Parameters:
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 file
-
print
public void print(Writer out)
Utility method for printing the contents of this model object to a stream.- Parameters:
out
- The output stream to write to
-
setSubtype
public void setSubtype(String subtype)
Set the subtype of the BFS.
-
getSubtype
public String getSubtype()
Get the BFS subtype.
-
getSectionCount
public int getSectionCount()
Get the number of sections.
-
addSection
public MetadataModel.Section addSection(String name)
Adds a new section to the model.- Parameters:
name
- The name of the section- Returns:
- The new section
-
getSection
public MetadataModel.Section getSection(int index)
Get the section at a given index.- Parameters:
index
- The index, a value between 0 andgetSectionCount()
-1- Returns:
- Information about the section
- Throws:
ArrayIndexOutOfBoundsException
- If the index is outside the allowed range
-
getSection
public MetadataModel.Section getSection(String name)
Get the first section with a given name. If there are multiple sections with the same name, only the first is returned.- Parameters:
name
- The name of the section to find- Returns:
- A section or null if no section exists
-
addFile
public void addFile(String key, String name)
Add an entry to the 'files' section.- Parameters:
key
- The entry keyname
- The filename (not verified)
-
getFileCount
public int getFileCount()
Get the number of entries in the 'files' section.
-
getFile
public String getFile(int index)
Get the file entry with a given index.- Parameters:
index
- The index, a value between 0 andgetFileCount()
- 1- Returns:
- The file name
-
getFile
public String getFile(String key)
Get the file entry for a given key. If multiple entries with the same key exists, only the first is returned.- Parameters:
key
- The key to look for- Returns:
- The file name of null if no entry exists for the given key
-
getValue
public 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.- Parameters:
section
- The name of the sectionkey
- The key of the entry- Returns:
- The value, or null if no section or entry is found
-
getValues
public 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.- Parameters:
section
- The name of the sectionkey
- The key of the entry- Returns:
- The values, or null if no section or entry is found
-
-