import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import javax.naming.*;
import java.util.*;

public class CreateOrg
{
    public static void main(String[] args)
    {
        try
        {
            Context ctx = new InitialContext();

            ConnectionFactory factory =
                (ConnectionFactory) ctx.lookup(
                    "javax.xml.registr.ConnectionFactory");
            
            Properties props = new Properties();

// Specify the implementation for the actual connection factory
            props.put("javax.xml.registry.factoryClass",
                "com.sun.xml.registry.uddi.ConnectionFactoryImpl");

// Specify the location of the inquiry and publish API's
            props.put("javax.xml.registry.queryManagerURL",
                "www-3.ibm.com/services/uddi/testregistry/inquiryapi");
            props.put("javax.xml.registry.lifeCycleManagerURL",
                "www-3.ibm.com/services/uddi/testregistry/publish");

// Store the properties in the factory
            factory.setProperties(props);

// Create the Connection
            Connection conn = factory.createConnection();

// Get the RegistryService
            RegistryService regService = conn.getRegistryService();

// Get the BusinessQueryManager
            BusinessLifeCycleManager lifeCycle =
                regService.getBusinessLifeCycleManager();

// Create a new organization
            Organization newOrg = lifeCycle.createOrganization(
                "WebServCorp");

// Describe the organization (must use an international string)
            newOrg.setDescription(
                lifeCycle.createInternationalString(
                    "Providing Web services to the world"));

            ArrayList save = new ArrayList();

// Add the organization to a collection
            save.add(newOrg);

// Save the collection
            BulkResponse resp = lifeCycle.saveObjects(save);

// Get the response data
            Collection respColl = resp.getCollection();

            Iterator iter = respColl.iterator();

// Get the key generated for the new organization
            Key key = (Key) iter.next();

            System.out.println("The organization's key is "+
                key.getId());
        }
        catch (Exception exc)
        {
            exc.printStackTrace();
        }
    }
}
