Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * Wikitty :: api
   * %%
   * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
   * %%
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as 
   * published by the Free Software Foundation, either version 3 of the 
  * License, or (at your option) any later version.
  * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Lesser Public License for more details.
  * 
  * You should have received a copy of the GNU General Lesser Public 
  * License along with this program.  If not, see
  * <http://www.gnu.org/licenses/lgpl-3.0.html>.
  * #L%
  */
 
 package org.nuiton.wikitty.services;
 
 import java.util.Date;
 import java.util.Map;
 import java.util.Set;
 
Wikitty service event. Contains :
  • Wikitty service as source
  • wikitties : wikitty added if type contains PUT_WIKITTY
  • ids & remove date : if type contains REMOVE_WIKITTY
  • extensions : extension added if type contains PUT_EXTENSION

Author(s):
chatellier
Version:
$Revision$ Last update : $Date$ By : $Author$
 
 // FIXME poussin 20120823 probleme de securte certain event remonte des wikitties
 // que les utilisateurs n'auraient potentiellement pas le droit de lire. Il ne faudrait
 // jamais remonter des objets mais seulement des ids. Voir l'impact sur le fonctionne
 // global avant de faire quoi que se soit
 public class WikittyEvent extends EventObject {

    
serialVersionUID.
 
     private static final long serialVersionUID = 9017732163643700599L;

    
Message type (put, remove, clear...).
 
     static public enum WikittyEventType {
         PUT_WIKITTY(.),
         REMOVE_WIKITTY(.),
         CLEAR_WIKITTY(.),
         PUT_EXTENSION(.),
         REMOVE_EXTENSION(.),
         CLEAR_EXTENSION(.);

        
le nom de la methode du listener a appeler pour ce type d'event
 
         public String listenerMethodName;
         WikittyEventType(String listenerMethodName) {
             this. = listenerMethodName;
         }
     }


    
unique event id, each event must have eventId, and event is sequence without hole. (ex: 0,1,2,3,4,5,6,...)
 
     protected long eventId;

    
Remote event (received from server).
 
     protected boolean remote;

    
event type, one event can have multiple type (ex: PUT_WIKITTY + PUT_EXTENSION
 
     protected EnumSet<WikittyEventTypetype;

    
heure de creation de l'event
 
     protected long time;

    
Use by PUT_WIKITTY, all wikitties added
 
     protected Map<StringWikittywikitties;

    
Use by REMOVE_WIKITTY. key: wikittyId, value: removed date
 
    protected Map<StringDateremoveDate;

    
Use by PUT_EXTENSION, all extensions added
    protected Map<StringWikittyExtensionextensions;

    
Use by REMOVE_EXTENSION, all extensions id deleted
    protected Set<StringdeletedExtensions;

    
Constructor with source org.nuiton.wikitty.WikittyService.

Parameters:
source wikitty service
    public WikittyEvent(Object source) {
        super(source);
        this. = System.currentTimeMillis();
        this. = EnumSet.noneOf(WikittyEventType.class);
    }

    
Return time of event creation.

Returns:
    public long getTime() {
        return ;
    }

    
To allow set transient source after deserialisation.

Parameters:
source source
    public void setSource(Object source) {
        this. = source;
    }
    public EnumSet<WikittyEventTypegetType() {
        return ;
    }

    

Parameters:
type
    public void addType(WikittyEventType type) {
        this..add(type);
    }

    
Is event remote.

Returns:
remote event
    public boolean isRemote() {
        return ;
    }

    
Change remote event property.

Parameters:
remote remote
    public void setRemote(boolean remote) {
        this. = remote;
    }
    public long getEventId() {
        return ;
    }

    
This method must be call with right id, just before send message notification

Parameters:
eventId
    public void setEventId(long eventId) {
        this. = eventId;
    }
    public Map<StringWikittygetWikitties() {
        return ;
    }
    public void addWikitty(Wikitty wikitty) {
        if ( == null) {
             = new LinkedHashMap<StringWikitty>();
            addType(.);
        }
        this..put(wikitty.getWikittyId(), wikitty);
    }
    public Map<StringDategetRemoveDate() {
        return ;
    }
    public void addRemoveDate(String wikittyId,  Date date) {
        if ( == null) {
             = new HashMap<StringDate>();
            addType(.);
        }
        .put(wikittyIddate);
    }
    public Map<StringWikittyExtensiongetExtensions() {
        return ;
    }
    public void addExtension(WikittyExtension extension) {
        if ( == null) {
             = new LinkedHashMap<StringWikittyExtension>();
            addType(.);
        }
        .put(extension.getId(), extension);
    }
    public Set<StringgetDeletedExtensions() {
        return ;
    }
    public void addDeletedExtension(String id) {
        if ( == null) {
             = new LinkedHashSet<String>();
            addType(.);
        }
        .add(id);
    }



    
Merge this event with event passed in arguement. Merged datas are:
  • type
  • wikitties
  • extensions
  • removeDate

    Parameters:
    e
  •     public void add(WikittyEvent e) {
            getType().addAll(e.getType());
            if (e.getWikitties() != null) {
                for (Map.Entry<StringWikittyi : e.getWikitties().entrySet()) {
                    addWikitty(i.getValue());
                }
            }
            if (e.getExtensions() != null) {
                for (Map.Entry<StringWikittyExtensioni : e.getExtensions().entrySet()) {
                    addExtension(i.getValue());
                }
            }
            if (e.getRemoveDate() != null) {
                for (Map.Entry<StringDatei : e.getRemoveDate().entrySet()) {
                    addRemoveDate(i.getKey(), i.getValue());
                }
            }
        }

        
    Update data directly in object passed in argument. Actually only version and deletion date are updated.

    rem: during store action, no migration has done. Migration is only done during restore process. This implies that extension don't change after store. But another client, may can load wikitty with migration and store it, or add manually some extension. In that case, stored wikitty has new/more extension that another client.

    And internally wikitty object is marked clean (not dirty)

    Parameters:
    e
    Returns:
    wikitty passed in argument or null, if event is CLEAR_WIKITTY
        public Wikitty update(Wikitty e) {
            if (e != null) {
                // update version
                String id = e.getWikittyId();
                if (.contains(.)) {
                    e = null;
                } else {
                    if (.contains(.)) {
                        Wikitty newWikitty = getWikitties().get(id);
                        // can be null if wikitty is already saved (uptodate), then this wikitty is not re-saved
                        if (newWikitty != null) {
                            e.replaceWith(newWikitty);
                        }
                    }
                    if (.contains(.)) {
                        Date date = getRemoveDate().get(id);
                        e.setDeleteDate(date);
                    }
                    e.clearDirty();
                }
            }
            return e;
        }
        @Override
        public String toString() {
            String toString = getClass().getName()
                    + "[source=" + 
                    + ", eventId=" + 
                    + ", time=" + 
                    + ", type=" + 
                    + ", remote=" + 
                    + ", wikitties=" + 
                    + ", removeDate=" + 
                    + ", extensions=" + 
                    + "]";
            return toString;
        }

        
    Permet de serializer en XML l'event. Pourrait etre utilise pour l'envoi sur un transporteur qui ne permet pas la serialisation java

    Returns:
        public String toXML() {
            XStream xstream = new XStream();
            xstream.setMode(.);
            xstream.alias("event"WikittyEvent.class);
            String result = xstream.toXML(this);
            return result;
        }

        
    Inverse de la methode toXML

    Parameters:
    xml
    Returns:
        static public WikittyEvent fromXML(String xml) {
            XStream xstream = new XStream();
    		xstream.alias("event"WikittyEvent.class);
    		WikittyEvent result = (WikittyEvent)xstream.fromXML(xml);
            return result;
        }
    New to GrepCode? Check out our FAQ X