XMPP.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 15KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2015-05-03 17:00
    上传日期
Describes XMPP protocol client with smach library.
XMPP.rar
  • XMPP
  • src
  • xmpp
  • CliClient.java
    7.2KB
  • CliUtil.java
    2.9KB
  • CliPresenceServiceListener.java
    2.5KB
  • PresenceHelper.java
    5.4KB
  • SessionManager.java
    2.7KB
  • CliSessionListener.java
    3.6KB
  • ReconnectionListener.java
    1.9KB
  • AuthenticationManager.java
    11KB
  • XMPP.java
    443B
  • SessionHelper.java
    1.8KB
  • manifest.mf
    85B
内容介绍
/* * Copyright (c) 2006, Mridul Muralidharan * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of the dev.java.net nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * AuthenticationHandler.java * * Created on May 17, 2006, 11:29 AM * */ package xmpp; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import CollaborationException; //import org.netbeans.lib.collab.CollaborationSession; //import org.netbeans.lib.collab.CollaborationSessionFactory; //import org.netbeans.lib.collab.CollaborationSessionListener; /** * * @author Mridul Muralidharan */ public class AuthenticationManager implements CollaborationSessionListener, SessionManager { private CollaborationSessionFactory factory = null; private String sessionProvider = null; private CollaborationSession session = null; private boolean connectionThreadStarted = false; private String password = null; private String serviceUrl = null; private CollaborationSessionListener listener = null; private String loginName = null; private String destination = null; private ReconnectionRunnable reconnRunnable = null; // List <SessionHelper> private List sessionHelpers = new LinkedList(); public AuthenticationManager(CollaborationSessionListener listener) throws CollaborationException{ this(listener , null); } public AuthenticationManager(String sessionProvider) throws CollaborationException{ // Use the specified session provider for CollaborationSessionFactory. this(null , sessionProvider); } public AuthenticationManager(CollaborationSessionListener listener , String sessionProvider) throws CollaborationException{ // Use the specified session provider for CollaborationSessionFactory. this.sessionProvider = sessionProvider; this.listener = listener; initFactory(); } public synchronized void addSessionHelper(SessionHelper helper){ if (!sessionHelpers.contains(helper)){ sessionHelpers.add(helper); } } public synchronized boolean removeSessionHelper(SessionHelper helper){ return sessionHelpers.remove(helper); } public CollaborationSessionFactory getFactory(){ return factory; } public synchronized CollaborationSession getSession(boolean canBlock) throws CollaborationException { if (null != session || !canBlock){ return session; } return createSession(null); } public synchronized CollaborationSession createSession(final ReconnectionListener reconListener) throws CollaborationException { return createSession(reconListener , true); } public synchronized CollaborationSession createSession(final ReconnectionListener reconListener , boolean waitForSession) throws CollaborationException { if (null != session){ return session; } // Validate that all info required for session creation are populated. validate(); ReconnectionListener recon = null; startConnectionThread(null == password ? null : password.toCharArray() , reconListener); //synchronized(this) if (waitForSession) { while (null == session && reconnRunnable.isRunning()){ try{ this.wait(); }catch(InterruptedException iEx){} } } return session; } public void onError(CollaborationException ex){ synchronized (this){ session = null; this.notifyAll(); } } public void setPassword(String password) { this.password = password; } public void setServiceUrl(String serviceUrl) { this.serviceUrl = serviceUrl; } public void setLoginName(String loginName) { this.loginName = loginName; } public void setDestination(String destination) { this.destination = destination; } private synchronized void startConnectionThread(char password[] , ReconnectionListener listener){ if (connectionThreadStarted){ assert (null != reconnRunnable); assert (reconnRunnable.isRunning()); return ; } assert (null == session); connectionThreadStarted = true; ReconnectionRunnable runnable = new ReconnectionRunnable(listener); runnable.setPassword(password); Thread th = new Thread(runnable); th.start(); reconnRunnable = runnable; } protected void validate() throws CollaborationException { if (null == serviceUrl){ throw new CollaborationException("serviceUrl not specified"); } if (0 == serviceUrl.trim().length()){ throw new CollaborationException("Empty serviceUrl - invalid"); } if (null == loginName){ throw new CollaborationException("loginName == null"); } } private static void emptyArray(char arr[]){ if (null != arr){ int count = 0; while (count < arr.length){ arr[count] = 0; count ++; } } } private void initFactory() throws CollaborationException { try{ if (null == sessionProvider){ factory = new CollaborationSessionFactory(); } else{ factory = new CollaborationSessionFactory(sessionProvider); } }catch(Exception ex){ throw new CollaborationException(ex); } return ; } private class ReconnectionRunnable implements Runnable{ private char[] passwordChars = null; private ReconnectionListener reconnListener; private boolean running = true; public ReconnectionRunnable(){ this(null); } public ReconnectionRunnable(ReconnectionListener reconnListener){ this.reconnListener = reconnListener; } public void setPassword(char password[]){ this.reconnListener = reconnListener; if (null != password){ passwordChars
评论
    相关推荐