stefan      2004/07/16 09:37:00

  Modified:    proposals/jcrri/src/org/apache/slide/jcr/core/observation
                        DispatchAction.java EventConsumer.java
                        EventDispatcher.java EventFilter.java
                        EventImpl.java
  Log:
  jcrri
  
  Revision  Changes    Path
  1.2       +7 -5      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/DispatchAction.java
  
  Index: DispatchAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/DispatchAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DispatchAction.java       1 Jul 2004 18:29:57 -0000       1.1
  +++ DispatchAction.java       16 Jul 2004 16:37:00 -0000      1.2
  @@ -36,7 +36,9 @@
    */
   class DispatchAction {
   
  -    /** The collection of <code>EventState</code>s */
  +    /**
  +     * The collection of <code>EventState</code>s
  +     */
       final EventStateCollection eventStates;
   
       /**
  @@ -50,7 +52,7 @@
        * <code>eventStates</code> and <code>eventConsumers</code>.
        */
       DispatchAction(EventStateCollection eventStates, Collection eventConsumers) {
  -        this.eventStates = eventStates;
  -        this.eventConsumers = eventConsumers;
  +     this.eventStates = eventStates;
  +     this.eventConsumers = eventConsumers;
       }
   }
  
  
  
  1.3       +56 -39    
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventConsumer.java
  
  Index: EventConsumer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventConsumer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EventConsumer.java        2 Jul 2004 16:24:36 -0000       1.2
  +++ EventConsumer.java        16 Jul 2004 16:37:00 -0000      1.3
  @@ -24,15 +24,15 @@
   
   package org.apache.slide.jcr.core.observation;
   
  -import javax.jcr.observation.EventListener;
  -import javax.jcr.observation.EventIterator;
   import javax.jcr.Ticket;
  +import javax.jcr.observation.EventIterator;
  +import javax.jcr.observation.EventListener;
   
   /**
    * The <code>EventConsumer</code> class combines the [EMAIL PROTECTED]
    * javax.jcr.observation.EventListener} with the implementation of specified
    * filter for the listener: [EMAIL PROTECTED] EventFilter}.
  - * <p>
  + * <p/>
    * Collections of [EMAIL PROTECTED] EventState} objects will be dispatched to 
[EMAIL PROTECTED]
    * #consumeEvents}.
    *
  @@ -41,16 +41,24 @@
    */
   class EventConsumer {
   
  -    /** The <code>Ticket</code> associated with this <code>EventConsumer</code>. */
  +    /**
  +     * The <code>Ticket</code> associated with this <code>EventConsumer</code>.
  +     */
       private final Ticket ticket;
   
  -    /** The listener part of this <code>EventConsumer</code>. */
  +    /**
  +     * The listener part of this <code>EventConsumer</code>.
  +     */
       private final EventListener listener;
   
  -    /** The <code>EventFilter</code> for this <code>EventConsumer</code>. */
  +    /**
  +     * The <code>EventFilter</code> for this <code>EventConsumer</code>.
  +     */
       private final EventFilter filter;
   
  -    /** cached hash code value */
  +    /**
  +     * cached hash code value
  +     */
       private int hashCode;
   
       /**
  @@ -66,22 +74,29 @@
        *                              or <code>filter</code> is<code>null</code>.
        */
       EventConsumer(Ticket ticket, EventListener listener, EventFilter filter) {
  -        if (ticket == null) throw new NullPointerException("ticket");
  -        if (listener == null) throw new NullPointerException("listener");
  -        if (filter == null) throw new NullPointerException("filter");
  -
  -        this.ticket = ticket;
  -        this.listener = listener;
  -        this.filter = filter;
  +     if (ticket == null) {
  +         throw new NullPointerException("ticket");
  +     }
  +     if (listener == null) {
  +         throw new NullPointerException("listener");
  +     }
  +     if (filter == null) {
  +         throw new NullPointerException("filter");
  +     }
  +
  +     this.ticket = ticket;
  +     this.listener = listener;
  +     this.filter = filter;
       }
   
       /**
        * Returns the <code>Ticket</code> that is associated
        * with this <code>EventConsumer</code>.
  +     *
        * @return the <code>Ticket</code> of this <code>EventConsumer</code>.
        */
       Ticket getTicket() {
  -        return getTicket();
  +     return getTicket();
       }
   
       /**
  @@ -91,22 +106,23 @@
        * @return the <code>EventListener</code> of this <code>EventConsumer</code>.
        */
       EventListener getEventListener() {
  -        return listener;
  +     return listener;
       }
   
       /**
        * Dispatches the events to the <code>EventListener</code>.
  +     *
        * @param events a collection of [EMAIL PROTECTED] EventState}s
  -     *   to dispatch.
  +     *               to dispatch.
        */
       void consumeEvents(EventStateCollection events) {
  -        // check if filtered iterator has at least one event
  -        EventIterator it = new FilteredEventIterator(events, filter);
  -        if (it.hasNext()) {
  -            listener.onEvent(it);
  -        } else {
  -            // otherwise skip this listener
  -        }
  +     // check if filtered iterator has at least one event
  +     EventIterator it = new FilteredEventIterator(events, filter);
  +     if (it.hasNext()) {
  +         listener.onEvent(it);
  +     } else {
  +         // otherwise skip this listener
  +     }
       }
   
       /**
  @@ -123,25 +139,26 @@
        *         other <code>EventConsumer</code>.
        */
       public boolean equals(Object obj) {
  -        if (this == obj) {
  -            return true;
  -        }
  -        if (obj instanceof EventConsumer) {
  -            EventConsumer other = (EventConsumer)obj;
  -            return ticket.equals(other.ticket)
  -                    && listener.equals(other.listener);
  -        }
  -        return false;
  +     if (this == obj) {
  +         return true;
  +     }
  +     if (obj instanceof EventConsumer) {
  +         EventConsumer other = (EventConsumer) obj;
  +         return ticket.equals(other.ticket)
  +                 && listener.equals(other.listener);
  +     }
  +     return false;
       }
   
       /**
        * Returns the hash code for this <code>EventConsumer</code>.
  +     *
        * @return the hash code for this <code>EventConsumer</code>.
        */
       public int hashCode() {
  -        if (hashCode == 0) {
  -            hashCode = ticket.hashCode() ^ listener.hashCode();
  -        }
  -        return hashCode;
  +     if (hashCode == 0) {
  +         hashCode = ticket.hashCode() ^ listener.hashCode();
  +     }
  +     return hashCode;
       }
   }
  
  
  
  1.2       +0 -0      
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventDispatcher.java
  
  Index: EventDispatcher.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventDispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  
  
  
  1.3       +98 -90    
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventFilter.java
  
  Index: EventFilter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EventFilter.java  2 Jul 2004 16:24:36 -0000       1.2
  +++ EventFilter.java  16 Jul 2004 16:37:00 -0000      1.3
  @@ -28,7 +28,9 @@
   import org.apache.slide.jcr.core.NodeId;
   import org.apache.slide.jcr.core.TicketImpl;
   
  -import javax.jcr.*;
  +import javax.jcr.Node;
  +import javax.jcr.RepositoryException;
  +import javax.jcr.StringIterator;
   import javax.jcr.access.AccessDeniedException;
   import javax.jcr.nodetype.NodeType;
   
  @@ -43,10 +45,14 @@
   
       static final EventFilter BLOCK_ALL = new BlockAllFilter();
   
  -    /** The ItemManager of the ticket */
  +    /**
  +     * The ItemManager of the ticket
  +     */
       private final ItemManager itemMgr;
   
  -    /** The ticket this EventFilter belongs to. */
  +    /**
  +     * The ticket this EventFilter belongs to.
  +     */
       private final TicketImpl ticket;
   
       /**
  @@ -55,7 +61,9 @@
        */
       private final long eventTypes;
   
  -    /** Only allow Items with the specified <code>absPath</code> */
  +    /**
  +     * Only allow Items with the specified <code>absPath</code>
  +     */
       private final String absPath;
   
       /**
  @@ -102,22 +110,22 @@
        *                   that registered the [EMAIL PROTECTED] 
javax.jcr.observation.EventListener}.
        */
       EventFilter(ItemManager itemMgr,
  -                TicketImpl ticket, 
  -                long eventTypes,
  -                String absPath,
  -                boolean isDeep,
  -                String[] uuids,
  -                NodeType[] nodeTypes,
  -                boolean noLocal) {
  -
  -        this.itemMgr = itemMgr;
  -        this.ticket = ticket;
  -        this.eventTypes = eventTypes;
  -        this.absPath = absPath;
  -        this.isDeep = isDeep;
  -        this.uuids = uuids;
  -        this.noLocal = noLocal;
  -        this.nodeTypes = nodeTypes;
  +             TicketImpl ticket,
  +             long eventTypes,
  +             String absPath,
  +             boolean isDeep,
  +             String[] uuids,
  +             NodeType[] nodeTypes,
  +             boolean noLocal) {
  +
  +     this.itemMgr = itemMgr;
  +     this.ticket = ticket;
  +     this.eventTypes = eventTypes;
  +     this.absPath = absPath;
  +     this.isDeep = isDeep;
  +     this.uuids = uuids;
  +     this.noLocal = noLocal;
  +     this.nodeTypes = nodeTypes;
       }
   
       /**
  @@ -128,7 +136,7 @@
        *         <code>EventFilter</code>.
        */
       TicketImpl getTicket() {
  -        return ticket;
  +     return ticket;
       }
   
       /**
  @@ -139,7 +147,7 @@
        *         <code>EventFilter</code>.
        */
       ItemManager getItemManager() {
  -        return itemMgr;
  +     return itemMgr;
       }
   
       /**
  @@ -149,63 +157,62 @@
        * @param eventState the <code>EventState</code> in question.
        * @return <code>true</code> if this <code>EventFilter</code> blocks the
        *         <code>EventState</code>.
  -     *
        * @throws RepositoryException if an error occurs while checking.
        */
       boolean blocks(EventState eventState) throws RepositoryException {
  -        // first do cheap checks
  +     // first do cheap checks
   
  -        // check event type
  -        long type = eventState.getType();
  -        if ((eventTypes & type) == 0) {
  -            return true;
  -        }
  -
  -        // check for ticket local changes
  -        if (noLocal && ticket.equals(eventState.getTicket())) {
  -            // listener does not wish to get local events
  -            return true;
  -        }
  -
  -        // check UUIDs
  -        String parentUUID = eventState.getParentUUID();
  -        if (uuids != null) {
  -            boolean match = false;
  -            for (int i = 0; i < uuids.length && !match; i++) {
  -                match |= parentUUID.equals(uuids[i]);
  -            }
  -            if (!match) {
  -                return true;
  -            }
  -        }
  -
  -        Node parent = null;
  -        try {
  -            parent = (Node)itemMgr.getItem(new NodeId(eventState.getParentUUID()));
  -        } catch (AccessDeniedException e) {
  -            return true;
  -        }
  -
  -        // check node types
  -        if (nodeTypes != null) {
  -            boolean match = false;
  -            for (int i = 0; i < nodeTypes.length && !match; i++) {
  -                match |= parent.isNodeType(nodeTypes[i].getName());
  -            }
  -            if (!match) {
  -                return true;
  -            }
  -        }
  -
  -        // check path
  -        StringIterator paths = parent.getPaths();
  -        boolean match = false;
  -        while (paths.hasNext() && !match) {
  -            match |= (isDeep) ? paths.nextString().startsWith(absPath)
  -                    : paths.nextString().equals(absPath);
  -        }
  +     // check event type
  +     long type = eventState.getType();
  +     if ((eventTypes & type) == 0) {
  +         return true;
  +     }
  +
  +     // check for ticket local changes
  +     if (noLocal && ticket.equals(eventState.getTicket())) {
  +         // listener does not wish to get local events
  +         return true;
  +     }
  +
  +     // check UUIDs
  +     String parentUUID = eventState.getParentUUID();
  +     if (uuids != null) {
  +         boolean match = false;
  +         for (int i = 0; i < uuids.length && !match; i++) {
  +             match |= parentUUID.equals(uuids[i]);
  +         }
  +         if (!match) {
  +             return true;
  +         }
  +     }
  +
  +     Node parent = null;
  +     try {
  +         parent = (Node) itemMgr.getItem(new NodeId(eventState.getParentUUID()));
  +     } catch (AccessDeniedException e) {
  +         return true;
  +     }
  +
  +     // check node types
  +     if (nodeTypes != null) {
  +         boolean match = false;
  +         for (int i = 0; i < nodeTypes.length && !match; i++) {
  +             match |= parent.isNodeType(nodeTypes[i].getName());
  +         }
  +         if (!match) {
  +             return true;
  +         }
  +     }
  +
  +     // check path
  +     StringIterator paths = parent.getPaths();
  +     boolean match = false;
  +     while (paths.hasNext() && !match) {
  +         match |= (isDeep) ? paths.nextString().startsWith(absPath)
  +                 : paths.nextString().equals(absPath);
  +     }
   
  -        return !match;
  +     return !match;
       }
   
       /**
  @@ -214,20 +221,21 @@
        */
       private static final class BlockAllFilter extends EventFilter {
   
  -        /**
  -         * Creates a new <code>BlockAllFilter</code>.
  -         */
  -        BlockAllFilter() {
  -            super(null, null, 0, null, true, null, null, true);
  -        }
  -
  -        /**
  -         * Always return <code>true</code>.
  -         * @return always <code>true</code>.
  -         */
  -        boolean blocks(EventState eventState) {
  -            return true;
  -        }
  +     /**
  +      * Creates a new <code>BlockAllFilter</code>.
  +      */
  +     BlockAllFilter() {
  +         super(null, null, 0, null, true, null, null, true);
  +     }
  +
  +     /**
  +      * Always return <code>true</code>.
  +      *
  +      * @return always <code>true</code>.
  +      */
  +     boolean blocks(EventState eventState) {
  +         return true;
  +     }
       }
   
   }
  
  
  
  1.3       +52 -46    
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventImpl.java
  
  Index: EventImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EventImpl.java    2 Jul 2004 16:24:37 -0000       1.2
  +++ EventImpl.java    16 Jul 2004 16:37:00 -0000      1.3
  @@ -24,15 +24,14 @@
   
   package org.apache.slide.jcr.core.observation;
   
  -import org.apache.slide.jcr.core.TicketImpl;
  +import org.apache.log4j.Logger;
   import org.apache.slide.jcr.core.ItemManager;
   import org.apache.slide.jcr.core.NodeId;
  -import org.apache.log4j.Logger;
  +import org.apache.slide.jcr.core.TicketImpl;
   
  -import javax.jcr.observation.Event;
   import javax.jcr.Node;
   import javax.jcr.RepositoryException;
  -import javax.jcr.Ticket;
  +import javax.jcr.observation.Event;
   
   /**
    * Implementation of the [EMAIL PROTECTED] javax.jcr.observation.Event} interface.
  @@ -42,7 +41,9 @@
    */
   final class EventImpl implements Event {
   
  -    /** Logger instance for this class */
  +    /**
  +     * Logger instance for this class
  +     */
       private static final Logger log = Logger.getLogger(EventImpl.class);
   
       /**
  @@ -56,10 +57,14 @@
        */
       private final ItemManager itemMgr;
   
  -    /** The shared [EMAIL PROTECTED] EventState} object. */
  +    /**
  +     * The shared [EMAIL PROTECTED] EventState} object.
  +     */
       private final EventState eventState;
   
  -    /** Cached String value of this <code>Event</code> instance. */
  +    /**
  +     * Cached String value of this <code>Event</code> instance.
  +     */
       private String stringValue;
   
       /**
  @@ -73,71 +78,72 @@
        * @param eventState the underlying <code>EventState</code>.
        */
       EventImpl(TicketImpl ticket, ItemManager itemMgr, EventState eventState) {
  -        this.ticket = ticket;
  -        this.itemMgr = itemMgr;
  -        this.eventState = eventState;
  +     this.ticket = ticket;
  +     this.itemMgr = itemMgr;
  +     this.eventState = eventState;
       }
   
       /**
        * @see Event#getType()
        */
       public long getType() {
  -        return eventState.getType();
  +     return eventState.getType();
       }
   
       /**
        * @see Event#getParentNode()
        */
       public Node getParentNode() throws RepositoryException {
  -        return (Node)itemMgr.getItem(new NodeId(eventState.getParentUUID()));
  +     return (Node) itemMgr.getItem(new NodeId(eventState.getParentUUID()));
       }
   
       /**
        * @see Event#getChildItemName()
        */
       public String getChildItemName() throws RepositoryException {
  -        return eventState.getChildItemQName().toJCRName(ticket);
  +     return eventState.getChildItemQName().toJCRName(ticket.getNamespaceResolver());
       }
   
       /**
        * @see Event#getUserId()
        */
       public String getUserId() {
  -        return eventState.getUserId();
  +     return eventState.getUserId();
       }
   
       /**
        * Returns a String representation of this <code>Event</code>.
  +     *
        * @return a String representation of this <code>Event</code>.
        */
       public String toString() {
  -        if (stringValue == null) {
  -            StringBuffer sb = new StringBuffer();
  -            sb.append("Event: Path: ");
  -            try {
  -                sb.append(getParentNode().getPath());
  -            } catch (RepositoryException e) {
  -                log.error("Exception retrieving path: " + e);
  -                sb.append("[Error retrieving path]");
  -            }
  -            sb.append(", ").append(EventState.valueOf(getType())).append(": ");
  -            try {
  -                sb.append(getChildItemName());
  -            } catch (RepositoryException e) {
  -                log.error("Exception retrieving child item name: " + e);
  -                sb.append("[Error retrieving child item name]");
  -            }
  -            sb.append(", UserId: ").append(getUserId());
  -            stringValue = sb.toString();
  -        }
  -        return stringValue;
  +     if (stringValue == null) {
  +         StringBuffer sb = new StringBuffer();
  +         sb.append("Event: Path: ");
  +         try {
  +             sb.append(getParentNode().getPath());
  +         } catch (RepositoryException e) {
  +             log.error("Exception retrieving path: " + e);
  +             sb.append("[Error retrieving path]");
  +         }
  +         sb.append(", ").append(EventState.valueOf(getType())).append(": ");
  +         try {
  +             sb.append(getChildItemName());
  +         } catch (RepositoryException e) {
  +             log.error("Exception retrieving child item name: " + e);
  +             sb.append("[Error retrieving child item name]");
  +         }
  +         sb.append(", UserId: ").append(getUserId());
  +         stringValue = sb.toString();
  +     }
  +     return stringValue;
       }
   
       /**
        * @see Object#hashCode()
        */
       public int hashCode() {
  -        return eventState.hashCode() ^ ticket.hashCode();
  +     return eventState.hashCode() ^ ticket.hashCode();
       }
   
       /**
  @@ -154,14 +160,14 @@
        *         object.
        */
       public boolean equals(Object obj) {
  -        if (this == obj) {
  -            return true;
  -        }
  -        if (obj instanceof EventImpl) {
  -            EventImpl other = (EventImpl)obj;
  -            return this.eventState.equals(other.eventState)
  -                    && this.ticket.equals(other.ticket);
  -        }
  -        return false;
  +     if (this == obj) {
  +         return true;
  +     }
  +     if (obj instanceof EventImpl) {
  +         EventImpl other = (EventImpl) obj;
  +         return this.eventState.equals(other.eventState)
  +                 && this.ticket.equals(other.ticket);
  +     }
  +     return false;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to