001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.roster.rosterstore;
018
019import java.util.Collection;
020import java.util.List;
021
022import org.jivesoftware.smack.roster.packet.RosterPacket;
023
024import org.jxmpp.jid.Jid;
025
026/**
027 * This is an interface for persistent roster store needed to implement
028 * roster versioning as per RFC 6121.
029 */
030
031public interface RosterStore {
032
033    /**
034     * This method returns a list of all roster items contained in this store. If there was an error while loading the store, then <code>null</code> is returned.
035     *
036     * @return List of {@link org.jivesoftware.smack.roster.RosterEntry} or <code>null</code>.
037     */
038    List<RosterPacket.Item> getEntries();
039
040    /**
041     * This method returns the roster item in this store for the given JID.
042     *
043     * @param bareJid The bare JID of the RosterEntry
044     * @return The {@link org.jivesoftware.smack.roster.RosterEntry} which belongs to that user
045     */
046    RosterPacket.Item getEntry(Jid bareJid);
047
048    /**
049     * This method returns the version number as specified by the "ver" attribute
050     * of the local store. For a fresh store, this MUST be the empty string.
051     *
052     * @return local roster version
053     */
054    String getRosterVersion();
055
056    /**
057     * This method stores a new roster entry in this store or updates an existing one.
058     *
059     * @param item the entry to store
060     * @param version the new roster version
061     * @return True if successful
062     */
063    boolean addEntry(RosterPacket.Item item, String version);
064
065    /**
066     * This method updates the store so that it contains only the given entries.
067     *
068     * @param items the entries to store
069     * @param version the new roster version
070     * @return True if successful
071     */
072    boolean resetEntries(Collection<RosterPacket.Item> items, String version);
073
074    /**
075     * Removes an entry from the store.
076     *
077     * @param bareJid The bare JID of the entry to be removed
078     * @param version the new roster version
079     * @return True if successful
080     */
081    boolean removeEntry(Jid bareJid, String version);
082
083    /**
084     * Reset the store by removing all entries and setting the version to the empty String.
085     *
086     * @since 4.2
087     */
088    void resetStore();
089}