View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.xml.registry.client.util; 11 12 import java.util.Collection; 13 import java.util.Iterator; 14 15 import javax.xml.registry.BulkResponse; 16 import javax.xml.registry.JAXRException; 17 import javax.xml.registry.infomodel.AuditableEvent; 18 import javax.xml.registry.infomodel.RegistryObject; 19 import javax.xml.registry.infomodel.User; 20 21 /* 22 * Miscellaneous utility methods for debugging and tests 23 * 24 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/util/RegistryObjectUtil.java,v 1.1 2003/03/20 12:10:04 ritzmann Exp $ 25 * 26 */ 27 public class RegistryObjectUtil { 28 29 /*** 30 * Retrieves id from RegistryObject. 31 * 32 * @param obj 33 * @return 34 * @throws JAXRException 35 */ 36 public static String toId(Object obj) throws JAXRException { 37 if (obj instanceof RegistryObject) { 38 RegistryObject ro = (RegistryObject) obj; 39 return ro.getKey().getId(); 40 } else { 41 return "[toId: not a RegistryObject, obj=" + obj + "]"; 42 } 43 } 44 45 /*** 46 * Retrieves first object from a Collection. 47 * 48 * @param col 49 * @return 50 */ 51 public static Object getFirstObject(Collection col) { 52 if (col == null) { 53 return null; 54 } 55 Iterator it = col.iterator(); 56 if (!it.hasNext()) { 57 return null; 58 } 59 return it.next(); 60 } 61 62 /*** 63 * Throws exception if BulkResponse contains any exceptions. 64 * 65 * @param response 66 * @throws JAXRException 67 */ 68 public static void checkBulkResponse(BulkResponse response) 69 throws JAXRException { 70 Collection exes = response.getExceptions(); 71 if (exes == null) { 72 return; 73 } 74 throw new JAXRException((JAXRException) getFirstObject(exes)); 75 } 76 77 /*** 78 * Retrieves owner of RegistryObject. 79 * 80 * @param ro RegistryObject to get the owner of 81 * @return owner, ie. creator or null if this is a new RegistryObject 82 */ 83 public static User getOwner(RegistryObject ro) throws JAXRException { 84 // Ask server who our creator is 85 Collection events = ro.getAuditTrail(); 86 if (events == null) { 87 return null; 88 } 89 for (Iterator it = events.iterator(); it.hasNext();) { 90 AuditableEvent ev = (AuditableEvent) it.next(); 91 if (ev.getEventType() == AuditableEvent.EVENT_TYPE_CREATED) { 92 return ev.getUser(); 93 } 94 } 95 return null; 96 } 97 98 }

This page was automatically generated by Maven