FileDocCategorySizeDatePackage
CustomEnum.javaAPI DocExample3989Tue Mar 11 22:47:34 GMT 2003ora.jwsnut.chapter7.jaxr

CustomEnum.java

package ora.jwsnut.chapter7.jaxr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessQueryManager;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.JAXRException;
import javax.xml.registry.LifeCycleManager;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.ClassificationScheme;
import javax.xml.registry.infomodel.Concept;
import ora.jwsnut.chapter7.util.Utils;

public class CustomEnum {

    // The BusinessQueryManager
    private static BusinessQueryManager bqm;
    
    public static void main(String[] args) {
        
        // Validate arguments
        if (args.length != 2) {
            usage();
        }
        
        // Process the arguments
        boolean isUddi = args[0].equals("-uddi");
        String queryURL = args[1];
        
        try {
            // Get the ConnectionFactory
            Properties props = new Properties();
            props.put("javax.xml.registry.queryManagerURL", queryURL);
 
            boolean displayID = false;
            if (isUddi) {
                String fileName = System.getProperty("CustomEnumFile");
                if (fileName != null) {
                    System.out.println("Custom taxonomy file is " + fileName);
                    System.setProperty("com.sun.xml.registry.userTaxonomyFilenames", fileName);
                } else {
                    displayID = true; // Step 1 - just display the ID
                }
            }
            
            ConnectionFactory cf = ConnectionFactory.newInstance();
            cf.setProperties(props);
            
            // Get and initialize the connection
            Connection conn = cf.createConnection();
            conn.setSynchronous(true);
            
            // Get the RegistryService and the BusinessQueryManager
            RegistryService registry = conn.getRegistryService();
            bqm = registry.getBusinessQueryManager();            

            // Run the example code
            displayEnum(displayID);
            
            // Close connection
            conn.close();           
            
        } catch (Throwable t) {
            System.out.println(t);
            t.printStackTrace(System.out);
            System.exit(1);
        }    
        
        System.exit(0);
    }
    
    private static void displayEnum(boolean displayID) throws JAXRException {
        // First find the classification scheme
        ClassificationScheme scheme = bqm.findClassificationSchemeByName(null, "TestEnum");
        if (scheme == null) {
            System.out.println("Please install the registry test data");
            System.exit(1);
        }
        System.out.println("Scheme id is " + scheme.getKey().getId());
        if (displayID) {
            System.exit(0);
        }
        
        // Now look for the Concepts
        Collection coll = scheme.getDescendantConcepts();
        System.out.print("Enumeration values: ");
        Iterator iter = coll.iterator();
        while (iter.hasNext()) {
            Concept c = (Concept)iter.next();
            System.out.print(c.getValue() + "  ");
        }
        System.out.println();
        
        // Locate by path
        String path = "/" + scheme.getKey().getId() + "/1";
        Concept c = bqm.findConceptByPath(path);
        if (c != null) {
            System.out.println("Located concept by path: value = " + c.getValue());
        } else {
            System.out.println("Failed to locate concept by path");
        }    
    }    
    
    private static void usage() {
        System.out.println("Usage:\tCustomEnum -uddi|-ebxml queryURL");
        System.exit(1);
    }
}