/* -*-Java-*- ******************************************************************************** * * File: DLIOPwrapper.java * RCS: $Header: /u/testbed/CVSROOT/dldev/doc/Visigenic/InfoBus/StreetRouterProxy/DLIOPwrapper.java,v 1.1 1998/05/19 23:23:34 paepcke Exp $ * Description: Handler for the Stanford InfoBus DLIOP Protocol * Author: Gerard Rodriguez, Stanford University * Created: Wed Jan 15 11:14:50 1998 * Modified: Thu Apr 16 13:50:14 1998 (Andreas Paepcke) paepcke@SNUGGLES * Language: Java * Package: N/A * Status: Experimental (Do Not Distribute) * * (c) Copyright 1998, Stanford University, all rights reserved. * ******************************************************************************** * * Revisions: * * Wed Apr 15 11:15:44 1998 (Andreas Paepcke) paepcke@SNUGGLES * Changed to conform to our new specification of collection plugs. ******************************************************************************** */ // Do do: // - fix a bit of grammar /** DLIOPwrapper.java implements the part of the INFOBUS Proxy that deals with the DLIOP protocol. Its methods are invoked from remote objects via CORBA calls. In order to do their work, they call the methods of another module, called a 'collection plug'. While the DLIOPwrapper is the same for all search proxies, collection plugs are specialized to accessing particular collections, though they have a very clear small interface which we invoke from this DLIOPwrapper module.

As far as CORBA interfaces go, an InfoBus Proxy is a CConstrainCollection object. DLIOPwrapper.java implements all the DLIOP methods that a INFOBUS Proxy should be able to answer.

You don't really need to understand this file. You should only need to modify the CollectionPlug file.

For further documentation: About DLIOP, see http://www-diglib.stanford.edu/cgi-bin/WP/get/SIDL-WP-1997-0054 For an explanation of what collection plugs do, see: ****

To understand everything in detail, please check that DLIOP URL. Just in summary, a search proceeds when the client calls RequestConstrain, passing the pointer to an object called a result collection. That object typically resides at the client's site. This DLIOPwrapper module processes the search with the help of the underlying collection plug. I then adds the resulting information to the result collection by way of remote method calls.

The main task of all the methods in this module is to take the parameters passed into them, to unpack them, to invoke the proper service method in the collection plug, to pack the return parameters, and to return them to the caller. What makes this module somewhat hard to understand is mostly the packing and unpacking of the parameters. For example, when 10 documents are returned, and each has title, author and date, then the information is packed into a 10 by 3 matrix. This matrix is then made part of the final return data structure which contains some additional information. The reason we do this, rather than the obvious of making each document into an object and just returning an array of those objects, is that so far, CORBA does not provide pass-by-value. This means that the returned objects would all just be pointers. Whenever the client would pull some information out of a document (like the author or the title), this would be a remote method invocation. That is too much of a performance drain. Once pass-by-value is available, we can re-design the DLIOP protocol to be much simpler. */ import IDLInterchange.*; import CosPropertyService.*; public class DLIOPwrapper extends CConstrainCollectionImpl { // Please, set this to the name of this proxy public final static String SERVICE_NAME = "StreetRouter"; // An array of CollectionPlugs, this proxy can deal with // several CollectionPlugs at the same time. static final short MAX_COLPLUGS = 50; private CollectionPlug[] colplugs = new CollectionPlug[MAX_COLPLUGS]; private short colplugspointer; // USMarc <-> English translator USMarc lusmarc = new USMarc(); // A pointer to the ORB in the StreetServer class private org.omg.CORBA.ORB orb; // Constructors for this class public DLIOPwrapper () { super(); Init(); } public DLIOPwrapper (String name) { super(name); Init(); } public DLIOPwrapper (String name, org.omg.CORBA.ORB porb ) { super(name); Init(); orb = porb; } public void CancelRequest( CosPropertyService.Any pMessageID) throws IDLInterchange.InvalidMessageID { // In the framework of the implementation of this proxy // it is not possible to cancel an ongoing request, since the // results are sent all together. return; } //RequestItemsProperties // //Request to be sent properties of items given their server-side //cookies. // //Sometime later, one or more SetItemsProperties messages will be sent to //pResultTarget and finally a CompletedRequest() or RaiseException() //will be sent to signal the end of the request. // // o pMessageID is the client-side data to pass back in order to // identify the resulting callback messages. // o pPropertyNames are the list of fields desired. // o pServerCookies is a list of server-side cookies of the items // requested. // o pClientCookies is a list of client-side cookies to be returned // in conjuction with the items' state information. The client can // place anything in these cookies and is guarateed to be matched // up with the resulting items. // o pResultTarget is the target result collection to send the Items to. public void RequestItemsProperties( CosPropertyService.Any pMessageID, java.lang.String[] pPropertyNames, CosPropertyService.Any[] pServerCookies, CosPropertyService.Any[] pClientCookies, IDLInterchange.CCollection pResultTarget) { System.out.println("RequestItemsProperties"); IDLInterchange.TException pException = new IDLInterchange.TException(); if ( pResultTarget == null ) { // No ResultTarget System.out.println("No valid Result Collection in the parameters"); return; } if ( pPropertyNames.length == 0 ) { // No properties System.out.println("No properties in the parameters"); pException.aRequestReason("No properties in the parameters"); pResultTarget.RaiseException(pMessageID,pException); return; } if ( pServerCookies.length == 0 ) { // No cookies System.out.println("pServerCookies equals 0"); pResultTarget.CompletedRequest(pMessageID); return; } if ( pServerCookies.length != pClientCookies.length ) { // Error. System.out.println("Unmatching number of Client Side Cookies"); pException.aRequestReason("Unmatching number of Client Side Cookies"); pResultTarget.RaiseException(pMessageID,pException); } IDLInterchange.TItemsCookieState pItems = new IDLInterchange.TItemsCookieState(); try { pItems.aStates = pack_properties(pServerCookies, pPropertyNames, pResultTarget); System.out.println("Properties packed"); pItems.aClientCookies = pClientCookies; pResultTarget.SetItemsProperties(pMessageID, pItems); pResultTarget.CompletedRequest(pMessageID); } catch (Exception e) { // Something went wrong System.out.println(e); pException.aRequestReason("Error retrieving the properties"); pResultTarget.RaiseException(pMessageID,pException); } return; } //GetItemsPropertyNames // //For a list of items, return a list of valid property names. public java.lang.String GetItemsPropertyNames(CosPropertyService.Any[] pCookies)[][] throws IDLInterchange.InvalidRequest, IDLInterchange.InvalidCookies, IDLInterchange.InvalidAuthenication, IDLInterchange.InvalidPayment, IDLInterchange.MultipleExceptions { System.out.println("GetItemsPropertyNames"); CollectionPlug colplug = new CollectionPlug(); int numOfProps = colplug.GetDefaultPropertyNames().length; if (pCookies.length == 0) { //Compatibility with AsynInterClient.py (Old InfoBus) // It needs to be changed String[][] propos = new String[1][numOfProps]; propos[0] = colplug.GetDefaultPropertyNames(); propos[0] = ToUSMarc(propos[0]); return (propos); } String[][] aux = new String[pCookies.length][numOfProps]; short tablepos; int numberofdoc; for(int i=0;i E'pointer':'number of doc' String forcookies = "E"; forcookies = forcookies.concat(String.valueOf(pointer)); forcookies = forcookies.concat(":"); forcookies = forcookies.concat(String.valueOf(colplug.TotalItems())); aCookie.a_string(forcookies); pNewMoreCookie[0] = new IDLInterchange.TAccessOption( aTarget, aCookie, anItemClass, aHints); return pNewMoreCookie; } // pack_properties // Packs the property values of a set of documents identified // by pServerCookies. private IDLInterchange.TItemsState pack_properties( CosPropertyService.Any[] pServerCookies, String[] pPropertyNames, IDLInterchange.CCollection pResultTarget) throws Exception{ IDLInterchange.TException pException = new IDLInterchange.TException(); IDLInterchange.TItemsState result = new IDLInterchange.TItemsState(); short tablepos; int indexdoc; // Do I have these properties? System.out.println("Packing properties"); if (!CollectionPlug.CheckPropAvailability(lusmarc.USMarc2English(pPropertyNames))) { System.out.println("I don't have this set of properties"); throw new Exception(); } else { System.out.println("Right set of properties"); } result.aNames = pPropertyNames; CosPropertyService.Any[][] anItemsState = new CosPropertyService.Any [pServerCookies.length] [pPropertyNames.length]; for(int i =0;i E'pointer':'number of doc' forcookies = "E"; forcookies = forcookies.concat(String.valueOf(pointer)); forcookies = forcookies.concat(":"); forcookies = forcookies.concat(String.valueOf(i)); // Putting the cookie and the rest in the right place aACs[i][0] = new IDLInterchange.TAccessOption(); aACs[i][0].aTarget = this; // the proxy itself is the only able to // respond to more the request_more_properties aACs[i][0].aCookie = new CosPropertyService.Any(); aACs[i][0].aCookie.a_string(forcookies); System.out.println(aACs[i][0].aCookie.a_string()); aACs[i][0].anItemClass = anItemClass; // not used aACs[i][0].aHints = aHints; // not used i++; } // Putting the values set in the loop in the right variable aState.anItemsState = anItemsState; IDLInterchange.TItemsACState pItems = new IDLInterchange.TItemsACState(aACs,aState); return pItems; } // GetPropertyValues // Returns the values of all the properties of the document pointed by // 'p' in the CollectionPlug pointed by colplug. The result is // and array of 'any's: private CosPropertyService.Any[] GetPropertyValues (int p, CollectionPlug colplug) throws java.lang.ArrayIndexOutOfBoundsException { int numOfProps = colplug.GetPropertyNames().length; CosPropertyService.Any[] aux = new CosPropertyService.Any [numOfProps]; String[] values = new String[numOfProps]; values = colplug.GetPropertyValues(p); for(int j=0;j