use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.
the class MSNContainer method connect.
public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
if (!(targetID instanceof MSNID)) {
throw new ContainerConnectException(Messages.MSNContainer_TargetIDNotMSNID);
}
client = new MsnClient();
ObjectCallback[] cb = { new ObjectCallback() };
try {
connectContext.getCallbackHandler().handle(cb);
client.addSessionListener(new ISessionListener() {
public void sessionConnected(ChatSession session) {
try {
Contact contact = session.getParticipants()[0];
final ID toID = namespace.createInstance(new Object[] { contact.getEmail() });
chatSessions.put(toID, session);
session.addChatSessionListener(new ChatSessionListener(toID));
} catch (IDCreateException e) {
// ignored since this should not be possible
}
}
});
client.getContactList().addContactListListener(new IContactListListener() {
public void contactAdded(Contact contact) {
final MSNRosterEntry entry = new MSNRosterEntry(MSNContainer.this, contact, namespace);
for (int i = 0; i < entries.size(); i++) {
Object e = entries.get(i);
if (e instanceof MSNRosterGroup) {
MSNRosterGroup group = (MSNRosterGroup) e;
if (group.getGroup().contains(contact)) {
MSNRosterEntry check = group.getEntryFor(contact);
if (check == null) {
check = entry;
contact.addContactListener(new IContactListener() {
public void nameChanged(String name) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(String personalMessage) {
entry.updatePersonalMessage();
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(Status status) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
});
group.add(check);
fireRosterEntryAdded(check);
}
fireRosterUpdate(group);
return;
}
} else {
MSNRosterEntry check = (MSNRosterEntry) e;
if (entry.getContact().equals(check.getContact())) {
fireRosterEntryAdded(check);
fireRosterUpdate(check.getParent());
return;
}
}
}
contact.addContactListener(new IContactListener() {
public void nameChanged(String name) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(String personalMessage) {
entry.updatePersonalMessage();
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(Status status) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
});
entries.add(entry);
entry.setParent(MSNContainer.this);
fireRosterEntryAdded(entry);
fireRosterUpdate(MSNContainer.this);
}
public void contactRemoved(Contact contact) {
MSNRosterEntry entry = findEntry(entries, contact.getEmail());
if (entry != null) {
fireHandleUnsubscribed(entry.getUser().getID());
fireRosterEntryRemoved(entry);
fireRosterUpdate(entry.getParent());
if (entry.getContact().getGroups().isEmpty()) {
entry.setParent(MSNContainer.this);
fireRosterUpdate(MSNContainer.this);
}
}
}
public void contactAddedUser(String email) {
try {
fireHandleSubscriptionRequest(namespace.createInstance(new Object[] { email }));
} catch (IDCreateException e) {
// ignored
}
}
public void contactRemovedUser(String email) {
// nothing to do
}
public void groupAdded(Group group) {
entries.add(new MSNRosterGroup(MSNContainer.this, group));
}
});
fireContainerEvent(new ContainerConnectingEvent(guid, targetID));
client.connect(targetID.getName(), (String) cb[0].getObject());
connectID = (MSNID) targetID;
fireContainerEvent(new ContainerConnectedEvent(guid, connectID));
Activator.getDefault().registerService(this);
} catch (UnsupportedCallbackException e) {
throw new ContainerConnectException(e);
} catch (IOException e) {
throw new ContainerConnectException(e);
}
}
use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.
the class RemoteServiceHandlerUtil method getActiveIRemoteServiceReferencesChecked.
public static IRemoteServiceReference[] getActiveIRemoteServiceReferencesChecked(ExecutionEvent event) throws ExecutionException {
final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
final IRemoteServiceContainerAdapter adapter = getActiveIRemoteServiceContainerAdapterChecked(event);
try {
return getRemoteServiceReferencesForRemoteServiceAdapter(adapter, serviceInfo);
} catch (IDCreateException e) {
throw new ExecutionException(e.getMessage(), e);
} catch (InvalidSyntaxException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.
the class DnsSdDiscoveryAdvertiser method connect.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
// $NON-NLS-1$ //$NON-NLS-2$
Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container");
// connect can only be called once
if (targetID != null || getConfig() == null) {
throw new ContainerConnectException(Messages.DnsSdDiscoveryAdvertiser_Container_Already_Connected);
}
// TODO convert non DnsSdServiceTypeIDs into DSTIDs
if (aTargetID == null) {
targetID = new DnsSdServiceTypeID();
} else {
final Namespace ns = getConnectNamespace();
try {
targetID = (DnsSdServiceTypeID) ns.createInstance(new Object[] { aTargetID });
} catch (IDCreateException e) {
throw new ContainerConnectException(e);
}
}
// instantiate a default resolver
if (resolver == null) {
try {
resolver = new SimpleResolver();
resolver.setTCP(true);
} catch (UnknownHostException e) {
throw new ContainerConnectException(e);
}
}
// done setting up this provider, send event
fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.
the class DnsSdNamespace method createInstance.
/* (non-Javadoc)
* @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
*/
public ID createInstance(Object[] parameters) throws IDCreateException {
if (parameters != null && parameters.length == 1 && parameters[0] instanceof String) {
String str = (String) parameters[0];
return new DnsSdServiceTypeID(this, str);
} else if (parameters != null && parameters.length == 1 && parameters[0] instanceof IServiceTypeID) {
IServiceTypeID serviceTypeID = (IServiceTypeID) parameters[0];
return new DnsSdServiceTypeID(this, serviceTypeID);
} else if (parameters != null && parameters.length == 1 && parameters[0] instanceof IServiceID) {
IServiceID serviceID = (IServiceID) parameters[0];
return new DnsSdServiceTypeID(this, serviceID.getServiceTypeID());
} else if (parameters != null && parameters.length == 1 && parameters[0] instanceof StringID) {
StringID stringID = (StringID) parameters[0];
return new DnsSdServiceTypeID(this, stringID.getName());
} else if (parameters != null && parameters.length == 2 && parameters[0] instanceof IServiceTypeID && parameters[1] instanceof URI) {
IServiceTypeID serviceTypeID = (IServiceTypeID) parameters[0];
URI uri = (URI) parameters[1];
return new DnsSdServiceID(this, new DnsSdServiceTypeID(this, serviceTypeID), uri);
} else if (parameters != null && parameters.length == 2 && parameters[0] instanceof String && parameters[1] instanceof URI) {
String serviceType = (String) parameters[0];
URI uri = (URI) parameters[1];
return new DnsSdServiceID(this, new DnsSdServiceTypeID(this, serviceType), uri);
} else {
throw new IDCreateException(Messages.DnsSdNamespace_Wrong_Parameters);
}
}
use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.
the class LookupHandler method execute.
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
String[] inputs = dialogSettings.getArray(MANUAL_LOOKUP_HANDLER);
InputDialogWithComboHistory dialog = new InputDialogWithComboHistory(window.getShell(), Messages.LookupHandler_DIALOG_TITLE, Messages.LookupHandler_DIALOG_LABEL, HOST_DOMAIN_TLD_PORT, inputs, VALIDATOR);
if (dialog.open() == InputDialog.OK) {
String input = dialog.getValue();
try {
URI uri = URI.create(input);
// verify the hostname to be resolveable
InetAddress.getByName(uri.getHost());
Job job = new LookupJob(uri);
job.setUser(false);
job.schedule();
// add the newly added input to the preference store
String[] copyOfPreviousInput;
if (inputs != null) {
copyOfPreviousInput = new String[inputs.length + 1];
copyOfPreviousInput[0] = input;
for (int i = 0; i < inputs.length; i++) {
copyOfPreviousInput[i + 1] = inputs[i];
}
} else {
copyOfPreviousInput = new String[] { input };
}
// but we don't want dups
Set aSet = new LinkedHashSet(Arrays.asList(copyOfPreviousInput));
dialogSettings.put(MANUAL_LOOKUP_HANDLER, (String[]) aSet.toArray(new String[aSet.size()]));
} catch (ContainerCreateException e) {
throw new ExecutionException(Messages.LookupHandler_EXEC_FAILED, e);
} catch (IDCreateException e) {
throw new ExecutionException(Messages.LookupHandler_EXEC_FAILED, e);
} catch (UnknownHostException e) {
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID, Messages.LookupHandler_UNKNOWN_HOSTNAME);
ErrorDialog.openError(null, Messages.LookupHandler_UNKNOWN_HOSTNAME, NLS.bind(Messages.LookupHandler_HOSTNAME_UNABLE_TO_RESOLVE, input), status);
}
}
return null;
}
Aggregations