Package com.calclab.emite.xep.storage

Source Code of com.calclab.emite.xep.storage.PrivateStorageManagerImpl

/*
* ((e)) emite: A pure Google Web Toolkit XMPP library
* Copyright (c) 2008-2011 The Emite development team
*
* This file is part of Emite.
*
* Emite 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.
*
* Emite 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Emite.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.calclab.emite.xep.storage;

import com.calclab.emite.base.xml.HasXML;
import com.calclab.emite.core.IQCallback;
import com.calclab.emite.core.XmppNamespaces;
import com.calclab.emite.core.session.XmppSession;
import com.calclab.emite.core.stanzas.IQ;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
* Implements http://xmpp.org/extensions/xep-0049.html
*/
@Singleton
public class PrivateStorageManagerImpl implements PrivateStorageManager {

  private final XmppSession session;

  @Inject
  protected PrivateStorageManagerImpl(final XmppSession session) {
    this.session = session;
  }

  @Override
  public void retrieve(final HasXML data, final PrivateStorageResponseEvent.Handler handler) {
    final IQ iq = new IQ(IQ.Type.get);
    iq.addQuery(XmppNamespaces.PRIVATE).addChild(data);

    session.sendIQ("priv", iq, new IQCallback() {
      @Override
      public void onIQSuccess(final IQ iq) {
        handler.onStorageResponse(new PrivateStorageResponseEvent(iq));
      }

      @Override
      public void onIQFailure(final IQ iq) {
      }
    });
  }

  @Override
  public void store(final HasXML data, final PrivateStorageResponseEvent.Handler handler) {
    final IQ iq = new IQ(IQ.Type.set);
    iq.addQuery(XmppNamespaces.PRIVATE).addChild(data);

    session.sendIQ("priv", iq, new IQCallback() {
      @Override
      public void onIQSuccess(final IQ iq) {
        handler.onStorageResponse(new PrivateStorageResponseEvent(iq));
      }

      @Override
      public void onIQFailure(final IQ iq) {
      }
    });
  }
}
TOP

Related Classes of com.calclab.emite.xep.storage.PrivateStorageManagerImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.