{
if (soLog.isDebugEnabled()) soLog.debug("lookupByAuthority(" + parent.getAuthorityId() + "," + segment.toString() + ")");
// the big goal is to make an XRDS, consisting of one or more XRDs
XRDS xrds = new XRDS();
boolean ret;
// give subclasses a chance to init the XRDS before we begin
ret = this.initXRDS(
xrds,
segment,
bSigned);
// if a subclass returned true, it doesnt want us to do any more work
if (ret == true) {
soLog.debug("Subclass handled XRDS completely. Returning it without any more work.");
return(xrds);
}
// generate XRDs for all subsegments in the request
for (int i=0; i<segment.getNumSubSegments(); i++) {
String subSegmentName = segment.getSubSegmentAt(i).toString();
try {
// create a new XRD
XRD xrd = new XRD();
// give subclasses a chance to init the XRD
ret = this.initXRD(
xrd,
parent,
subSegmentName,
bSigned);
// if a subclass returned true, it doesnt want us to do any more work
if (ret == true) {
soLog.debug("Subclass handled XRD completely. Returning it without any more work.");
xrds.add(xrd);
break;
}
// give authority handlers a chance to init it, if there are any for the current parent authority
List authorityHandlers = new ArrayList();
if (moAuthorityHandlers.get(parent.getAuthorityId()) != null)
authorityHandlers.addAll((List) moAuthorityHandlers.get(parent.getAuthorityId()));
for (Iterator ii = authorityHandlers.iterator(); ii.hasNext(); ) {
if (ret == true) break;
AuthorityHandler authorityHandler = (AuthorityHandler) ii.next();
ret = authorityHandler.initXRD(
xrd,
parent,
subSegmentName,
bSigned);
}
// if an authority handler returned true, it doesnt want us to do any more work
if (ret == true) {
soLog.debug("Authority Handler handled XRD completely. Returning it without any more work.");
xrds.add(xrd);
break;
}
// using the parent authority and subsegment name, find the authority we are describing now
SubSegment subSegment;
try {
subSegment = moStore.findSubSegment(parent, subSegmentName);
if (subSegment == null) throw new StoreNotFoundException("Null value returned.");
} catch (StoreNotFoundException ex) {
ServerNotFoundException ex2 = new ServerNotFoundException("Cannot find subsegment: " + subSegmentName, ex);
soLog.warn(ex2);
throw ex2;
}
Authority authority = moStore.getSubSegmentAuthority(subSegment);
// look up Refs and Services from the store, as well as LocalIDs if the store supports it
Ref[] refs = moStore.getAuthorityRefs(authority);
Service[] services = moStore.getAuthorityServices(authority);
LocalID[] localIds;
if (moStore instanceof StoreBetterLookup) {
localIds = ((StoreBetterLookup) moStore).getSubSegmentLocalIds(subSegment);
} else {
localIds = new LocalID[0];
}
// fill it with information we got from the store
for (int ii=0; ii<refs.length; ii++) xrd.addRef(refs[ii]);
for (int ii=0; ii<services.length; ii++) xrd.addService(services[ii]);
for (int ii=0; ii<localIds.length; ii++) xrd.addLocalID(localIds[ii]);
// do we want a local authority resolution service for this authority?
// this piece of information comes from the store, but we actually create
// the service, since this requires knowledge of the server configuration
if (authority.getLocalAuthService().equals(Boolean.TRUE)) {
URI[] uris;
try {
uris = new URI[2];
uris[0] = fillURI(authority.getAuthorityId(), "http");
uris[1] = fillURI(authority.getAuthorityId(), "https");
} catch(URISyntaxException ex) {
throw new ServerInternalException("Invalid URI for authority resolution service.", ex);
}
xrd.addService(new AuthorityResolutionService(uris, authority.getAuthorityId()));
}
// let our subclasses finish the XRD before we append it to the XRDS
this.finishXRD(
xrd,
parent,
subSegment,
authority,
bSigned);
// let authority handlers finish the XRD, if there are any for this authority
for (Iterator ii = authorityHandlers.iterator(); ii.hasNext(); ) {
AuthorityHandler authorityHandler = (AuthorityHandler) ii.next();
authorityHandler.finishXRD(
xrd,
parent,
subSegment,
authority,
bSigned);
}
// append XRD to the XRDS
xrds.add(xrd);
// authority becomes the parent authority for the next subsegment
parent = authority;
} catch (StoreException oEx) {