/******************************************************************************
* Copyright (c) 2007 Savino Sguera. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this
* distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Savino Sguera < s.sguera@ieee.org >
******************************************************************************
*/
package org.eclipse.twipse.ecf;
import java.util.Map;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerListener;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.user.IUser;
import org.eclipse.ecf.presence.IPresence;
import org.eclipse.ecf.presence.Presence;
import org.eclipse.ecf.presence.roster.IRosterEntry;
import org.eclipse.ecf.presence.roster.IRosterGroup;
import org.eclipse.ecf.presence.roster.IRosterItem;
import org.eclipse.ecf.presence.roster.RosterEntry;
import org.eclipse.ecf.presence.roster.RosterGroup;
import org.eclipse.ecf.presence.roster.RosterItem;
import org.eclipse.twipse.TwipsePlugin;
import org.eclipse.twipse.core.ITwitterClient;
import org.eclipse.twipse.core.TwitterClient;
import org.eclipse.twipse.model.Status;
import org.eclipse.twipse.model.User;
public class TwitterContainer implements IContainer {
private ITwitterClient client = new TwitterClient();
private ID localId;
private TwitterID targetID;
public TwitterContainer(ID id){
localId=id;
}
public void addListener(IContainerListener listener) {
// TODO Auto-generated method stub
}
public void connect(ID targetID, IConnectContext connectContext)
throws ContainerConnectException {
}
public void disconnect() {
}
public void dispose() {
// TODO Auto-generated method stub
}
public Object getAdapter(Class serviceType) {
// TODO Auto-generated method stub
return null;
}
public Namespace getConnectNamespace() {
return IDFactory.getDefault().getNamespaceByName(
TwipsePlugin.NAMESPACE_IDENTIFIER);
}
public ID getConnectedID() {
return this.targetID;
}
public void removeListener(IContainerListener listener) {
// TODO Auto-generated method stub
}
public ID getID() {
// TODO Auto-generated method stub
return this.localId;
}
protected IRosterEntry makeRosterEntry(IRosterItem parent, User user) {
String userName = user.getScreen_name();
ID userID;
IRosterEntry entry;
try {
userID = IDFactory.getDefault().createID(targetID.getNamespace(), userName);
IUser child = new org.eclipse.ecf.core.user.User(userID,userName);
IPresence presence = new Presence(IPresence.Type.AVAILABLE);
entry = new RosterEntry(parent, child,presence);
/*IPresence presence = presenceContainer.createPresence(userID.getName());
entry.setPresenceState(presence);*/
return entry;
} catch (IDCreateException e) {
e.printStackTrace();
}
return null;
}
private void populateRoster() {
Map<User,Status> friends = client.getFriends();
//IRosterItem parent = new RosterItem(
for(User u : friends.keySet()){
//IRosterEntry entry = makeRosterEntry(u);
//IRosterEntry entry = makeRosterEntry(parent,u);
}
/*for(int i = 0; i < groups.length; i++) {
IRosterGroup group = new RosterGroup(groups[i].getName());
for(int j = 0; j < groups[i].getMembers().size(); j++) {
YahooUser u = (YahooUser) groups[i].getMembers().get(j);
IRosterEntry entry = makeRosterEntry(u);
entry.add(group);
presenceContainer.fireRosterEntry(entry);
}
}*/
}
}