FileDocCategorySizeDatePackage
Audit.javaAPI DocExample4583Tue Dec 03 16:18:50 GMT 2002ora.jwsnut.chapter7.jaxr

Audit

public class Audit extends Object

Fields Summary
private static javax.xml.registry.BusinessQueryManager
bqm
Constructors Summary
Methods Summary
private static voidgetAuditEvents()


        // Get the Organization entries
        ArrayList namePatterns = new ArrayList();
        namePatterns.add("%");
        BulkResponse res = bqm.findOrganizations(null, namePatterns, null, null, null, null);

        // Process the results
        Collection coll = res.getCollection();
        if (!coll.isEmpty()) {
            Iterator iter = coll.iterator();
            while (iter.hasNext()) {
                Organization org = (Organization)iter.next();
                coll = org.getAuditTrail();
                System.out.println("Events for " + org.getName().getValue() + ": " + coll.size());
                Iterator aIter = coll.iterator();
                while (aIter.hasNext()) {
                    showAuditableEvent((AuditableEvent)aIter.next());
                }
           }
        }   

        // Get all the auditable events
        res = bqm.getRegistryObjects(LifeCycleManager.AUDITABLE_EVENT);
        if (res != null) {
	      coll = res.getCollection();
            System.out.println("Events for current user: " + coll.size());
            Iterator aIter = coll.iterator();
            while (aIter.hasNext()) {
                showAuditableEvent((AuditableEvent)aIter.next());
            }
        }
    
public static voidmain(java.lang.String[] args)

        
        // Validate arguments
        if (args.length != 1) {
            usage();
        }
        
        // Process the common arguments
        String queryURL = args[0];
        
        try {
            // Get the ConnectionFactory
            Properties props = new Properties();
            props.put("javax.xml.registry.queryManagerURL", queryURL);
            
            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
            getAuditEvents();
            
            // Close connection
            conn.close();           
            
        } catch (Throwable t) {
            System.out.println(t);
            t.printStackTrace(System.out);
            System.exit(1);
        }    
        
        System.exit(0);
    
private static voidshowAuditableEvent(javax.xml.registry.infomodel.AuditableEvent evt)

        String eventType = "??";
        switch (evt.getEventType()) {
        case AuditableEvent.EVENT_TYPE_CREATED:
            eventType = "CREATED";
            break;
        case AuditableEvent.EVENT_TYPE_DELETED:
            eventType = "DELETED";
            break;
        case AuditableEvent.EVENT_TYPE_DEPRECATED:
            eventType = "DEPRECATED";
            break;
        case AuditableEvent.EVENT_TYPE_UNDEPRECATED:
            eventType = "UNDEPRECATED";
            break;
        case AuditableEvent.EVENT_TYPE_UPDATED:
            eventType = "UPDATED";
            break;
        case AuditableEvent.EVENT_TYPE_VERSIONED:
            eventType = "VERSIONED";
            break;
        }
	  String name = evt.getUser() == null ? "Unknown" : evt.getUser().getPersonName().getFullName(); 
        System.out.println("\tType: " + eventType + ", date: " + evt.getTimestamp() + 
                           ", user: " + name);
    
public static voidusage()

        System.out.println("Usage:\tAudit queryURL");
        System.exit(1);