⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 removeregistryentry.java

📁 java web services how to program
💻 JAVA
字号:
// Fig. 10.12: RemoveRegistryEntry.java
// Removes previously registered entry from XML registry.

package com.deitel.jws1.jaxr;

// JAXR core packages
import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;

// java core packages
import java.util.*;
import java.net.PasswordAuthentication;

public class RemoveRegistryEntry {

   // capability interface for querying XML registry
   private BusinessQueryManager queryManager;

   // capability interface for adding, updating, removing entries
   private BusinessLifeCycleManager lifeCycleManager;
   
   // default constructor
   public RemoveRegistryEntry() throws Exception
   {
      // create login password pair
      String userName = "username";
      String password = "password";
      
      // create XMLRegistry manager instance
      XMLRegistryManager registryManager =
         new XMLRegistryManager( userName, password );

      // obtain business query 
      queryManager =
         registryManager.getBusinessQueryManager();
      
      // obtain business life cycle manager reference
      lifeCycleManager =
         registryManager.getBusinessLifeCycleManager();
      
   } // end constructor 

   // queries registry with provided string
   public BulkResponse getOrganizations() throws JAXRException
   {
      // define qualifiers
      Collection qualifierList = new ArrayList();
       
      // matches sorted in ascending order
      qualifierList.add( FindQualifier.SORT_BY_NAME_ASC );
      
      // matches all companies containing Deitel
      String pattern1 = "%Deitel%";
      
      // matches all companies containing Associates
      String pattern2 = "%Associates%";
      
      // matches organizations that include words
      // "Deitel" or "Associates" in their name
      Collection namePatternList = new ArrayList();
      namePatternList.add( pattern1 );
      namePatternList.add( pattern2 );

      // classification for education services
      ClassificationScheme classificationScheme =
         queryManager.findClassificationSchemeByName(
            null, "ntis-gov:naics" );
      
      // create classification
      Classification classification = 
         lifeCycleManager.createClassification(
            classificationScheme,
            "Educational Support Services",
            "61171" );
      
      Collection classificationList = new ArrayList();
      classificationList.add( classification );
      
      // obtain matching organizations
      BulkResponse toReturn = 
         queryManager.findOrganizations( 
            qualifierList, namePatternList,
            classificationList, null, null, null );
      
      return toReturn;

   } // end method getOrganizations
   
   // create Collection of organization Keys
   public static Collection createKeyList(
      BulkResponse bulkResponse )
      throws JAXRException
   {
      // obtain organizations
      Collection organizationCollection =
         bulkResponse.getCollection();
         
      // create iterator of collection elements
      Iterator organizations =
         organizationCollection.iterator();
      
      // contain organizations to remove
      Collection keyList = new ArrayList();
      
      // remove each organization
      while ( organizations.hasNext() ) {
   
         // obtain reference to Organization instance
         Organization organization =
            ( Organization )organizations.next();
         
         // obtain and display organization name
         InternationalString name = organization.getName();
         
         System.out.println(
            "\nOrganization to remove:  " +
            name.getValue() );
         
         // obtain identifying key
         Key organizationKey = organization.getKey();
         
         // add key to Collection
         keyList.add( organizationKey );
         
         System.out.println( "Key: " + 
            organizationKey.getId() );
         
      } // end while
      
      // return Collection
      return keyList;
      
   } // end method createKeyList

   // remove specified organization
   public BulkResponse remove( Collection keyList ) 
      throws JAXRException
   {
      // remove organization
      BulkResponse bulkResponse = 
         lifeCycleManager.deleteOrganizations( keyList );
      
      return bulkResponse;

   } // end method remove
   
   // display exceptions contained in BulkResponse 
   public static void displayRemovedEntries( 
      BulkResponse bulkResponse ) 
      throws JAXRException
   {
      // get removed entries
      Collection removedCollection = 
         bulkResponse.getCollection();
      
      // organizations successfully removed
      Iterator removedOrganizations =
         removedCollection.iterator();
         
      // display removed organization keys
      while ( removedOrganizations.hasNext() ) {
            
         Key removedKey =
            ( Key )removedOrganizations.next();
            
         System.out.println( "Removed organization with key " +
            removedKey.getId() );
            
      } // end while
         
   } // end method displayRemovedEntries
   
   // display exceptions contained in BulkResponse 
   public static void displayExceptions( 
      BulkResponse bulkResponse ) throws JAXRException
   {
      // get exceptions Collection
      Collection exceptionCollection = 
         bulkResponse.getExceptions();
       
      // ensure exceptions occurred
      if ( exceptionCollection != null ) {

         // exceptions raised
         Iterator exceptionsRaised =
            exceptionCollection.iterator();
         
         // display exceptions raised
         while ( exceptionsRaised.hasNext() ) {
            
            Exception exception =
               ( Exception )exceptionsRaised.next();
            
            exception.printStackTrace();
         } // end while
         
      } // end if
      
   } // end method displayExceptions
   
   // entry point for class RemoveRegistryEntry
   public static void main( String[] args ) 
   {
      // find and remove matching organizations
      try {   
         
         RemoveRegistryEntry entryRemoval =
            new RemoveRegistryEntry();
         
         // get matching organizations
         BulkResponse bulkResponse =
            entryRemoval.getOrganizations();
         
         // obtain exception collection
         Collection exceptionCollection =
            bulkResponse.getExceptions();
      
         // display exception information
         if ( exceptionCollection != null ) {
            
            // display exceptions
            Iterator exceptions =
               exceptionCollection.iterator();
            
            // display exception stack trace
            while ( exceptions.hasNext() ) {
               JAXRException exception =
                  ( JAXRException )exceptions.next();
               
               exception.printStackTrace();
            } 
            
            // exit application
            return;
            
         } // end if
         
         // create Collection of keys
         Collection keyList = createKeyList( bulkResponse );
         
         // remove organizations
         BulkResponse removalResults =
            entryRemoval.remove( keyList );

         // display removed entries
         displayRemovedEntries( removalResults );
         
         // display exceptions
         displayExceptions( removalResults );
        
      } // end try
      
      // catch all exceptions
      catch ( Exception exception ) {
         exception.printStackTrace();
      }
      
   } // end method main
   
} // end class RemoveRegistryEntry

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -