Discussions

EJB design: Value-list handler, value-list iterator and session-facade strat

  1. Hello all,

    Further to an earlier post, I rewrote my post trying to me more accurate in my question.

    Here is my problem:

    I am trying to implement the value-list handler design pattern using the session facade strategy. In the pattern as it is described here
    (http://java.sun.com/blueprints/corej2eepatterns/Patterns/ValueListHandler.html) the client accesses the value-list handler AND the iterator directly.

    As I chose the session-facade strategy having my value-list handler as a stateful session ejb, I don't know how the client is going to access the iterator. I see only one option: Having the client access the iterator through the ejb value-list handler. This requires adding new methods to the ejb.

    Is this the correct way of doing it? Is there another way of doing this?

    Thanks in advance,

    Julien Martin.
  2. hi,

    You are right that the session bean will have a method to return the instance of a Value list handler...

    When the client requests a collection, or a subset of a collection through a session bean,session bean provides a instance of the handler bean which in turn, returns the requested results as a serialized collection of Transfer Objects. The client receives the collection and now has a local copy of the requested information, which the client can display or process. When the client needs an additional subset of the results, it requests the handler to return another serialized collection containing the required results. The client can process the query results in smaller, manageable chunks. The handler bean also provides the client with navigation facilities (previous and next) so that the results may be traversed forward and backward as necessary.




    public class ValueListHandler
    implements ValueListIterator {

      protected List list;
      protected ListIterator listIterator;

      public ValueListHandler() {
      }

      protected void setList(List list)
      throws IteratorException {
        this.list = list;
        if(list != null)
          listIterator = list.listIterator();
        else
          throw new IteratorException("List empty");
      }

      public Collection getList(){
        return list;
      }
        
      public int getSize() throws IteratorException{
        int size = 0;
            
        if (list != null)
          size = list.size();
        else
          throw new IteratorException(...); //No Data

        return size;
      }
        
      public Object getCurrentElement()
      throws IteratorException {

        Object obj = null;
        // Will not advance iterator
        if (list != null)
        {
          int currIndex = listIterator.nextIndex();
          obj = list.get(currIndex);
        }
        else
          throw new IteratorException(...);
        return obj;

      }
        
      public List getPreviousElements(int count)
      throws IteratorException {
        int i = 0;
        Object object = null;
        LinkedList list = new LinkedList();
        if (listIterator != null) {
          while (listIterator.hasPrevious() && (i < count)){
            object = listIterator.previous();
            list.add(object);
            i++;
          }
        }// end if
        else
          throw new IteratorException(...); // No data

        return list;
      }
        
      public List getNextElements(int count)
      throws IteratorException {
        int i = 0;
        Object object = null;
        LinkedList list = new LinkedList();
        if(listIterator != null){
          while( listIterator.hasNext() && (i < count) ){
            object = listIterator.next();
            list.add(object);
            i++;
          }
        } / / end if
        else
          throw new IteratorException(...); // No data

        return list;
      }
        
      public void resetIndex() throws IteratorException{
        if(listIterator != null){
          listIterator = list.ListIterator();
        }
        else
          throw new IteratorException(...); // No data
      }
      ...
    }
  3. @see http://mlavwilson.sourceforge.net/vlh/index.html