The Metadata Model
The RETS IQ RETS Library includes an in-memory model for Metadata that allows developers to easily traverse and query Metadata.
The top level of the Metadata tree is the MetadataSystem node. On this resources can be retrieved either by iterating through the list using the getResources() method or by requesting them by name using the getResource(String name) method.
The example below fetches the Metadata from the server and then iterates through the Resources and Classifications printing out their names. For the full example code please refer to the GetMetadata example.
// Download the Metadata
MetadataSystem system = session.getMetadata();
// Print out some of the System information
System.out.println(
"SYSTEM: " + system.getName() +
" - " + system.getDescription());
// Iterate through all the resources
for(MetadataResource resource: system.getResources())
{
// Print out the Resource name
System.out.println(
" RESOURCE: " + resource.getName());
// Iterate through all the classifications for the resource
for(MetadataClass classification: resource.getClasses())
{
// Print out the classification name and description
System.out.println(
" CLASS: " + classification.getName() +
" - " + classification.getDescription());
}
}
Traversing The Tree Automatically
All nodes in the Metadata model derive from the MetadataTableMap. This allows them to be traversed in a generic manner.
For example if a developer wanted to traverse the complete Metadata tree and print the node types and names recursively then this could be done using the following code.
public void printNode(MetadataTableMap node, int depth)
{
// Indentation
for(int i = 0; i < depth; ++i) System.out.print("\t");
// Print the node type and node name
System.out.println(node.getMetadataType() + ": " + node);
// Iterate through each child type
for(MetadataType type: node.getChildTypes())
{
// Get the children nodes of a given type
for(MetadataTableMap child: node.getChildren(type))
{
// Print out the child node and increase indentation
printNode(child, depth + 1);
}
}
}
// Get the metadata from the server
MetadataSystem system = session.getMetadata();
// Print out the system node which will then
// recursively call all the children nodes
printNode(system, 0);
Memory Considerations
The Metadata in-memory model may consume a reasonable amount of memory depending on the size of the metadata. If you get OutOfMemoryException exceptions increase the JVM memory allocation using the -Xms and -Xmx Java virtual machine arguments.
For example to start the JVM with 128MB of memory and allowing it to expand to a maximum of 256MB, the parameters would be -Xms128m and -Xmx256m respectively.
java -Xms128m -Xmx256 -cp %MY_CLASSPATH% MyApplication