GetMetadata.java
01 package com.bigllc.retsiq.examples;
02 
03 import java.net.MalformedURLException;
04 
05 import com.bigllc.retsiq.metadata.MetadataClass;
06 import com.bigllc.retsiq.metadata.MetadataResource;
07 import com.bigllc.retsiq.metadata.MetadataSystem;
08 import com.bigllc.retsiq.simpleclient.RETSClientException;
09 import com.bigllc.retsiq.simpleclient.RETSConnection;
10 import com.bigllc.retsiq.simpleclient.RETSUserSession;
11 
12 /**
13  * Example to demonstrate fetching metadata in memory and traversing
14  * some of the elements.
15  
16  * This example will require greater memory allocation to hold the 
17  * metadata. This can be set by using the VM arguments -Xms128m and
18  * -Xmx256m.
19  
20  @author Marc G. Smith
21  */
22 public class GetMetadata 
23 {
24   public static void main(String[] argsthrows MalformedURLException 
25   {
26     String loginurl   = "http://rets.server.com/rets/login";
27     String username   = "username";
28     String password     = "password";
29     
30     // Create the connection class
31     RETSConnection connection = new RETSConnection(loginurl);
32     RETSUserSession session = null;
33     
34     try {
35       // Authenticate the user and get session
36       session = connection.getSession(username, password);
37       
38       MetadataSystem system = session.getMetadata();
39       
40       System.out.println(
41         "SYSTEM: " + system.getName() 
42         " - " + system.getDescription());
43       
44       for(MetadataResource resource: system.getResources()) {
45 
46         System.out.println(
47           "    RESOURCE: " + resource.getName());
48         
49         for(MetadataClass classification: resource.getClasses()) {
50           System.out.println(
51             "        CLASS: " + classification.getName() +
52             " - " + classification.getDescription());
53         }
54       }
55     }
56     catch(RETSClientException e) {
57       System.err.println(e.getMessage());
58     }
59     finally {
60       if(session != null) { 
61         try {
62           session.logout()
63         
64         catch(RETSClientException e) {
65           System.err.println(e.getMessage());
66         }
67       }
68     }
69   }
70 }