[V5.1 and later]UDDI TestCreateMinimalEntity.java

TestCreateMinimalEntity.java:

package com.ibm.uddi.promoter.sample;

/*
* IBM WebSphere UDDI Registry Sample Program 
* 
* "This sample program may be freely used, executed, copied and modified by customer 
* (a) for its own instruction and study, (b) in order to develop applications which run with 
* IBM WebSphere products, either for customer's own internal use or for redistribution with 
* customer's own products."
*
* Product 5630-A36,  (C) COPYRIGHT International Business Machines Corp., 2003
* All Rights Reserved * Licensed Materials - Property of IBM
*              
*/

import java.sql.Connection;

import com.ibm.uddi.promoter.PromoterLogger;
import com.ibm.uddi.promoter.config.Configuration;
import com.ibm.uddi.promoter.config.DatabaseConfiguration;
import com.ibm.uddi.promoter.db.DBException;
import com.ibm.uddi.promoter.db.DBManager;
import com.ibm.uddi.promoter.entity.BusinessStub;
import com.ibm.uddi.promoter.entity.ServiceStub;
import com.ibm.uddi.promoter.exception.PromoterDBException;
import com.ibm.uddi.promoter.exception.PromoterException;
import com.ibm.uddi.promoter.publish.KeyDetector;

/**
 * Example of how to write minimal data entities directly to UDDI database.
 * 
 * It is up to the developer to update the entity using UDDI4J publish operations with 
 * further information. Normally there would be no need to use these classes, as 
 * the PromoterAPI will handle minimal entity creation and updates.
 * 
 * @author IBM
 */
public class TestCreateMinimalEntity {

    public static void main(String[] args) {

        System.out.println("Writing minimal entities to UDDI registry using BusinessStub and ServiceStub classes");

        try {
            Configuration config = null;
            // get config data from properties file (could easily be set programmatically)
            config = new Configuration("c:/promoter/UDDIUtilityTools.properties");
            
            // write messages to console
            config.setMessageStream(System.out);
            
            // start trace and message logging
            PromoterLogger.getLogger().initialise(config.getLoggerConfiguration());

            DatabaseConfiguration dbConfig = config.getDatabaseConfiguration();

            // get db manager
            DBManager dbManager = DBManager.getInstance(dbConfig);

            Connection connection = dbManager.getConnection();

            // KeyDetector ensures no duplicate keys get into database            
            KeyDetector keyDetector = new KeyDetector(connection);

            // create minimal entity object (business)
            BusinessStub businessSeed = new BusinessStub(keyDetector);

            // populate seed entity with minimal data     
            businessSeed.setKey("1B5F411F-AAAA-4BF1-B5AB-5FC7555FABA3");
            businessSeed.setName("business entity test 2");
            businessSeed.setOperatorName("myOperatorName");
            businessSeed.setOwnerName("UNAUTHENTICATED");

            // connect to UDDI database and write the minimal entity data
            businessSeed.createStub();
            
            // create minimal entity object (service)
            ServiceStub serviceSeed = new ServiceStub(keyDetector);
            
            // populate seed entity with minimal data     
            serviceSeed.setKey("3F5F411F-AAAA-4BF1-B5AB-5FC7555FABA3");
            serviceSeed.setName("test service stub");
            serviceSeed.setParentKey("1B5F411F-AAAA-4BF1-B5AB-5FC7555FABA3");
            serviceSeed.setSeq(1);
            
            // connect to UDDI database and write the minimal entity data
            serviceSeed.createStub();

            System.out.println("Finished writing minimal entities to UDDI registry");

  // this will be thrown if the entity already exists
        } catch (PromoterDBException e) {
            System.out.println(e);
        } catch (PromoterException e) {
            System.out.println(e);
        } catch (DBException e) {
            System.out.println(e);
        }

    }
}


Related tasks
Enabling Universal Description, Discovery and Integration (UDDI)
Related reference
UDDI TestEntityExporter.java
UDDI TestEntityImporter.java
UDDI TestEntityPromoter.java
UDDI TestEntityFinder.java
UDDI TestEntityDeleter.java
UDDI TestUddiSerializer.java
UDDI TestUddiDeserializer.java
UDDI TestStubManager.java