Search in sources :

Example 21 with IDCreateException

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);
    }
}
Also used : Status(org.eclipse.ecf.protocol.msn.Status) Group(org.eclipse.ecf.protocol.msn.Group) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ISessionListener(org.eclipse.ecf.protocol.msn.events.ISessionListener) IContactListener(org.eclipse.ecf.protocol.msn.events.IContactListener) IOException(java.io.IOException) ChatSession(org.eclipse.ecf.protocol.msn.ChatSession) Contact(org.eclipse.ecf.protocol.msn.Contact) IChatSessionListener(org.eclipse.ecf.protocol.msn.events.IChatSessionListener) MsnClient(org.eclipse.ecf.protocol.msn.MsnClient) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IContactListListener(org.eclipse.ecf.protocol.msn.events.IContactListListener) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) ID(org.eclipse.ecf.core.identity.ID) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException)

Example 22 with IDCreateException

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);
    }
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 23 with IDCreateException

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));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) UnknownHostException(java.net.UnknownHostException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) SimpleResolver(org.xbill.DNS.SimpleResolver) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 24 with IDCreateException

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);
    }
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) StringID(org.eclipse.ecf.core.identity.StringID) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) URI(java.net.URI)

Example 25 with IDCreateException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IStatus(org.eclipse.core.runtime.IStatus) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) URI(java.net.URI) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)34 ID (org.eclipse.ecf.core.identity.ID)16 Matcher (java.util.regex.Matcher)11 Namespace (org.eclipse.ecf.core.identity.Namespace)8 ThreadMessageID (org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 UnknownHostException (java.net.UnknownHostException)3 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)3 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)3 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)3 URI (java.net.URI)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2 Job (org.eclipse.core.runtime.jobs.Job)2 IBBObject (org.eclipse.ecf.bulletinboard.IBBObject)2 IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)2